Skip to content

Commit f6c6fee

Browse files
committed
refactor(core): Improve animal management and data handling
Refactor AnimalManager and RescueManager to improve clarity and correct return types. Modify FeedingSchedule and FosterHome to use final fields for immutability.
1 parent 0612be4 commit f6c6fee

4 files changed

Lines changed: 21 additions & 24 deletions

File tree

src/main/java/com/academixxx/AnimalManager.java

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,10 @@ public void addAnimal() {
3636

3737
/**
3838
* Creates and registers an animal programmatically.
39-
* @param type animal type
39+
*
40+
* @param type animal type
4041
* @param condition health/condition description
41-
* @param status current status label
42+
* @param status current status label
4243
* @return the created Animal
4344
*/
4445
public Animal createAnimal(String type, String condition, String status) {
@@ -49,6 +50,7 @@ public Animal createAnimal(String type, String condition, String status) {
4950

5051
/**
5152
* Finds an animal by its ID.
53+
*
5254
* @param id the animal identifier
5355
* @return the Animal if found, otherwise null
5456
*/
@@ -61,19 +63,18 @@ public Animal findById(int id) {
6163

6264
/**
6365
* Updates the status of an existing animal.
64-
* @param id animal ID
66+
*
67+
* @param id animal ID
6568
* @param newStatus new status label
66-
* @return true if updated, false if animal not found
6769
*/
68-
public boolean updateStatus(int id, String newStatus) {
70+
public void updateStatus(int id, String newStatus) {
6971
for (int i = 0; i < animals.size(); i++) {
7072
Animal a = animals.get(i);
7173
if (a.id() == id) {
7274
animals.set(i, new Animal(a.id(), a.type(), a.condition(), newStatus));
73-
return true;
75+
return;
7476
}
7577
}
76-
return false;
7778
}
7879

7980
/**
@@ -96,11 +97,9 @@ public void listAnimals() {
9697
JOptionPane.showMessageDialog(null, sb.toString(), "Animals", JOptionPane.INFORMATION_MESSAGE);
9798
}
9899

99-
/**
100-
* Returns a copy of the current animals list for reporting/scheduling.
101-
*/
102100
/**
103101
* Returns a shallow copy of the animals list for read-only use.
102+
*
104103
* @return list copy of animals
105104
*/
106105
public List<Animal> getAnimals() {

src/main/java/com/academixxx/RescueManager.java

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,6 @@ public void registerRescue() {
8686
);
8787
}
8888

89-
/**
90-
* Displays the list of rescues recorded.
91-
*/
9289
/**
9390
* Displays all recorded rescue events.
9491
*/
@@ -100,11 +97,11 @@ public void listRescues() {
10097
StringBuilder sb = new StringBuilder("Rescue Events:\n");
10198
for (RescueEvent e : events) {
10299
sb.append("#").append(e.id())
103-
.append(" Animal #").append(e.animalId())
104-
.append(" - ").append(e.location())
105-
.append(" | Rescuer: ").append(e.rescuer())
106-
.append(" | When: ").append(e.dateTime())
107-
.append('\n');
100+
.append(" Animal #").append(e.animalId())
101+
.append(" - ").append(e.location())
102+
.append(" | Rescuer: ").append(e.rescuer())
103+
.append(" | When: ").append(e.dateTime())
104+
.append('\n');
108105
}
109106
JOptionPane.showMessageDialog(null, sb.toString());
110107
}

src/main/java/com/academixxx/models/FeedingSchedule.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
* This project keeps it minimal by design.
1010
*/
1111
public class FeedingSchedule {
12-
private int id;
13-
private int animalId;
12+
private final int id;
13+
private final int animalId;
1414
private final List<LocalTime> feedingTimes = new ArrayList<>();
1515
private String notes;
1616

@@ -49,6 +49,7 @@ public String getNotes() {
4949

5050
/**
5151
* Sets optional notes for this schedule.
52+
*
5253
* @param notes free-form notes
5354
*/
5455
public void setNotes(String notes) {

src/main/java/com/academixxx/models/FosterHome.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@
88
* Validation/persistence are out of scope for this in-memory app.
99
*/
1010
public class FosterHome {
11-
private int id;
12-
private String caretakerName;
13-
private String address;
14-
private int capacity;
11+
private final int id;
12+
private final String caretakerName;
13+
private final String address;
14+
private final int capacity;
1515
private final List<Integer> animalIds = new ArrayList<>();
1616

1717
public FosterHome(int id, String caretakerName, String address, int capacity) {

0 commit comments

Comments
 (0)