Skip to content
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

Frida Anselin #141

Open
wants to merge 24 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
b1571a9
Initial domain model
Jan 13, 2025
fe5d77f
Update domain model
Jan 14, 2025
32c5190
Add basketTest for addItem function - red
Jan 14, 2025
2c03e52
Add itemTest for item constructor - red
Jan 14, 2025
289ca92
Add constructor and getters for item to pass test - green
Jan 14, 2025
61a7c09
Add testBagelCreation - red
Jan 14, 2025
326157f
Add bagel constructor to pass testBagelCreation - green
Jan 14, 2025
936a3b8
Add testCoffeeCreation - red
Jan 14, 2025
9311c9d
Add coffee constructor to make testCoffeeCreation pass - green
Jan 14, 2025
65075a9
Add testFillingCreation - red
Jan 14, 2025
e07d8f9
Add filling constructor to pass testFillingCreation - green
Jan 14, 2025
cced6d7
Correct testAddItem for basket class + basket code to pass test - green
Jan 14, 2025
0c4a129
Add testGetTotalprice - red
Jan 14, 2025
dff0b1a
Add code to pass testGetTotalprice - green
Jan 14, 2025
d58c9e8
Add testRemoveItem - red
Jan 14, 2025
888121b
Add code to pass testRemoveItem - green
Jan 14, 2025
98ccb43
Add testSetCapacity - red
Jan 14, 2025
0a5bf28
Add setter for basket capacity and refactor addItem to pass testSetCa…
Jan 14, 2025
000a4c8
Refactor to return correct phrase when item added successfully or the…
Jan 14, 2025
da8ba38
Refactor to return correct phrase when item removed successfully or w…
Jan 14, 2025
9eaf6a7
Add testHasItem for inventory - red
Jan 14, 2025
84502ed
Refactor inventory class, add testPrintInventory - red
Jan 14, 2025
aa0a5f6
Update domain model
Jan 14, 2025
84e5460
Add class diagram
Jan 14, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added Screenshot 2025-01-15 002216.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
88 changes: 88 additions & 0 deletions domain-model.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
# Bagels domain model


## OrderManager class ?
| Methods | Member variables | Scenario | Result |
|------------------------------------|------------------|-------------------------------|---------------------------|
| | String name? | | |
| | Basket basket | | |
| addItemToBasket(Item item) | | basket is not full | string itemAddedMessage |
| | | basket is full | string fullBasketMessage |
| | | item is in menu/inventory | void |
| | | item is not in menu/inventory | string notInStockMessage |
| removeItemFromBasket(Item item) | | item is in basket | string itemRemovedMessage |
| | | item is not in basket | string errorMessage |
| changeBasketCapacity(int capacity) | | capacity was updated | true / string? |
| | | capacity was not updated | false / string? |
| | | | double totalPrice |
| | | | |
| | | | String itemsInInventory |
| | | | |
| | | | |

## Basket class

| Methods | Member variables | Scenario | Results |
|------------------------------------|----------------------------|------------------|---------|
| | ArrayList<Item item> items | | |
| | int capacity | | |
| addItem(Item item) | | item added | true |
| | | item not added | false |
| getTotalCost(ArrayList<Item item>) | | gets total cost | int |
| deleteItem(Item item) | | item deleted | true |
| | | item not deleted | false |
| setCapacity(int) | | | |
| | | | |


## Item class

| Methods | member variables | scenario | result |
|------------|------------------|--------------|--------|
| getSKU | String SKU | gets SKU | string |
| getPrice | double price | gets price | double |
| getName | String name | gets name | string |
| getVariant | String variant | gets variant | string |

## Inventory class

| Methods | member variables | scenario | result |
|-----------------------|----------------------------------|-------------------------------|------------------------|
| | Map<String SKU, Item item> items | | |
| getItem(String SKU) | | item exists | Item object or null |
| | | item does not exist | null |
| printItem(String SKU) | | inventory has items | string of items |
| | | inventory does not have items | string inventory empty |


## Bagel class inherits from item


| Methods | member variables | scenario | result |
|--------------------------------------------------------------|---------------------|----------|------------------|
| | String SKU | | string |
| | double price | | double |
| | String name="Bagel" | | string |
| | String variant | | string |
| Constructor(Bagel(String SKU, String variant, double price)) | | | new bagel object |


## Filling class inherits from item

| Methods | member variables | scenario | result |
|----------------------------------------------------------------|-----------------------|----------|--------------------|
| | String SKU | | string |
| | double price | | double |
| | String name="Filling" | | string |
| | String variant | | string |
| Constructor(Filling(String SKU, String variant, double price)) | | | new filling object |

