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 4 of 4

Thread: help pulling information from different classes when you have more than one

  1. #1
    Junior Member
    Join Date
    Feb 2012
    Posts
    10
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default help pulling information from different classes when you have more than one

    I'm having trouble with a homework assignment. This is what I need to do.

    You are to create 2 classes and use the helper class I have provided to complete this lab.

    The first class you are to create will determine your recommended weight (Kg), given the userís age and height (cm). The formula for calculating the recommended weight is:

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

    The second class you are to create will convert the weight in kg to pounds (1 kilogram = 2.20462262 pounds). Then it will have another method to calculate your weight on other planets. One method should be used per planet.

    Use the values in this table.
    Planet Multiply the Earth Weight by
    Mercury 0.4
    Venus 0.9
    Jupiter 2.5
    Saturn 1.1

    The guidelines for your Recommended Weight class are as follows:

    Class Name: RecommendedWeight

    Method Name: getRecommendedWeight
    Parameters: height (double) and age (int)
    Desired Result: Calculate the recommended weight based on the height and age of
    the user
    Data Returned: The recommended weight in kilograms (double)


    Class Name: PlanetWeights

    Method Name: convertKilogramsToPounds
    Parameters: weightInKilograms (double)
    Desired Result: Calculate the weight of the user in pounds
    Data Returned: The weight of the user in pounds (double)

    Method Name: calculateWeightOnMercury
    Parameters: weightInPounds (double)
    Desired Result: Calculate the weight of the user on Mercury
    Data Returned: The weight of the user, in pounds, on Mercury (double)

    Method Name: calculateWeightOnVenus
    Parameters: weightInPounds (double)
    Desired Result: Calculate the weight of the user on Venus
    Data Returned: The weight of the user, in pounds, on Venus (double)

    Method Name: calculateWeightOnJupiter
    Parameters: weightInPounds (double)
    Desired Result: Calculate the weight of the user on Jupiter
    Data Returned: The weight of the user, in pounds, on Jupiter (double)

    Method Name: calculateWeightOnSaturn
    Parameters: weightInPounds (double)
    Desired Result: Calculate the weight of the user on Saturn
    Data Returned: The weight of the user, in pounds, on Saturn (double)


    This is the helper class my teacher has given.
    public class Lab2 {
    	public static void main(String[] args){
    		RecommendedWeight weight = new RecommendedWeight();
    		PlanetWeights planets = new PlanetWeights();
     
    		double weightInKgs = weight.getRecommendedWeight(177, 25);
     
    		double weightInLbs = planets.convertKilogramsToPounds(weightInKgs);
    		double weightOnMercury = planets.calculateWeightOnMercury(weightInLbs);
    		double weightOnVenus = planets.calculateWeightOnVenus(weightInLbs);
    		double weightOnJupiter = planets.calculateWeightOnJupiter(weightInLbs);
    		double weightOnSaturn= planets.calculateWeightOnSaturn(weightInLbs);
     
    		System.out.println("Your recommended weight in pounds: " + weightInLbs);
    		System.out.println("Your recommended weight on Mercury " + weightOnMercury);
    		System.out.println("Your recommended weight on Venus " + weightOnVenus);
    		System.out.println("Your recommended weight on Jupiter " + weightOnJupiter);
    		System.out.println("Your recommended weight on Saturn " + weightOnSaturn);
    	}
    }
    This is my Class Name: RecommendedWeight: I think this is correct.
    class RecommendedWeight{
    private double height;
    private int age;
     
     
    double getRecommendedWeight(double newHeight, int newAge){
        height=newHeight;
        age=newAge;
       double recWeight = (height -100 + age /10) * 0.90;
        return recWeight;
    }
    }
    The problem I have is in the planetWeights class. I'm not sure how to bring in the weight in kilograms so I can convert it to pounds. I have spent hours on this doing multiple ways. I know this is wrong but this is the last thing I tried.
    class PlanetWeights{
    private RecommendedWeight Weight = new RecommendedWeight();
    double weightInKilograms = Weight.getRecommendedWeight();
    private double weightInPounds;
     
    double convertKilogramsToPounds(){
     
    double recWeight;
     
    weightInKilograms=1*2.20462262;
    weightInPounds=recweight*weightInKilograms;
    return  weightInLbs;
     
    }
     
    double calculateWeightOnMercury(){
     
    return  weightOnMercury;
     
    }
     
    double calculateWeightOnVenus(){
     
    return  weightOnVenus;
     
    }
     
     
    double calculateWeightOnJupiter(){
     
    return  weightOnJupiter;
     
    }
     
     
    double calculateWeightOnSaturn(){
     
    return  weightOnSaturn;
     
    }
     
    }
    Not too worried about the planets yet. I know if someone can point me in the right direction with the kilograms to pounds, I should be able to get the rest.


  2. #2
    Junior Member
    Join Date
    Oct 2011
    Posts
    20
    Thanks
    1
    Thanked 4 Times in 4 Posts

    Default Re: help pulling information from different classes when you have more than one

    Hmmm... if 1 kilogram = 2.20462262 pounds, then all you'd have to do is the following:

    private double weightInPounds;
     
    double convertKilogramsToPounds(){
     
    weightInPounds=weightInKilograms*2.20462262;
    return  weightInPounds;
     
    }

    Or just return it as the result:

    double convertKilogramsToPounds(){
     
    return  (weightInKilograms*2.20462262);
     
    }

    Correct me if im misunderstanding your problem or if anything is wrong.

  3. The Following User Says Thank You to Henry518 For This Useful Post:

    mickey2012 (February 6th, 2012)

  4. #3
    Junior Member
    Join Date
    Feb 2012
    Posts
    10
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: help pulling information from different classes when you have more than one

    That gives me an error in public class Lab2. convertKilogramsToPounds() in PlanetWeights cannot be applied to (double)
    I cannot change the code in Lab2. This is my updated code for PlanetWeights.
    class PlanetWeights{
     
    double convertKilogramsToPounds(){
     
    double weightInKilograms=0.0;
     
    return  (weightInKilograms*2.20462262);
     
    }
     
    double calculateWeightOnMercury(){
     
    double weightOnMercury=0.0;
     
    return  (weightOnMercury*0.4);
     
    }
     
    double calculateWeightOnVenus(){
     
    double weightOnVenus=0.0;
     
    return  (weightOnVenus*0.9);
     
    }
     
    double calculateWeightOnJupiter(){
     
    double weightOnJupiter=0.0;
     
    return  weightOnJupiter*2.5;
     
    }
     
    double calculateWeightOnSaturn(){
     
    double weightOnSaturn=0.0;
     
    return  (weightOnSaturn*1.1);
     
    }
     
    }

  5. #4
    Junior Member
    Join Date
    Feb 2012
    Posts
    10
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: help pulling information from different classes when you have more than one

    I figured it out! Thank you for your help!!!
     
    public double convertKilogramsToPounds(double weightInKilograms){
     
    return  (weightInKilograms*2.20462262);
     
    }

Similar Threads

  1. can't get all the information out of my array at once... please help
    By Tate in forum What's Wrong With My Code?
    Replies: 3
    Last Post: November 28th, 2010, 06:22 AM
  2. Pulling Data from Website
    By aussiemcgr in forum Java Theory & Questions
    Replies: 0
    Last Post: August 20th, 2010, 09:42 AM
  3. Pulling in data from access
    By tdc5013 in forum JDBC & Databases
    Replies: 2
    Last Post: March 15th, 2010, 05:40 PM
  4. Getting information from a folder
    By shadihrr in forum File I/O & Other I/O Streams
    Replies: 1
    Last Post: February 23rd, 2010, 04:13 PM
  5. Passing Information between classes
    By SKhoujinian91 in forum Object Oriented Programming
    Replies: 4
    Last Post: December 8th, 2009, 03:40 PM