Question: This assignment will put into practice the following topics: ArrayLists ( Chapter 1 1 ) Collections.sort ( Chapter 1 1 ) Polymorphism ( Chapter 1
This assignment will put into practice the following topics:
ArrayLists Chapter
Collections.sortChapter
Polymorphism Chapter
Abstract Classes Chapter
Interfaces ComparableChapter
composition Chapter
For this assignment, we are going to simulate a aquarium that contains fish. One rule about aquariums is that there is a limit to how many fish it can hold due to oxygen consumption. If you add too many, there won't be enough oxygen and the fish will die. So the careful aquarium owner will keep track of the fish added to the tank so as to maintain a healthy environment for the fish. You'll write a application that helps aquarium owners determine how many fish can be added to a tank. Here's a UML diagram of the classes needed to solve the problem:
Image Attached
Fish
Fish will be an abstract class. It's meant to model the common characteristics of all fish. It's a class we will never create an instance of but it is useful as it defines the attributes and behavior for all subclasses of fish. In this model, we are stating that all fish swim in a zone, and have some amount of oxygen consumption.
zone is an integer representing the zone of the aquarium where the fish spends most of it's time. The zones are defined as follows: top middle bottom
There is one constructor, that takes an integer representing the zone and saves it in the instance variable named zone.
There is a getter method for zone variable.
There is an abstract method shown in italics in UML named getOxygenConsumption that returns the oxygen content needed by the fish.
There is an abstract method shown in italics in UML named swim that returns a String representing how the fish swims.
The two abstract methods are "instructions" to subclasses. Any subclass that we want to create an instance of will have to define howwhere they swim, and how much oxygen they require.
Note that the abstract class Fish implements the Comparable interface. This interface is part of the Java API and does not have to be created in this assignment. Since Fish implements Comparable, it means that it must provide a concrete implementation of the compareTo method. We will use it to sort the fish by zone. The compareTo method will be analogous to the ComparableRectangle in listing except we will order by zone, instead of area.
subclasses of Fish
default constructor: for all subclasses are simple and contain just one line of code: a call to the super class constructor, passing a integer representing the zone they swim in There are no other constructors for subclasses of Fish.
Danio's swim at the top, so it should forward a to the superclass constructor.
Tetra's swim in the middle, so it should forward a to the superclass constructor.
Cory's swim at the bottom, so it should forward a to the superlcass constructor.
getOxygenConsumption: This method just returns an integer representing how much oxygen the fish requires. It could be the result of a calculation, but we'll keep it simple and return an integer as follows:
Danios: return
Tetras: return ;
Corys: return ;
swim: This method describes how a particular type of fish swim. For our model, we'll return a string in each sublcass as follows:
Danios: return "Danio darting".
Tetras: return "Tetra gliding".
Corys: return Cory just hanging out".
Aquarium
This class contains our fish. To hold our fish, you will use an ArrayList with the concrete type set to Fish as shown in UML ArrayLists allow us to add items to the list without worrying if we are going back the end of the list, as it resizes the list for us And, it is part of the Collections framework, which allows us to do things like sort the ArrayList assuming we implement comparable
You should have a instance variable that represents the oxygen content of the tank. This will be based on the surface area of the tank.
It continues in the image attached because this space only allows characters.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
