Advertisement
Guest User

Untitled

a guest
Apr 25th, 2018
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.43 KB | None | 0 0
  1. package backpack;
  2.  
  3. import java.util.ArrayList;
  4.  
  5. /**Class: Aquarium
  6. * @author Rick Price
  7. * @version 1.0
  8. * Course : ITEC 2140 Fall 2017
  9. * Written: November 16, 2014
  10. *
  11. *
  12. * This class build the Aquarium class. This class manages the aquarium used on test 2
  13. *
  14. * Purpose: Manage the list of fish created for test 2 extra credit
  15. */
  16. public class Aquarium
  17. {
  18. private ArrayList<Fish> allFish = new ArrayList<Fish>();
  19.  
  20. /** Method: getFish
  21. * @param int fishNum - the number of the fish the user wants to return
  22. * @return Fish, the fish requested by the user
  23. */
  24. public Fish getFish(int fishNum)
  25. {
  26. try
  27. {
  28. if (fishNum > allFish.size())
  29. {
  30. System.out.println("Fish out of range. Returning the last fish.");
  31. return allFish.get(allFish.size()-1);
  32. }
  33. else if (fishNum < 0)
  34. {
  35. System.out.println("Fish number too small. Returning the first fish");
  36. return allFish.get(0);
  37. }
  38. else
  39. {
  40. return allFish.get(fishNum);
  41. }
  42. }
  43. catch (IndexOutOfBoundsException iob)
  44. {
  45. System.out.println("No fish in the aquarium yet");
  46. return new Fish();
  47. }
  48. }
  49.  
  50. /** Method: addFish
  51. * @param Fish the fish the user wants to add
  52. * @return none
  53. */
  54. public void addFish(Fish newFish)
  55. {
  56. allFish.add(newFish);
  57. }
  58.  
  59. /** Method: getNumFish
  60. * @param none
  61. * @return int the number of fish in the aquarium
  62. */
  63. public int getNumFish()
  64. {
  65. return allFish.size();
  66. }
  67.  
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement