Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public void giveDog() {
- System.out.println("Enter the name of the dog?> ");
- String specifiedDog = scanner.nextLine().trim();
- if (dogUtils.checkIfDogExists(specifiedDog, dogs)) {
- System.out.println("Error: no dog with that name");
- runCommandLoop();
- }
- if (dogUtils.checkIfDogHasOwner(specifiedDog, dogs)) {
- System.out.println("Error: the dog already has an owner");
- runCommandLoop();
- }
- String specifiedNewOwner = inputUserName();
- for (int i = 0; i < dogs.size(); i++) {
- if (dogs.get(i).getName().toLowerCase().equals(specifiedDog.toLowerCase())) {
- for (int j = 0; j < users.size(); j++) {
- if (users.get(j).getName().toLowerCase().equals(specifiedNewOwner.toLowerCase())) {
- users.get(j).addOwnedDog(dogs.get(i).getName());
- dogs.get(i).setUser(users.get(j));
- System.out.println(users.get(j).getName() + " now owns " + dogs.get(i).getName());
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement