How To Add a Method/Demo?
Hello, so i have a program here and i wanted to know how do i make a demo to test the class
I do not know if i need to edit the program i have so it is able to understand the demo.
Also i wanted to know when you are compiling the program, do you compile both at the same time? how does it put the two seperate programs together?
Anyways here is the program:
Code java:
<package my_bmi;
import java.util.Scanner;
public class My_BMI_3
{
public static void main(String[] args)
{
String name; //name of BMI person
int Weight; //weight in pounds
int Height; //height in inches
double bmi; // BMI
System.out.println ("This Java program calculates your BMI");
Scanner KB = new Scanner (System.in);
System.out.print ("Please enter your name: ");
name= KB.nextLine();
System.out.print ("Please enter your weight in pounds: ");
Weight= KB.nextInt();
System.out.print ("Please enter your height in inches: ");
Height= KB.nextInt();
bmi = (Weight *703)/(Height * Height);
System.out.println ( name + " for your weight: " + Weight + " and height: " + Height);
if (bmi<18.5)
{
System.out.print ("According to your BMI you are underweight.");
}
if (bmi>= 18.5 && bmi<25)
{
System.out.print ("According to your BMI you are normal weight.");
}
if (bmi>= 25 && bmi<30)
{
System.out.print ("According to your BMI you are overweight.");
}
if (bmi>=30)
{
System.out.print ("According to your BMI you are obese.");
}
System.out.print ("\n");
System.out.println ("Thank you for using the BMI program. Good bye");
}
}>
Re: How To Add a Method/Demo?
Quote:
how do i make a demo to test the class
what happens when you compile the class? Any errors?
What happens when you execute the class? Any errors?
Does it do what you want?
The class has a main() method and shouldn't need another driver/demo class to test it.
2 Attachment(s)
Re: How To Add a Method/Demo?
Quote:
Originally Posted by
Norm
what happens when you compile the class? Any errors?
What happens when you execute the class? Any errors?
Does it do what you want?
The class has a main() method and shouldn't need another driver/demo class to test it.
For example I have this where they have a program for a Dog
and then there is another program where it shows the information and it plugs the information into the program.
Attachment 1639
Attachment 1638
My code is good there are no errors and runs great i just need to add a "Demo" but i am not sure how
Re: How To Add a Method/Demo?
Quote:
i just need to add a "Demo"
Why?
If the code does all it's supposed to as it is now, what would a Demo do?
The code has one method: main(). There is not any meaningful way to have another class go with it.
Re: How To Add a Method/Demo?
because its for class lol
there is away that you can add methods or something like that and it shows you the results (demo) for that program. I dont no if i explain it, because i dont understand it quite myself lol
i have to convert my program to a class and create a demo class that TESTS the class
that is the objective
Re: How To Add a Method/Demo?
Quote:
i have to convert my program to a class and create a demo class that TESTS the class
You will need to move all the code out of the main() method.
The way the class is now coded, there is no sense in having another class to test it.