-
Notifications
You must be signed in to change notification settings - Fork 64
Expand file tree
/
Copy pathApp.java
More file actions
54 lines (41 loc) · 1.51 KB
/
App.java
File metadata and controls
54 lines (41 loc) · 1.51 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
package io.zipcoder;
import io.zipcoder.pets.Cat;
import io.zipcoder.pets.Dog;
import io.zipcoder.pets.Horse;
import io.zipcoder.pets.Pet;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
public class App {
List<Pet> petList = new ArrayList<Pet>();
Console menu = new Console(System.in, System.out);
public void runApp() {
int numberOfPets;
numberOfPets = this.menu.getIntegerInput("How many pets do you have?");
for (int i = 0; i < numberOfPets; i++) {
String petType = "";
String petName = "";
petType = this.menu.getStringInput("What type is pet: " + (i+1) + "?");
addPet(petType);
petName = this.menu.getStringInput("What is the pet name?");
this.petList.get(i).setName(petName);
}
printPets();
}
public void addPet(String petType){
petType = petType.toLowerCase();
if (petType.equals("cat")) this.petList.add(new Cat());
if (petType.equals("dog")) this.petList.add(new Dog());
if (petType.equals("horse")) this.petList.add(new Horse());
}
public void printPets(){
int i = 0;
for (Pet eachPet : this.petList){
String petInfo = "";
petInfo = petInfo.concat(this.petList.get(i).getPetType().concat(": " + this.petList.get(i).getName()));
petInfo = petInfo.concat(" - " + this.petList.get(i).speak());
this.menu.println(petInfo);
i++;
}
}
}