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

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

1. ## 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.  Reply With Quote

3. ## 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.  Reply With Quote

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

mickey2012 (February 6th, 2012)

5. ## 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);

}

}```  Reply With Quote

6. ## 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);

}```  Reply With Quote