desislava_topuzakova

Grooming Salon

Feb 12th, 2022
427
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.38 KB | None | 0 0
  1. package groomingSalon;
  2.  
  3. import java.util.ArrayList;
  4. import java.util.List;
  5.  
  6. public class GroomingSalon {
  7. private List<Pet> data;
  8. private int capacity;
  9.  
  10. public GroomingSalon(int capacity) {
  11. this.capacity = capacity;
  12. this.data = new ArrayList<>();
  13. }
  14.  
  15. public void add(Pet pet) {
  16. //проверка има ли място в салона
  17. if (this.data.size() < capacity) {
  18. this.data.add(pet);
  19. }
  20. }
  21.  
  22. public boolean remove(String name) {
  23. for (Pet pet : this.data) {
  24. if (pet.getName().equals(name)) {
  25. return this.data.remove(pet);
  26. }
  27. }
  28. return false;
  29. }
  30.  
  31. public Pet getPet(String name, String owner) {
  32. for (Pet pet : this.data) {
  33. if (pet.getName().equals(name) && pet.getOwner().equals(owner)) {
  34. return pet;
  35. }
  36. }
  37. return null;
  38. }
  39.  
  40. public int getCount() {
  41. return this.data.size();
  42. }
  43.  
  44. public String getStatistics() {
  45. StringBuilder builder = new StringBuilder();
  46. builder.append(" The grooming salon has the following clients:").append("\n");
  47. for (Pet pet : this.data) {
  48. builder.append(pet.getName()).append(" ").append(pet.getOwner()).append("\n");
  49. }
  50. return builder.toString();
  51. }
  52. }
  53.  
Advertisement
Add Comment
Please, Sign In to add comment