Do the following programming exercises:
// a triangle with sides of length 4, 5, and 6 Triangle t = new Triangle(4, 5, 6);
s = (side1 + side2 + side3) / 2 area = square root of (s * (s - side1) * (s - side2) * (s - side3))
public interface Eatable { public String howToEat(); }Every class of an eatable object must implement the Eatable interface. Create the following sets of classes:
For each class that implements Eatable, the howToEat method needs to be defined to return the eating instructions (as a String).
You can use the following main program to test:
public class EatingTest { public static void main(String[] args) { Object[] objects = { new Object(), new Animal(), new Tiger(), new Chicken(), new Elephant(), new Fruit(), new Apple(), new Orange() }; for (int i = 0; i < objects.length; i++) { showObject(objects[i]); } } public static void showObject(Object object) { System.out.print(object); if (object instanceof Eatable) { System.out.print(((Eatable)object).howToEat()); } System.out.println(); } }
java.lang.Object@f4a24a Animal Tiger Chicken (pluck then cook) Elephant Fruit (eat raw) Apple (polish) Orange (peel)
Note: The toString() method for class Object (the base class version) returns a string consisting of the name of the class, the '@' symbol, and the hash code of the object (in hexadecimal format). Your output for the toString() method of the Object instance may not look exactly like mine.
E-mail this jar file to me (myers@cs.fsu.edu) by the due date. Your
e-mail subject should be HW7-SUBMIT. Include your name and section
in the e-mail body. Please only submit ONCE, unless you make a mistake
and need to correct it (before the due date) -- and minimize this. Only
the last submission will be graded.