DOGGY G
DOGGY G

Reputation: 15

How to test this program

To start, I'm a beginning programmer so forgive me if i make any mistakes. So I had to write a small method which i think i did successfully.

But now i'm stuck, my book helped me writing this method(if some of you wondering how i managed to make it). Now i need to provide a program to test the method i wrote. But i really have no clue how to test this.

Here is my method i wrote:

public static void opdracht3b1(double x, double y, double z){
        double[] numbers = new double[] {x, y, z};
        double smallestNumber = x;

        for(double number : numbers){
            if(number < smallestNumber){
                smallestNumber = number;
            }
        }

        System.out.println("Input numbers: " + x + ", " + y + ", " + z + ".");
        System.out.println("Smallest Number: " + smallestNumber + ".");
    }

The bottom two lines printing is what I'm trying to accomplish.

I would really appreciate some help.

Thank you guys

Upvotes: 0

Views: 62

Answers (2)

olovholm
olovholm

Reputation: 1392

If you are going to write tests a good place to start is by applying a testing framework for unit testing. For this is e.g. junit a good place to start. You would also find an IDE useful e.g. Eclipse.

If you want to test coding without too much setup and contextual knowledge I also recommend looking at processing.org. This is a small IDE where you can write code, and the online resources are good, and made for learning programming.

Sorry for not answering your question to the point, but hopefully it will give you a good starting point for exploring.

Upvotes: 0

SpiderShlong
SpiderShlong

Reputation: 224

public class myProgram //class that contains your code
{
public static void main(String [] args) //main method is always called at runtime
{
    opdracht3b1(num1,num2,num3); //fill in numbers with the 3 numbers you want 
}
public static void opdracht3b1(double x, double y, double z){
    double[] numbers = new double[] {x, y, z};
    double smallestNumber = x;

    for(double number : numbers){
        if(number < smallestNumber){
            smallestNumber = number;
        }
    }

    System.out.println("Input numbers: " + x + ", " + y + ", " + z + ".");
    System.out.println("Smallest Number: " + smallestNumber + ".");
}
}

I also would highly recommend that your download eclipse or another IDE

Upvotes: 1

Related Questions