Advertisement
Guest User

Untitled

a guest
Feb 20th, 2020
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.94 KB | None | 0 0
  1. package aquarium;
  2.  
  3. import java.util.ArrayList;
  4. import java.util.LinkedHashMap;
  5. import java.util.List;
  6. import java.util.Map;
  7.  
  8.  
  9. public class Aquarium {
  10. private LinkedHashMap<String, Fish> fishInPool;
  11. private String name;
  12. private int capacity;
  13. private int size;
  14.  
  15. public Aquarium(String name, int capacity, int size) {
  16. this.fishInPool = new LinkedHashMap<>();
  17. this.name = name;
  18. this.capacity = capacity;
  19. this.size = size;
  20. }
  21.  
  22. public String getName() {
  23. return this.name;
  24. }
  25.  
  26. public int getCapacity() {
  27. return this.capacity;
  28. }
  29.  
  30. public int getSize() {
  31. return this.size;
  32. }
  33.  
  34. public void add(Fish fish) {
  35. if (this.fishInPool.size() < this.getCapacity()) {
  36. if(!this.fishInPool.containsKey(fish.getName())){
  37. this.fishInPool.put(fish.getName(),new Fish(fish.getName(),fish.getColor(),fish.getFins()));
  38. }
  39.  
  40. }
  41. }
  42.  
  43. public boolean remove(String name) {
  44. if (this.fishInPool.containsKey(name)) {
  45. this.fishInPool.remove(name);
  46. return true;
  47. }
  48. return false;
  49. }
  50.  
  51. public int getFishInPool() {
  52. return this.fishInPool.size();
  53. }
  54.  
  55. public Fish findFish(String name) {
  56. if (this.fishInPool.containsKey(name)) {
  57.  
  58. return this.fishInPool.get(name);
  59. }
  60. return null;
  61. }
  62.  
  63. public String report() {
  64. StringBuilder sb = new StringBuilder();
  65. String append = String.format("Aquarium: %s ^ Size: %d", this.getName(), this.getSize());
  66. sb.append(append);
  67. sb.append(System.lineSeparator());
  68. for (Map.Entry<String, Fish> stringFishEntry : this.fishInPool.entrySet()) {
  69. sb.append(stringFishEntry.getValue().toString());
  70. sb.append(System.lineSeparator());
  71. }
  72.  
  73. return sb.toString();
  74. }
  75. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement