-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDoggiesDobranowski.java
53 lines (43 loc) · 1.29 KB
/
DoggiesDobranowski.java
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
//(c) A+ Computer Science
//www.apluscompsci.com
//Name - Patrick Dobranowski
//Date - 02/16/2021
import java.util.Arrays;
public class DoggiesDobranowski {
private DogDobranowski[] pups;
public DoggiesDobranowski(int size) {
// point pups at a new arry of Dog
pups = new DogDobranowski[size];
}
public void set(int spot, int age, String name) {
// put a new Dog in the array at spot
// make sure spot is in bounds
if (spot < pups.length)
pups[spot] = new DogDobranowski(age, name);
}
public String getNameOfOldest() {
String nameOfOldest = "";
int oldestAge = Integer.MIN_VALUE;
for (DogDobranowski d : pups) {
if (d.getAge() > oldestAge) {
oldestAge = d.getAge();
nameOfOldest = d.getName();
}
}
return nameOfOldest;
}
public String getNameOfYoungest() {
String nameOfYoungest = "";
int youngestAge = Integer.MAX_VALUE;
for (DogDobranowski d : pups) {
if (d.getAge() < youngestAge) {
youngestAge = d.getAge();
nameOfYoungest = d.getName();
}
}
return nameOfYoungest;
}
public String toString() {
return "" + Arrays.toString(pups);
}
}