Test on Classes Name _____________________________ Date _____________ Given public class Planet { private String name; private double weight; private double circumference; public Planet(String n, double w, double c) {} public double getWeight(){ } public void printWeight() { } public void printInfo() { } public String toString() { } public int compareByWeight(Planet p){ } public int compareByName(Planet p) {} } For each of the following re-write the heading and number your answers . Make sure to include braces. 1. Write the constructor for the Planet class. 2. Write the getWeight() member function 3. Write the toString() member function returning the planet name. 4. Write the compareByWeight function 5. Write the compareByName function 6. Write the printWeight() function 7. Write the printInfo() function printing out all the information about the planet. Given the following declarations in the main program Planet p1 = new Planet(“Venus”,5000,67); Planet p2 = new Planet(“Mars”,400,53); 8. Two of the following are correct ways to print Venus’ weight. a. p1.getWeight() b. System.out.println(p1.getWeight()); c. p1.printWeight(); d. System.out.println(p1.printWeight()); e. p1.toString(); what are they? ______________ 9. Using an if-then structure write code that will print out the name of the planet with the greatest weight using the compareByWeight() function. 10. Using an if-then structure write code that will print out the planet with the greatest weight without using the compareBy Weight() member function. 11. Write code that will print out Venus’ name. 12. Write code that will print out all the information about Mars. 13. Complete the code that will assign to we Mar’s weight. double we = 14. Complete the code that will assign the name of planet p1 to p p = The Integer class is a built in class that has the following member functions public Integer(int n) String toString() int compareTo(Object o) 15. Write code that will initialize 2 Integer objects to two int values – you pick the values (call the objects n1 and n2) 16. Write code that will print out the Integer n1 in reverse order (if the number was 5421 it will print out 1245) 17. Write code that will print out the largest number of the two objects (assume they are not the same) Given class fraction { private int num; private int den; public fraction() // default constructor - set num to 0, den to 1{} public fraction(int n,int d){} public void reduce(){ } public int getden(){ } public int getnum(){} public fraction multiply(fraction f){} public String toString(){} } Number and write heading with braces for all answers 18. Write the reduce() member function. 19. Write the multiply member function. 20. Write the toString() member function