Results 1 to 4 of 4
  1. #1
    dangolf is offline Member
    Join Date
    Feb 2013
    Posts
    5
    Rep Power
    0

    Default Need help with program

    Need help with following program:

    Write a program that displays the recommended weight (kg), given the user's age and height cm). The formula for calculating the recommended weight is

    recommendedWeight = (height - 100 + age / 10) * 0.90

    Define a service class named Height and include an appropriate method for getting a recommended weight of a designated height.


    Please note the following:No instance variable should be declared as public.
    1.) Class must have a default constructor and a parameterized constructor.
    2.) Class must have necessary methods as indicated in the problem statement of the text.
    3.) You will also add a separate class named Tester.java to test the class that you are going to write to solve the problem. This class will only have a main method and will create objects of the class you have written and invoke method(s) to see if it is working correctly.

    This is what I have and I'm pretty sure it's wrong.

    public class RecommendedWeight{

    private double recommendedWeight;
    private double height;
    private int age;

    public RecommendedWeight(){
    height=0;
    age=0;
    recommendedWeight=0;
    }

    public int getAge(){
    return age;
    }

    public double getHeight(){
    return height;
    }

    public void setHeight(double h){
    height=h;
    }

    public void setAge(int a){
    age=a;
    }

    public double getRecommendedWeight(){
    return (height - 100 + age/ 10);
    }

    }


    I am completely lost for the tester class. This is only my second week in intro to Java. Thanks for any input!

  2. #2
    wfsteadman is offline Member
    Join Date
    Jan 2013
    Location
    Texas
    Posts
    45
    Rep Power
    0

    Default Re: Need help with program

    Well based on requirements, you don't have a parametrized constructor you would want something like:
    Java Code:
    public RecommendedWeight( int height, int age){
    this.height = height;
    this.age = age;
     Since you are going to figure this out you would not need to have recommendedWeight=0; here but it doesn't hurt to have it their either.
    }
    Without seeing any more code, there is no way to tell what is going on, do you have a class with main in it etc....

  3. #3
    dangolf is offline Member
    Join Date
    Feb 2013
    Posts
    5
    Rep Power
    0

    Default Re: Need help with program

    The only class I have main is in the tester class. I was able to do the program but without encapsulation. However, I have to have encapsulation (using private).

  4. #4
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,423
    Rep Power
    20

    Default Re: Need help with program

    Please go through the Forum Rules, particularly the third paragraph. Also go through Guide For New Members and BB Code List - Java Programming Forum - Learn Java Programming and edit your post accordingly.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

Similar Threads

  1. Replies: 4
    Last Post: 11-21-2012, 02:19 PM
  2. Replies: 2
    Last Post: 04-02-2011, 01:57 PM
  3. Replies: 13
    Last Post: 03-22-2011, 07:49 AM
  4. changing my program to array working program
    By Chewart in forum New To Java
    Replies: 39
    Last Post: 11-18-2009, 07:53 PM
  5. Replies: 0
    Last Post: 10-04-2007, 10:33 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •