Skip to content

Commit 9c75850

Browse files
committed
Fix: formatting issue in Cat.java
1 parent 06eb376 commit 9c75850

File tree

1 file changed

+68
-45
lines changed
  • lesson_16/objects/objects_app/src/main/java/com/codedifferently/lesson16/cutecat

1 file changed

+68
-45
lines changed

lesson_16/objects/objects_app/src/main/java/com/codedifferently/lesson16/cutecat/Cat.java

Lines changed: 68 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -3,64 +3,87 @@
33
import java.util.ArrayList;
44
import java.util.Arrays;
55

6-
//Exception
6+
// Exception
77
class InvalidCatNameException extends Exception {
8-
public InvalidCatNameException (String message) {
9-
super(message);
10-
}
8+
public InvalidCatNameException(String message) {
9+
super(message);
10+
}
1111
}
1212

1313
// Enum for Cat Breed
1414
enum Breed {
15-
SIAMESE, PERSIAN, MAINCOON, SPHYNX, BENGAL, UNKNOWN
15+
SIAMESE,
16+
PERSIAN,
17+
MAINCOON,
18+
SPHYNX,
19+
BENGAL,
20+
UNKNOWN
1621
}
1722

1823
public class Cat {
19-
// Member variables
20-
private String name;
21-
private int age;
22-
private double weight;
23-
private boolean isIndoor;
24-
private Breed breed;
25-
private ArrayList<String> favoriteFoods;
24+
// Member variables
25+
private String name;
26+
private int age;
27+
private double weight;
28+
private boolean isIndoor;
29+
private Breed breed;
30+
private ArrayList<String> favoriteFoods;
2631

27-
// Constructor
28-
public Cat(String name, int age, double weight, Breed breed, boolean isIndoor) throws InvalidCatNameException {
29-
if (name == null || name.trim().isEmpty()) {
30-
throw new InvalidCatNameException("Cat name cannot be empty.");
31-
}
32-
this.name = name;
33-
this.age = age;
34-
this.weight = weight;
35-
this.isIndoor = isIndoor;
36-
this.breed = breed;
37-
this.favoriteFoods = new ArrayList<>(Arrays.asList("Fancy Feast", "Purina Naturals")); //Default for Ninja
32+
// Constructor
33+
public Cat(String name, int age, double weight, Breed breed, boolean isIndoor)
34+
throws InvalidCatNameException {
35+
if (name == null || name.trim().isEmpty()) {
36+
throw new InvalidCatNameException("Cat name cannot be empty.");
3837
}
38+
this.name = name;
39+
this.age = age;
40+
this.weight = weight;
41+
this.isIndoor = isIndoor;
42+
this.breed = breed;
43+
this.favoriteFoods =
44+
new ArrayList<>(Arrays.asList("Fancy Feast", "Purina Naturals")); // Default for Ninja
45+
}
3946

40-
// Function 1: Add Favorite Food (uses collection)
41-
public void addfavoriteFood(String food) {
42-
favoriteFoods.add(food);
43-
}
47+
// Function 1: Add Favorite Food (uses collection)
48+
public void addfavoriteFood(String food) {
49+
favoriteFoods.add(food);
50+
}
4451

45-
//Function 2: Print Favorite Foods (uses loop)
46-
public void printfavoriteFoods() {
47-
System.out.println(name + "'s favorite foods:");
48-
for (String v : favoriteFoods) {
49-
System.out.println("- " + v);
50-
}
52+
// Function 2: Print Favorite Foods (uses loop)
53+
public void printfavoriteFoods() {
54+
System.out.println(name + "'s favorite foods:");
55+
for (String v : favoriteFoods) {
56+
System.out.println("- " + v);
5157
}
58+
}
5259

53-
// Function 3: Is the cat a senior? (uses conditional)
54-
public boolean isSenior() {
55-
return age >= 10;
56-
}
60+
// Function 3: Is the cat a senior? (uses conditional)
61+
public boolean isSenior() {
62+
return age >= 10;
63+
}
64+
65+
// Getters for testing
66+
public String getName() {
67+
return name;
68+
}
69+
70+
public int getAge() {
71+
return age;
72+
}
73+
74+
public double getWeight() {
75+
return weight;
76+
}
77+
78+
public boolean getIsIndoor() {
79+
return isIndoor;
80+
}
81+
82+
public Breed getBreed() {
83+
return breed;
84+
}
5785

58-
// Getters for testing
59-
public String getName() { return name; }
60-
public int getAge() { return age; }
61-
public double getWeight() { return weight; }
62-
public boolean getIsIndoor() { return isIndoor; }
63-
public Breed getBreed() { return breed; }
64-
public ArrayList<String> getfavoriteFoods() {return favoriteFoods; }
65-
}
86+
public ArrayList<String> getfavoriteFoods() {
87+
return favoriteFoods;
88+
}
6689
}

0 commit comments

Comments
 (0)