Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 6 of 6

Thread: How To Add a Method/Demo?

  1. #1
    Junior Member
    Join Date
    Dec 2012
    Posts
    18
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Question 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:

    <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");
         }
    }>


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: How To Add a Method/Demo?

    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.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Dec 2012
    Posts
    18
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Re: How To Add a Method/Demo?

    Quote Originally Posted by Norm View Post
    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.

    6r7gyc.jpg

    2rpcvmq.jpg

    My code is good there are no errors and runs great i just need to add a "Demo" but i am not sure how

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: How To Add a Method/Demo?

    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.
    If you don't understand my answer, don't ignore it, ask a question.

  5. #5
    Junior Member
    Join Date
    Dec 2012
    Posts
    18
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default 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

  6. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: How To Add a Method/Demo?

    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.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. how/where to add new method and attributes
    By me. in forum Java Theory & Questions
    Replies: 3
    Last Post: October 18th, 2012, 09:33 AM
  2. Using a method to add two classes and produce a third
    By shamman84 in forum Object Oriented Programming
    Replies: 6
    Last Post: February 5th, 2012, 09:18 PM
  3. override list add method?
    By ober0330 in forum Collections and Generics
    Replies: 10
    Last Post: July 17th, 2011, 07:34 PM
  4. [SOLVED] Can't add a method without getting errors
    By petemyster in forum What's Wrong With My Code?
    Replies: 2
    Last Post: April 15th, 2011, 12:18 PM
  5. how to implement method to add new Student and display it
    By exose in forum What's Wrong With My Code?
    Replies: 6
    Last Post: February 10th, 2011, 11:39 AM