Skip to content

Commit 2d72e1f

Browse files
committed
Feat: Changes
1 parent 52f8b4f commit 2d72e1f

File tree

1 file changed

+59
-57
lines changed
  • lesson_16/objects/objects_app/src/main/java

1 file changed

+59
-57
lines changed
Lines changed: 59 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,78 +1,80 @@
1-
21
import java.util.ArrayList;
32
import java.util.List;
43

54
public class Dog implements DogTest {
65

7-
// Custom exception
8-
public static class DogAgeException extends Exception {
6+
// Custom exception
7+
public static class DogAgeException extends Exception {
98

10-
public DogAgeException(String message) {
11-
super(message);
12-
}
9+
public DogAgeException(String message) {
10+
super(message);
1311
}
12+
}
1413

15-
// Enum for dog colors
16-
public enum Colors {
17-
WHITE, BROWN, BLONDE
18-
}
14+
// Enum for dog colors
15+
public enum Colors {
16+
WHITE,
17+
BROWN,
18+
BLONDE
19+
}
1920

20-
// Member variables
21-
private int age;
22-
private String breed;
23-
private String gender;
24-
private Colors color;
25-
private boolean isFed;
26-
private List<String> favoriteToys;
21+
// Member variables
22+
private int age;
23+
private String breed;
24+
private String gender;
25+
private Colors color;
26+
private boolean isFed;
27+
private List<String> favoriteToys;
2728

28-
// Constructor
29-
public Dog(int age, String breed, String gender, Colors color, boolean isFed) throws DogAgeException {
30-
if (age < 0) {
31-
throw new DogAgeException("Age cannot be negative.");
32-
}
33-
this.age = age;
34-
this.breed = breed;
35-
this.gender = gender;
36-
this.color = color;
37-
this.isFed = isFed;
38-
this.favoriteToys = new ArrayList<>();
29+
// Constructor
30+
public Dog(int age, String breed, String gender, Colors color, boolean isFed)
31+
throws DogAgeException {
32+
if (age < 0) {
33+
throw new DogAgeException("Age cannot be negative.");
3934
}
35+
this.age = age;
36+
this.breed = breed;
37+
this.gender = gender;
38+
this.color = color;
39+
this.isFed = isFed;
40+
this.favoriteToys = new ArrayList<>();
41+
}
4042

41-
// Member functions
42-
public String getDogDescription() {
43-
return age > 5 ? "Senior Dog" : "Young Dog"; // Conditional expression
44-
}
43+
// Member functions
44+
public String getDogDescription() {
45+
return age > 5 ? "Senior Dog" : "Young Dog"; // Conditional expression
46+
}
4547

46-
public void addFavoriteToy(String toy) {
47-
favoriteToys.add(toy);
48-
}
48+
public void addFavoriteToy(String toy) {
49+
favoriteToys.add(toy);
50+
}
4951

50-
public List<String> getFavoriteToys() {
51-
List<String> toys = new ArrayList<>();
52-
for (String toy : favoriteToys) { // Loop
53-
toys.add(toy);
54-
}
55-
return toys;
52+
public List<String> getFavoriteToys() {
53+
List<String> toys = new ArrayList<>();
54+
for (String toy : favoriteToys) { // Loop
55+
toys.add(toy);
5656
}
57+
return toys;
58+
}
5759

58-
// Getters
59-
public int getAge() {
60-
return age;
61-
}
60+
// Getters
61+
public int getAge() {
62+
return age;
63+
}
6264

63-
public String getBreed() {
64-
return breed;
65-
}
65+
public String getBreed() {
66+
return breed;
67+
}
6668

67-
public String getGender() {
68-
return gender;
69-
}
69+
public String getGender() {
70+
return gender;
71+
}
7072

71-
public Colors getColor() {
72-
return color;
73-
}
73+
public Colors getColor() {
74+
return color;
75+
}
7476

75-
public boolean isFed() {
76-
return isFed;
77-
}
77+
public boolean isFed() {
78+
return isFed;
79+
}
7880
}

0 commit comments

Comments
 (0)