$30.00
Order NowIn this assignment, you will implement a Fish/Lake simulation similar to the
previous assignment. You will then make adjustments to accommodate class
hierarchies and make use of inheritance as well as a JAVA interface.
(1) The Basic Classes
Consider the following Fish, Lake and Fisher classes. Create a folder called Part1 and copy all the code
into unique files into that folder and then compile them:
______________________________________________________________________________ public class Fish {
// Any fish below this size must be thrown back into the lake
public static int THROW_BACK_SIZE = 18;
protected int size;
protected float weight;
public Fish(int aSize, float aWeight) {
size = aSize;
weight = aWeight;
}
public boolean isDesirableTo(Fisher f) {
// Replace the line below with your code
return false;
}
public boolean canKeep() {
// Replace the line below with your code
return false;
}
public int getSize() { return size; }
public float getWeight() { return weight; }
public String toString () {
return (“A ” + size + “cm ” + weight + “kg Fish”);
}
}
______________________________________________________________________________ public class Lake {
private Fish[] catchableThings;
private int numThings;
public Lake(int capacity) {
catchableThings = new Fish[capacity];
numThings = 0;
}
public int getNumCatchableThings() { return numThings; }
public boolean isFull() { return numThings == catchableThings.length; }
public String toString() { return “Lake with ” + numThings + ” catchable things”; }
// Add the given thing to the lake
public void add(Fish aCatchableThing) {
if (numThings < catchableThings.length)
catchableThings[numThings++] = aCatchableThing;
}
// Choose a random thing to be caught in the lake and return it
public Fish catchSomething() {
if (numThings == 0) return null;
int index = (int)(Math.random() * numThings);
Fish f = catchableThings[index];
catchableThings[index] = catchableThings[numThings-1];
catchableThings[numThings-1] = null;
numThings--;
return f;
}
// List all things in the lake
public void listAllThings() {
System.out.println(" " + this + " as follows:");
for (int i=0; i
for (int i=0; i
WhatsApp us