Advertisement
Guest User

Untitled

a guest
Jan 18th, 2020
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.15 KB | None | 0 0
  1. public void giveDog() {
  2. System.out.println("Enter the name of the dog?> ");
  3.  
  4. String specifiedDog = scanner.nextLine().trim();
  5.  
  6. if (dogUtils.checkIfDogExists(specifiedDog, dogs)) {
  7. System.out.println("Error: no dog with that name");
  8. runCommandLoop();
  9. }
  10.  
  11. if (dogUtils.checkIfDogHasOwner(specifiedDog, dogs)) {
  12. System.out.println("Error: the dog already has an owner");
  13. runCommandLoop();
  14. }
  15.  
  16. String specifiedNewOwner = inputUserName();
  17.  
  18. for (int i = 0; i < dogs.size(); i++) {
  19. if (dogs.get(i).getName().toLowerCase().equals(specifiedDog.toLowerCase())) {
  20.  
  21. for (int j = 0; j < users.size(); j++) {
  22. if (users.get(j).getName().toLowerCase().equals(specifiedNewOwner.toLowerCase())) {
  23. users.get(j).addOwnedDog(dogs.get(i).getName());
  24. dogs.get(i).setUser(users.get(j));
  25.  
  26. System.out.println(users.get(j).getName() + " now owns " + dogs.get(i).getName());
  27.  
  28. }
  29. }
  30. }
  31. }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement