Define a SeaLife class with the following private members:

  • String name
  • String color

and public members:

  • Constructors
  • getters, setters
  • toString() -- overridden from Object

Define a subclasses Fish and Crustacean that each extends the SeaLife class.

The Fish class should have the following private members:

  • int numFins
  • int dir // -1, 0, 1, 2, 3 to indicate hovering with (-1), or swimming N,E,S,W (0,1,2,3 respectively).

and public members:

  • Constructors
  • getters, setters
  • boolean isSwinming() // returns false iff dir /= -1
  • boolean isHovering () // returns true iff dir == -1
  • toString() -- overridden appropriately from SeaLife

The Crustacean class should have the following private members:

  • int numClaws
  • int dir // -1, 0, 1, 2, 3 to indicate hiding with (-1), or crawling N,E,S,W (0,1,2,3 respectively).

and public members:

  • Constructors
  • getters, setters
  • boolean isCrawling() // returns false iff dir /= -1
  • boolean isHiding () // returns true iff dir == -1
  • SeaLife wins(SeaLife sl) // returns a reference to this object or s1, randomly
  • toString() -- overridden appropriately from SeaLife

Write a main program with the following declarations:

Fish fish1, fish2;
Crustacean lobster, crab;

Initialize the above references to objects with attributes of your choice. Print out the attributes of each, using toString().

“Stage a few battles” (by invoking wins) between fish1, fish2, lobster and crab, and print the name ofwho wins.

Add a SeaLife array to your main method by declaring: SeaLife[] creatures = new SeaLife[4]. Fill itwith 2 Fish objects and 2 Crustacean objects. Traverse the array with a loop to print out details of eachobject. Use toString() polymorphically.

Place the following statements in your main method in order to report which compile and run ok,which do not compile ok, which compile ok but produce a runtime error.

SeaLife creatureA, creatureB;
creatureA = fish1;
creatureB = lobster;
lobster = fish1;
lobster = crab; // what is lobster’s name now?
boolean b = creatureA.isSwimming();
boolean c = (Fish) creastureA.isSwimming;
boolean d = creatureB.isSwimming();
boolean e = (Fish) creatureB.isSwimming();
Academic Honesty!
It is not our intention to break the school's academic policy. Projects posted are only used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly fill out the form. Please provide a valid email address and we'll get back to you in less than 24 hours. We will be sending an invoice through PayPal upon confirmation. We are a non profit organization however we need an amount to keep this organization running, and to be able to complete our research and development.