-
Notifications
You must be signed in to change notification settings - Fork 64
Expand file tree
/
Copy pathApplication.java
More file actions
72 lines (55 loc) · 2.22 KB
/
Application.java
File metadata and controls
72 lines (55 loc) · 2.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package io.zipcoder;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Scanner;
public class Application {
private int numberOfPetsOwned;
private Scanner userInput= new Scanner(System.in);
private ArrayList<String> petName = new ArrayList<String>();
private ArrayList<String> petType = new ArrayList<String>();
private ArrayList<Pets> petCollector = new ArrayList<>();
private HashMap<String, String> petList = new HashMap<String, String>();
public static void main(String[] args) {
Application app = new Application();
app.numberOfPets();
app.getPetCollection();
app.allPetsSpeak();
}
public Integer numberOfPets() {
System.out.println("Where are my manners... Hello Human!! Its a pleasure to meet your" +
" acquaintance. Would you be so kind as to tell me how many pets do you own? " +
"(please enter an integer greater than 0).");
int tempCount = userInput.nextInt();
userInput.nextLine();
if (tempCount > 0) {
numberOfPetsOwned = tempCount;
} else {
numberOfPets();
}
return numberOfPetsOwned;
}
public void getPetCollection() {
for (int i = 0; i < numberOfPetsOwned; i ++) {
String name;
String type;
System.out.println("What is the name of pet #" + (i+1) + " ?");
name = userInput.nextLine();
System.out.println("Please identify the type of pet (Dog, Cat or Snake)" + "that " + name + " is.");
type = userInput.nextLine();
this.petCollector.add(PetFactory.petCreator(type, name));
}
}
public void petListBuilder(ArrayList<String> petType, ArrayList<String> petName) {
for (int i = 0; i < petType.size(); i++) {
petList.put(petType.get(i), petName.get(i));
}
}
public String getPetFromList (String key) {
return this.petList.get(key);
}
public void allPetsSpeak() {
for (Pets pet: petCollector) {
System.out.println("Your " + pet.getClass().getSimpleName() + " named " + pet.getName() + " says \"" + pet.speak() + "\"");
}
}
}