## Coffee class inherits from item

| Methods | member variables | scenario | result |
|---------------------------------------------------------------|----------------------|----------|-------------------|
| | String SKU | | string |
| | double price | | double |
| | String name="Coffee" | | string |
| | String variant | | string |
| Constructor(Coffee(String SKU, String variant, double price)) | | | new coffee object |
8 changes: 8 additions & 0 deletions src/main/java/com/booleanuk/core/Bagel.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.booleanuk.core;

public class Bagel extends Item{

public Bagel(String SKU, double price, String name, String variant) {
super(SKU, price, name, variant);
}
}
45 changes: 45 additions & 0 deletions src/main/java/com/booleanuk/core/Basket.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package com.booleanuk.core;

import java.util.ArrayList;

public class Basket {
private ArrayList<Item> basketItems;
private int capacity;


public Basket(ArrayList<Item> items) {
this.basketItems = items;
}

public String addItem(Item item) {
if (!(basketItems.size() >= capacity)) {
basketItems.add(item);
return "Item added successfully!";
}
return "Basket is full!";
}

public String removeItem(Item item) {
if (basketItems.contains(item)) {
basketItems.remove(item);
return "Item removed!";
}
return "Could not remove - item was never in basket";
}

public double getTotalPrice(ArrayList<Item> items) {
double total = 0.0;
for (Item item : items) {
total += item.getPrice();
}
return total;
}

public int getCapacity() {
return capacity;
}

public void setCapacity(int capacity) {
this.capacity = capacity;
}
}
7 changes: 7 additions & 0 deletions src/main/java/com/booleanuk/core/Coffee.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.booleanuk.core;

public class Coffee extends Item{
public Coffee(String SKU, double price, String name, String variant) {
super(SKU, price, name, variant);
}
}
7 changes: 7 additions & 0 deletions src/main/java/com/booleanuk/core/Filling.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.booleanuk.core;

public class Filling extends Item{
public Filling(String SKU, double price, String name, String variant) {
super(SKU, price, name, variant);
}
}
33 changes: 33 additions & 0 deletions src/main/java/com/booleanuk/core/Inventory.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.booleanuk.core;

import java.util.ArrayList;
import java.util.HashMap;

public class Inventory {
private HashMap<String, Item> inventoryItems;

public Inventory(HashMap<String, Item> inventoryItems) {
this.inventoryItems = new HashMap<>();
this.inventoryItems.put("BGLO", new Item("BGLO", 0.49, "Bagel", "Onion"));
this.inventoryItems.put("BGLP", new Item("BGLP", 0.39, "Bagel", "Plain"));
this.inventoryItems.put("BGLE", new Item("BGLE", 0.49, "Bagel", "Everything"));
this.inventoryItems.put("BGLS", new Item("BGLS", 0.49, "Bagel", "Sesame"));
this.inventoryItems.put("COFB", new Item("COFB", 0.99, "Coffee", "Black"));
this.inventoryItems.put("COFW", new Item("COFW", 1.19, "Coffee", "White"));
this.inventoryItems.put("COFC", new Item("COFC", 1.29, "Coffee", "Capuccino"));
this.inventoryItems.put("COFL", new Item("COFL", 1.29, "Coffee", "Latte"));
this.inventoryItems.put("FILB", new Item("FILB", 0.12, "Filling", "Bacon"));
this.inventoryItems.put("FILE", new Item("FILE", 0.12, "Filling", "Egg"));
this.inventoryItems.put("FILC", new Item("FILC", 0.12, "Filling", "Cheese"));
this.inventoryItems.put("FILX", new Item("FILX", 0.12, "Filling", "Cream Cheese"));
this.inventoryItems.put("FILS", new Item("FILS", 0.12, "Filling", "Smoked Salmon"));
this.inventoryItems.put("FILH", new Item("FILH", 0.12, "Filling", "Ham"));
}

public boolean hasItem(String item) {
System.out.println(item);
System.out.println(inventoryItems);
return inventoryItems.containsKey(item);
}
}

32 changes: 32 additions & 0 deletions src/main/java/com/booleanuk/core/Item.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.booleanuk.core;

public class Item {

private String SKU;
private double price;
private String name;
private String variant;

public Item(String SKU, double price, String name, String variant) {
this.SKU = SKU;
this.price = price;
this.name = name;
this.variant = variant;
}

public String getSKU() {
return SKU;
}

public double getPrice() {
return price;
}

public String getName() {
return name;
}

public String getVariant() {
return variant;
}
}
21 changes: 21 additions & 0 deletions src/test/java/com/booleanuk/core/BagelTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.booleanuk.core;

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

