Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package backpack;
- import java.util.ArrayList;
- /**Class: Aquarium
- * @author Rick Price
- * @version 1.0
- * Course : ITEC 2140 Fall 2017
- * Written: November 16, 2014
- *
- *
- * This class build the Aquarium class. This class manages the aquarium used on test 2
- *
- * Purpose: Manage the list of fish created for test 2 extra credit
- */
- public class Aquarium
- {
- private ArrayList<Fish> allFish = new ArrayList<Fish>();
- /** Method: getFish
- * @param int fishNum - the number of the fish the user wants to return
- * @return Fish, the fish requested by the user
- */
- public Fish getFish(int fishNum)
- {
- try
- {
- if (fishNum > allFish.size())
- {
- System.out.println("Fish out of range. Returning the last fish.");
- return allFish.get(allFish.size()-1);
- }
- else if (fishNum < 0)
- {
- System.out.println("Fish number too small. Returning the first fish");
- return allFish.get(0);
- }
- else
- {
- return allFish.get(fishNum);
- }
- }
- catch (IndexOutOfBoundsException iob)
- {
- System.out.println("No fish in the aquarium yet");
- return new Fish();
- }
- }
- /** Method: addFish
- * @param Fish the fish the user wants to add
- * @return none
- */
- public void addFish(Fish newFish)
- {
- allFish.add(newFish);
- }
- /** Method: getNumFish
- * @param none
- * @return int the number of fish in the aquarium
- */
- public int getNumFish()
- {
- return allFish.size();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement