Skip to content

Commit 4c78dbb

Browse files
Karen AlabiKaren Alabi
authored andcommitted
feat: implments add item method with logic for closet item, closet value, and seaon count
1 parent 1903ec2 commit 4c78dbb

File tree

1 file changed

+23
-7
lines changed
  • lesson_16/objects/objects_app/src/main/java/com/codedifferently/lesson16/wardrobecollection

1 file changed

+23
-7
lines changed

lesson_16/objects/objects_app/src/main/java/com/codedifferently/lesson16/wardrobecollection/PersonalCloset.java

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public enum Season {
2121
private int maxCapacity;
2222
private double totalValue;
2323
private boolean isOrganized;
24-
private ArrayList<Clothing Item> items;
24+
private ArrayList<ClothingItem> items;
2525
private HashMap<Season, Integer> seasonalItems;
2626

2727
// Constructor for personal closet
@@ -31,23 +31,39 @@ public PersonalCloset (String ownerName, int maxCapacity) {
3131
this.totalValue = 0.0;
3232
this.isOrganized = false;
3333
this.items = new ArrayList<>();
34-
this.seaonalItems = new HashMap<>();
34+
this.seasonalItems = new HashMap<>();
3535
}
3636

3737
//core methods
3838

3939
// adds item to closet
4040
public boolean addItem(ClothingItem item) {
41-
return false;
41+
// if closet is full, cannot add item
42+
if (items.size(0) >= maxCapacity) {
43+
return false;
44+
}
45+
46+
//adding item to closet and increasing closet total value of closet
47+
items.add(item);
48+
totalValue += item.getValue();
49+
50+
// checks what season item is meant for and keeps track of number of items in that season
51+
Season seaason = item.getSeason();
52+
seasonalItems.put(season, seasonalItems.getOrDefault(season, 0) + 1);
53+
54+
// returns true if item is added
55+
return true;
4256
}
4357

4458
// removes item from closet
4559
public void removeItem(ClothingItem item) {
46-
// throws exception if item is not found in closet
47-
public static class ItemNotFoundException extends Exception{
60+
return;
61+
}
4862

63+
// throws exception if item is not found in closet
64+
public static class ItemNotFoundException extends Exception{
4965
}
50-
}
66+
5167

5268
// creates outfit by selecting items based on the season
5369
public List<Clothing Item> createOutfit(Season season) {
@@ -68,7 +84,7 @@ public String getOwnerName() {
6884
return ownerName;
6985
}
7086

71-
public void setOwnerName() {
87+
public void setOwnerName(String ownerName) {
7288
this.ownerName = ownerName;
7389
}
7490

0 commit comments

Comments
 (0)