Skip to content
Closed
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
package com.codedifferently.lesson16.wardobecollection;

import java.util.ArrayList;

public class ClothingItem {
// Member variables
private String name;
private String type;
private String color;
private String size;
private double value;
private PersonalCloset.Season season;

// Constructor
public ClothingItem (String name, String type, String color, String size, double value, PersonalCloset.Season season) {
this.name = name;
this.type = type;
this.color = color;
this.size = size;
this.value = value;
this.season = season;
}

// Getters and Setters
public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public String getType() {
return type;
}

public void setType(String type) {
this.type = type;
}

public String getColor() {
return color;
}

public void setColor(String color) {
this.color = color;
}

public String getSize() {
return size;
}

public void setSize(String size) {
this.size = size;
}

public double getValue() {
return value;
}

public void setValue(double value) {
this.value = value;
}

public PersonalCloset.Season getSeason() {
return season;
}

public void setSeason(PersonalCloset.Season season) {
this.season = season;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,170 @@
package com.codedifferently.lesson16.wardobecollection;

import java.util.List;
import java.util.Map;
import java.util.ArrayList;
import java.util.HashMap;

// Personal closet class to represent persons wardrobe collection
public class PersonalCloset {
// Enum for seaons
public enum Season {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Formatting looks wrong, please fix.

FALL,
WINTER,
SPRING,
SUMMER,
ALL_SEASON
}

// Member variables
private String ownerName;
private int maxCapacity;
private double totalValue;
private boolean isOrganized;
private ArrayList<ClothingItem> items;
private HashMap<Season, Integer> seasonalItems;

// Constructor for personal closet
public PersonalCloset (String ownerName, int maxCapacity) {
this.ownerName = ownerName;
this.maxCapacity = maxCapacity;
this.totalValue = 0.0;
this.isOrganized = false;
this.items = new ArrayList<>();
this.seasonalItems = new HashMap<>();
}

// Core methods

// Method adds item to closet
public boolean addItem(ClothingItem item) {
// If closet is full, cannot add item
if (items.size() >= maxCapacity) {
return false;
}

// Adding item to closet and increasing total value of closet
items.add(item);
totalValue += item.getValue();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!


// Checks what season item is meant for and keeps track of number of items in that season
Season season = item.getSeason();
seasonalItems.put(season, seasonalItems.getOrDefault(season, 0) + 1);

// Returns true if item is added
return true;
}

// Method removes item from closet
public void removeItem(ClothingItem item) throws ItemNotFoundException {
// If item is not in closet, throws an error
if (!items.contains(item)) {
throw new ItemNotFoundException("Item is not in closet.");
}

// Remove item from closet and decreases toal value of closet
items.remove(item);
totalValue -= item.getValue();

// Grab clothing item based on season and decrease count
Season season = item.getSeason();
seasonalItems.put(season, seasonalItems.get(season) - 1);
}


// Method creates outfit by selecting items based on the season
public List<ClothingItem> createOutfit(Season season) {
// Creating empty list that stores clothing items
List<ClothingItem> outfit = new ArrayList<>();

// Iterating through all items in the closet and grabbing item at index
for (int i = 0; i < items.size(); i++) {
ClothingItem item = items.get(i);

// Check if clothing item matches particular season or is good for all seasons
if (item.getSeason() == season || item.getSeason() == Season.ALL_SEASON) {
//add item to list
outfit.add(item);
}
}
// Returns final list of clothing items in an outfit
return outfit;
}

// Method organizes closet by type of item and color
public void organizeCloset() {
// Create a map where key is type of clothing and value is list of clothing items of that type
Map<String, List<ClothingItem>> organized = new HashMap<>();


// Iterate through every item in closet
for (int i = 0; i < items.size(); i++) {
ClothingItem item = items.get(i);
String type = item.getType();

// Check if that type of clothing item is in the list
List<ClothingItem> itemList = organized.get(type);
if (itemList == null) {
// If it doesn’t exist, make a new list and put it in the map
itemList = new ArrayList<>();
organized.put(type, itemList);
}

// Adding items to list by type
itemList.add(item);
}

// closet is organized
isOrganized = true;
}

// method returns a map shwoing how many items are in closet based on season
public Map<Season, Double> getSeasonalItem() {
return new HashMap<>(seasonalItems);
}

// getters and setters
public String getOwnerName() {
return ownerName;
}

public void setOwnerName(String ownerName) {
this.ownerName = ownerName;
}

public int getMaxCapacity() {
return maxCapacity;
}

public void setMaxCapacity(int maxCapacity) {
this.maxCapacity = maxCapacity;
}

public double getTotalValue() {
return totalValue;
}

public void setTotalValue(double totalValue) {
this.totalValue = totalValue;
}

public boolean isOrganized () {
return isOrganized;
}

public void setOrganized(boolean isOrganized) {
this.isOrganized = isOrganized;
}

public List<ClothingItem> getItems() {
return new ArrayList<>(items);
}

// Custom exception if item is not found in closet
public static class ItemNotFoundException extends Exception{
public ItemNotFoundException(String message) {
super(message);
}
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package com.codedifferently.lesson16;

import org.junit.jupiter.api.Test;

public class PersonalClosetTest {
PersonalCloset closet;
private Mop<Season, Integer> sesonalItems;

@BeforeEach
void setUp() {
PersonalCloset = new PersonalCloset ("Karen", 4);
ClothingItem sweater = new ClothingItem("")
}

@Test
public void testAddItemToEmptyCloset {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see you're still working on this. Carry on.

// Arrange

// Act

// Assert
}

@Test
public void testaddItemToFullCloset {
// Arrange

// Act

// Assert

}

@Test
public void testremoveExistingItem {
// Arrange

// Act

// Assert
}

@Test
public void testcreateOutfit {
// Arrange

// Act

// Assert
}

@Test
public void testorganizeCloset {
// Arrange

// Act

// Assert
}

}
Loading