I have three assignments using bluej program im a learner at it i have done he first two assignment but the last one is causing me grief to no better end i have hopefully attached the file with this message.
The question i need to know is
This in only in the Tank Class
Task A
1 i can only at the moment have one fish in the tank i need to increase the amount of fish in the tank.
2 be able to ad a fish to the Tank.
3 Remove a fish from the Tank.
4 Have a method to get the population of the Tank.
Task B
1 In my getFish method i Need to change method so that it returns a fish based on an index passed in.
2 In my hasFish method i need method to return true value if is a fish in the tank.
3 In my printTank method in this method, change the method so that it prints out the number of fish in the tank and print out the list of the fish in the tank.
4 In my feed method in this method the fish that gets fed is determined randomly.
if cannot down load file here is the code
Any help much appreciated thankyou from me IN NZAny help much appreciated thankyou from me IN NZ/** * * Charlie Ngatai * @v3 */ import java.util.ArrayList; public class Tank { private Fish myFish; private Feeder feeder; private boolean full; private boolean hasFeeder; /** * Constructor for objects of class Tank */ public Tank() { full = false; hasFeeder = false; myFish = null; feeder = null; } /** * Add a fish to the Tank. * @param fish, the fish to the tank */ public void addFish(Fish fish) { // Can only have one fish if(!full) { myFish = fish; full = false; } else { System.out.println("Sorry there is no room in the tank. It is already occupied and the resident fish will not share. "); } } /** * Remove the fish - eg if it has died. */ public void removeFish() { // Can only remove if there is a fish there if(full) { myFish = null; full = false; } } /** * Returns the tank's fish (which may be null). * @return The fish that lives in the tank */ public Fish getFish() { return myFish; } /** * Returns True if a fish is living in the tank. False if the tank is empty. * @return the emptiness of the tank. */ public boolean hasFish() { return full; } /** * Prints information about this tank and any fish living in it. */ public void printTank() { System.out.println("************************"); System.out.println("Welcome to my Tank"); if(full) { System.out.println("There is a fish living in it."); System.out.println(myFish.toString()); } else { System.out.println("The tank is currently empty"); } } /** * Method to attach a new feeder to the Tank * @param newFeeder */ public void addFeeder(Feeder newFeeder) { if(!hasFeeder) feeder = newFeeder; } /** * Allows the feeder to be removed */ public void removeFeeder() { // Can only remove if there is a feeder there if(hasFeeder) { feeder = null; hasFeeder = false; } } /** * Method to restock the feeder * @param amount - int * @param food - food */ public void restock(int amount, String food) { if (food.equals("Fish food pellets")|| food.equals("Spirulina pellets")|| food.equals("Brine Shrimp")|| food.equals("Whole wheat flake")) { feeder.changeFoodLevel(amount); feeder.setFoodType(food); } } /** * Feeds the fish in the tank. */ public void feed() { int flare = feeder.getFlare(); feeder.changeFoodLevel(-flare); myFish.eat(flare); } /** * Simulates the passing week */ public void simulateWeeks(int weeks) { for (int week = 1; week < weeks; week++) { for(int day = 1; day < 7; day++) { System.out.println("The fish has been fed."); feed(); System.out.println("The fish has swam 50 m."); myFish.swim(50); } System.out.println("The fish has a birthday."); myFish.birthday(); } } }