-
Notifications
You must be signed in to change notification settings - Fork 24
feat: adds initial implementation of bank account, savings account, and business checking account class #539
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
karensprojects22
wants to merge
12
commits into
code-differently:main
from
karensprojects22:lesson_17
Closed
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
a88b77b
feat: adds PersonalCloset and PersonalClosetTest file
1903ec2
feat: creates basic PersonalCloset class structure with enums, variab…
4c78dbb
feat: implments add item method with logic for closet item, closet va…
eb78119
feat: implements remove item method with custom exception for items n…
b2d760c
feat: implements createOutfit method to pick clothes based on season
c8b3b9d
fix: corrects items.size() and seasonal counts in Personal Closet class
de685c4
feat: creates Clothing Item class file
40a0b07
chore: updates getter and setter methods for Personal Closet class
1ce5e47
feat: adds basic Clothing Item class structure
8dfe557
feat: adds basic class structure of PersonalClosetTest class
fbf1325
Merge branch 'code-differently:main' into lesson_17
karensprojects22 5dde5de
feat: implements initial bank account, business checking account, and…
karensprojects22 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
72 changes: 72 additions & 0 deletions
72
...jects_app/src/main/java/com/codedifferently/lesson16/wardrobecollection/ClothingItem.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
170 changes: 170 additions & 0 deletions
170
...cts_app/src/main/java/com/codedifferently/lesson16/wardrobecollection/PersonalCloset.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 { | ||
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(); | ||
|
||
// 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); | ||
} | ||
} | ||
} | ||
|
61 changes: 61 additions & 0 deletions
61
...src/test/java/com/codedifferently/lesson16/wardrobecollectiontest/PersonalClosetTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 { | ||
// 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 | ||
} | ||
|
||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Must not include L16 work.