Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package aquarium;
- import java.util.ArrayList;
- import java.util.LinkedHashMap;
- import java.util.List;
- import java.util.Map;
- public class Aquarium {
- private LinkedHashMap<String, Fish> fishInPool;
- private String name;
- private int capacity;
- private int size;
- public Aquarium(String name, int capacity, int size) {
- this.fishInPool = new LinkedHashMap<>();
- this.name = name;
- this.capacity = capacity;
- this.size = size;
- }
- public String getName() {
- return this.name;
- }
- public int getCapacity() {
- return this.capacity;
- }
- public int getSize() {
- return this.size;
- }
- public void add(Fish fish) {
- if (this.fishInPool.size() < this.getCapacity()) {
- if(!this.fishInPool.containsKey(fish.getName())){
- this.fishInPool.put(fish.getName(),new Fish(fish.getName(),fish.getColor(),fish.getFins()));
- }
- }
- }
- public boolean remove(String name) {
- if (this.fishInPool.containsKey(name)) {
- this.fishInPool.remove(name);
- return true;
- }
- return false;
- }
- public int getFishInPool() {
- return this.fishInPool.size();
- }
- public Fish findFish(String name) {
- if (this.fishInPool.containsKey(name)) {
- return this.fishInPool.get(name);
- }
- return null;
- }
- public String report() {
- StringBuilder sb = new StringBuilder();
- String append = String.format("Aquarium: %s ^ Size: %d", this.getName(), this.getSize());
- sb.append(append);
- sb.append(System.lineSeparator());
- for (Map.Entry<String, Fish> stringFishEntry : this.fishInPool.entrySet()) {
- sb.append(stringFishEntry.getValue().toString());
- sb.append(System.lineSeparator());
- }
- return sb.toString();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement