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.
This is my Class Name: RecommendedWeight: I think this is correct.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); } }
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 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; } }
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.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; } }