public class BagelTest {

@Test
public void testBagelCreation(){
String SKU = "BGLS";
double price = 0.49;
String name = "Bagel";
String variant = "Sesame";
Bagel bagel = new Bagel(SKU, price, name, variant);

Assertions.assertEquals(SKU, bagel.getSKU());
Assertions.assertEquals(price, bagel.getPrice());
Assertions.assertEquals(name, bagel.getName());
Assertions.assertEquals(variant, bagel.getVariant());
}
}
71 changes: 71 additions & 0 deletions src/test/java/com/booleanuk/core/BasketTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
package com.booleanuk.core;

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import java.util.ArrayList;

public class BasketTest {
private Basket basket;
private Item bagel;
private Item coffee;
private Item filling;

@BeforeEach
public void setUp() {
ArrayList<Item> basketItems = new ArrayList<>() {{
add(bagel);
add(coffee);
add(filling);
}};
basket = new Basket(basketItems);
basket.setCapacity(6);
bagel = new Item("BGLS", 0.49, "Bagel", "Sesame");
coffee = new Item("COFB", 0.99, "Coffee" , "Black");
filling = new Item("FILX", 0.12, "Filling", "Cream Cheese");
}

@Test
public void testAddItem() {
Assertions.assertEquals("Item added successfully!",basket.addItem(coffee));
Assertions.assertEquals("Item added successfully!",basket.addItem(bagel));
Assertions.assertEquals("Item added successfully!",basket.addItem(filling));
}

@Test
public void testAddItemToFullBasket() {
basket.setCapacity(2);
basket.addItem(bagel);
basket.addItem(filling);

}

@Test
public void testRemoveItem() {
basket.addItem(coffee);
basket.addItem(bagel);
Assertions.assertEquals("Item removed!",basket.removeItem(coffee));
Assertions.assertEquals("Item removed!",basket.removeItem(bagel));
Assertions.assertEquals("Could not remove - item was never in basket", basket.removeItem(filling));
}

@Test
public void testGetTotalPrice() {
ArrayList<Item> basketItems = new ArrayList<>() {{
add(bagel);
add(coffee);
add(filling);
}};
Assertions.assertEquals(1.60, basket.getTotalPrice(basketItems));
}

@Test
public void testSetCapacity(){
basket.setCapacity(2);
basket.addItem(bagel);
basket.addItem(coffee);
Assertions.assertEquals("Basket is full!", basket.addItem(filling));
}

}
20 changes: 20 additions & 0 deletions src/test/java/com/booleanuk/core/CoffeeTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.booleanuk.core;

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

public class CoffeeTest {
@Test
public void testCoffeeCreation(){
String SKU = "COFB";
double price = 0.99;
String name = "Coffee";
String variant = "Black";
Coffee coffee = new Coffee(SKU, price, name, variant);

Assertions.assertEquals(SKU, coffee.getSKU());
Assertions.assertEquals(price, coffee.getPrice());
Assertions.assertEquals(name, coffee.getName());
Assertions.assertEquals(variant, coffee.getVariant());
}
}
20 changes: 20 additions & 0 deletions src/test/java/com/booleanuk/core/FillingTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.booleanuk.core;

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

public class FillingTest {
@Test
public void testFillingCreation(){
String SKU = "BGLS";
double price = 0.49;
String name = "Bagel";
String variant = "Sesame";
Filling filling = new Filling(SKU, price, name, variant);

Assertions.assertEquals(SKU, filling.getSKU());
Assertions.assertEquals(price, filling.getPrice());
Assertions.assertEquals(name, filling.getName());
Assertions.assertEquals(variant, filling.getVariant());
}
}
30 changes: 30 additions & 0 deletions src/test/java/com/booleanuk/core/InventoryTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.booleanuk.core;

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import java.util.HashMap;

public class InventoryTest {
private Inventory inventory;
private Item itemB;
private Item itemC;
private Item itemF;

@BeforeEach
public void setUp() {
HashMap<String, Item> inventoryItems = new HashMap<>() {{
put("BGLS", itemB);
put("COFB", itemC);
}};
inventory = new Inventory(inventoryItems);
itemB = new Item("BGLS", 0.49, "Bagel", "Sesame");
itemC = new Item("COFB", 0.99, "Coffee" , "Black");
}

@Test
public void testPrintInventory() {
Assertions.assertEquals("BGLS, 0.49, Bagel, Sesame \n COFB, 0.99, Coffee, Black" ,inventory.printInventory());
}
}
Loading
Loading