-
Notifications
You must be signed in to change notification settings - Fork 64
Expand file tree
/
Copy pathQuestionairre.java
More file actions
81 lines (69 loc) · 2.36 KB
/
Questionairre.java
File metadata and controls
81 lines (69 loc) · 2.36 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
73
74
75
76
77
78
79
80
81
package io.zipcoder;
import io.zipcoder.Pets.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
public class Questionairre {
protected int numOfPets;
protected ArrayList<Pet> petArrayList;
public Questionairre(){
petArrayList = new ArrayList<>();
}
public ArrayList<Pet> getPetArrayList() {
return petArrayList;
}
public void numOfPetsPrompt() {
Console.print("Hello dear user. How many pets do you have?");
numOfPets = Console.getInt();
}
public void setPetArrayList(){
Console.print("Thanks! What kind of pets do you have? Please specify using only the following:");
for (int i = 0; i < numOfPets; i++) {
Console.print(Arrays.toString(PetTypes.values()));
String usersKindOfPets = Console.getString();
Console.print("What's their name?");
String name = Console.getString();
Console.print("How old is this pet?");
int age = Console.getInt();
petTypeSwitch(usersKindOfPets, name, age);
}
}
public String speakNSay() {
String petList = "";
for (Pet currentPet:petArrayList) {
petList += ("The " + currentPet.getClass().getSimpleName() + " named " + currentPet.getName()
+ " says " + currentPet.speak() + ". ");
}
System.out.println(petList);
return petList;
}
public void petListTypeSort() {
Collections.sort(petArrayList, new SortByPetType());
for (Pet pet:petArrayList) {
System.out.println(pet.getName());
}
}
public void petListNameSort() {
Collections.sort(petArrayList);
for (Pet pet:petArrayList){
System.out.println(pet.getName());
}
}
public void petTypeSwitch(String usersKindOfPets, String name, int age) {
Pet tempPet;
switch (usersKindOfPets.toLowerCase()) {
case "cat":
tempPet = new Cat(name, age);
petArrayList.add(tempPet);
break;
case "dog":
tempPet = new Dog(name, age);
petArrayList.add(tempPet);
break;
case "capybara":
tempPet = new Capybara(name, age);
petArrayList.add(tempPet);
break;
}
}
}