Here we would like you to rewrite the program using a class to represent the pla
ID: 3661860 • Letter: H
Question
Here we would like you to rewrite the program using a class to represent the planet and its gravity. The class should include a constructor that allows a planet to be specified with a string, using any capitalization (if the spring is not a planet name, then earth should be assumed). The default constructor for the class will create an object representing earth. the class has an observer operator that takes a weight on earth as an argument and return the weight on the planet. It should have a second observer that returns the name of the planet as a string with proper capitalization. For ease of reference, the information for the original problem is repeated here. The following table gives the factor by which the weight must be multiplied for each planet. The program should output an error ,message should make it clear to the user how a planet name must be entered. Be sure to use proper formatting and include appropriate comments in your code. The output should be labeled clearly and formatted neatly. Mercury 0.4155 Venus 0.8975 Earth 1.0 Moon 0.166 Mars 0.3507 Jupiter 2.5374 Saturn 1.0677 Uranus 0.8974 Neptune 1.1794 Pluto 0.0899
Explanation / Answer
class planet
{
String pla;
planet()
{
pla="Earth";
}
double earth(double wt)
{
return wt;
}
String planet_name(String pl)
{
return pl.toUpperCase();
}
}
class planet_test
{
public static void main(String args[])
{
planet p=newplanet();
double w=p.earth(1);
System.out.println("Earth weight is "+w);
String n=p.planet_name("jupiter");
System.out.println("Capitalized name is "+n);
}
}