Assignment #7 - Chapter 8: Inheritance and Interfaces

Due: Thursday, July 10

From chapter 8, do programming exercises 8.1 and 8.6 (page 334) - Also note the extra instructions below.


Filenames should be

Note that these filenames all start with a capital letter. Please make your filenames match mine exactly.

Extra Instructions

  1. For exercise 8.1, write the source code in a file named Triangle.java. To compile this, you will need to use the GeometricObject class from the chapter 8 examples. Do not hand in the GeometricObject file -- you only need to hand in the Triangle.java file.
  2. For exercise 8.6:

The Prob8_6 class

public class Prob8_6
{
    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)
        {
            ((Eatable)object).howToEat();
        }
        System.out.println();
    }
}

Sample run of Exercise 8.6

 java.lang.Object@f4a24a
 Animal
 Tiger
 Chicken (pluck then cook)
 Elephant
 Fruit (eat raw)
 Apple (polish)
 Orange (peel)

Compiling

Remember that the compile command is "javac", at the unix command prompt. Compile your code on program.cs.fsu.edu, and then run your programs with the "java" command.

Submitting:

Submit programs through the submission web page.