Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
c5fe5d1
Create a domain model draft
pudkipz Jan 10, 2025
b962f92
Create class diagram
pudkipz Jan 10, 2025
b9c81e9
Add class files, add test for successfully adding an item to basket
pudkipz Jan 10, 2025
4457831
Add basket method for adding an item
pudkipz Jan 10, 2025
a08bac1
Add test for successfully removing an item
pudkipz Jan 10, 2025
54a540d
Add basket method for removing item
pudkipz Jan 10, 2025
d5cfabd
Modify test to make sure basket is empty after removing the only item…
pudkipz Jan 10, 2025
1e71212
Fix basket should be empty after removing the only item that was added
pudkipz Jan 10, 2025
e11c555
Add test for increasing the basket size when adding a bagel
pudkipz Jan 10, 2025
5a469e3
Fix adding a bagel increases the basket size
pudkipz Jan 10, 2025
b7fb96b
Fix removing the last bagel gives empty basket
pudkipz Jan 10, 2025
f953218
Add test for making sure the correct bagel is removed from the basket
pudkipz Jan 10, 2025
2809076
Add member fields and accessors for Item
pudkipz Jan 10, 2025
51d5a8b
Add test to ensure not adding past basket capacity
pudkipz Jan 10, 2025
61e1f6d
Add check when adding to basket to ensure not adding past capacity
pudkipz Jan 10, 2025
91673fd
Add test for cost of empty basket
pudkipz Jan 10, 2025
5a7d685
Add basket method for calculating total cost
pudkipz Jan 10, 2025
672b888
Add test for calculating total cost of multiple items
pudkipz Jan 10, 2025
9346276
Implement calculating total cost of basket
pudkipz Jan 10, 2025
2f48146
Fix remove method not removing the correct item
pudkipz Jan 10, 2025
31feefa
Update class diagram and domain model to reflect code
pudkipz Jan 10, 2025
ff0fabb
Add test for showing stock (excl. filling)
pudkipz Jan 13, 2025
599befb
Implement showItems
pudkipz Jan 13, 2025
13220ef
Add test and implementation for showFillings
pudkipz Jan 13, 2025
54d8f2b
Add test and implementation for listing bagels and drinks
pudkipz Jan 13, 2025
c18a1c0
Implement menu for placing an order
pudkipz Jan 13, 2025
fca402a
Implement menu for removing from basket
pudkipz Jan 13, 2025
51443cc
Update domain model to fit with implementation
pudkipz Jan 13, 2025
2f6547e
Finish core
pudkipz Jan 13, 2025
96fdb43
Add domain model for extension
pudkipz Jan 13, 2025
0ee6ece
Refactor Bagel and Coffee to distinct classes
pudkipz Jan 13, 2025
a533928
Add option to order discount bagel with coffee
pudkipz Jan 13, 2025
b2b3949
Update getting size of coffee to account for discount bagel
pudkipz Jan 13, 2025
4895a56
Copy core test to extension test (ShopHandler)
pudkipz Jan 13, 2025
08ea0a6
Add menu-less methods for ordering bagels and coffee
pudkipz Jan 14, 2025
4ddeb94
Add test for calculating 6-pack bagel discount
pudkipz Jan 14, 2025
3330521
Add test for 12-pack bagels
pudkipz Jan 14, 2025
8308fa0
Add test for coffe & bagel discount
pudkipz Jan 14, 2025
dbca879
Add test for some combo of coffees and bagels
pudkipz Jan 14, 2025
9022308
Add test for non-empty receipt
pudkipz Jan 14, 2025
70236cf
Add test and implementation for some order
pudkipz Jan 14, 2025
a5f4796
Update domain model and class diagram to reflect implementation
pudkipz Jan 14, 2025
990380c
Add tests for Bagel and Coffee
pudkipz 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 class_diagram.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added class_diagram_extension.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
103 changes: 103 additions & 0 deletions domain-model-extension.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
# Bob's Bagels -- Domain model

## Class: Item

### Member variables

- sku: String
- price: double
- name: String
- variant: String
- size: int (e.g., fillings maybe don't take up capacity)

### Methods

Accessors for all fields.

## Class: Basket

### Member variables

- capacity: static int
- items: List<Item>

### Methods

| Method | Scenario | Result |
|----------------------------------------------------|-----------------------------------------------------|-------------------------------------------------------------|
| addItem(name: String, variant: String): boolean | Basket is full | Return false. Print error message, don't add item to basket |
| addItem(item: Item): boolean | Basket is not full | Return true. Add item to basket. |
| | One or more fields are invalid (shop doesn't stock) | Return false. Print error message. |
| removeItem(name: String, variant: String): boolean | Item is not found in basket | Return false. Print error message. |
| | Item is found in basket | Return true. Remove item from basket. |
| setCapacity(newCapacity: int): static void | newCapacity is valid (> 0) | Update the basket capacity. |
| | newCapacity is not valid (<= 0) | Don't change the basket capacity. |
| getCapacity(): int | | |
| getTotalCost(): double | | Calculate and return the cost of items in basket. |

## Class: ShopHandler

This is the public interface that a customer or manager interacts with the Bob's Bagels system through.

### Member variables

- basket: Basket
- ~~stockedItems: `List<Map<attribute (String), value (String)>>()`~~
- - stockedItems: `List<Item>` (copy existing items when adding new items)

### Methods

| Method | Scenario | Result |
|--------------------------------------------------------------------------|----------|-------------------------------------------------------------------|
| placeOrder(): void | | Guide the customer through selecting items to order (interactive) |
| showItems(): String | | Return String of bagels and coffee w/ prices |
| showFillings(): String | | Return String of fillings w/ prices |
| orderBagel(): boolean | | Add a bagel with optional filling to basket if it's not full. |
| orderCoffee(): boolean | | Add coffee with optional bagel for a discount if it's not full. |
| setBasketCapacity(): void | | Update the basket capacity for all baskets. |
| calculateDiscounts(): double | | Apply the discounts and return savings. |
| showReceiptWithDiscounts(): String | | Return String with receipt, including discounts. |
| show/Fillings/Bagels/Coffees(): String | | Return String showing possible orders and prices |
| Some helper functions that I don't think are important enough to mention | | |

## Class: Coffee

Inherits from: Item.

### Member variables:
- discountBagel: Bagel

### Methods

| Method | Scenario | Result |
|---------------------------|------------------------------------|-----------------------------------------------|
| getSize(): int | | Returns size, includes optional discountBagel | | |
| getPrice(): double | | includes optional discountBagel |
| getDiscountBagel(): Bagel | There is a bagel/there is no bagel | Returns the bagel/returns null |

## Class: Bagel

Inherits from: Item

### Member variables:

- filling: Item

### Methods

| Method | Scenario | Result |
|--------------------|--------------------------------------|----------------------------------|
| getSize(): int | | Returns size |
| getPrice(): double | | includes optional filling |
| getFilling(): Item | There is filling/there is no filling | Returns the filling/returns null |

# Class: Main

Run interactive interface to interactively place an order. (Not up to date with extensions.)

# User stories (extension)

- As a customer, I want to be able to have a bagel with my coffee for a discount.
- As a customer, I want multi-priced discounts to apply at checkout.
- As a customer, I want to get a receipt when paying.
- As a concerned customer, I want to know how much I saved using discounts.
62 changes: 62 additions & 0 deletions domain-model.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# Bob's Bagels -- Domain model

## Class: Item

### Member variables

- sku: String
- price: double
- name: String
- variant: String
- size: int (e.g., fillings maybe don't take up capacity)

### Methods

Accessors for all fields.

## Class: Basket

### Member variables

- capacity: static int
- items: List<Item>

### Methods

| Method | Scenario | Result |
|----------------------------------------------------|-----------------------------------------------------|-------------------------------------------------------------|
| addItem(name: String, variant: String): boolean | Basket is full | Return false. Print error message, don't add item to basket |
| addItem(item: Item): boolean | Basket is not full | Return true. Add item to basket. |
| | One or more fields are invalid (shop doesn't stock) | Return false. Print error message. |
| removeItem(name: String, variant: String): boolean | Item is not found in basket | Return false. Print error message. |
| | Item is found in basket | Return true. Remove item from basket. |
| setCapacity(newCapacity: int): static void | newCapacity is valid (> 0) | Update the basket capacity. |
| | newCapacity is not valid (<= 0) | Don't change the basket capacity. |
| getCapacity(): int | | |
| getTotalCost(): double | | Calculate and return the cost of items in basket. |

## Class: ShopHandler

This is the public interface that a customer or manager interacts with the Bob's Bagels system through.

### Member variables

- basket: Basket
- ~~stockedItems: `List<Map<attribute (String), value (String)>>()`~~
- - stockedItems: `List<Item>` (copy existing items when adding new items)

### Methods

| Method | Scenario | Result |
|-------------------------------|----------|-----------------------------------------------------------------------|
| placeOrder(): void (boolean?) | | Guide the customer through selecting items to order. |
| showItems(): String | | Return String of bagels and coffee w/ prices |
| showFillings(): String | | Return String of fillings w/ prices |
| orderBagel(): void | | Let customer choose a bagel. Then, let customer add optional filling. |
| orderCoffee(): void | | Let customer choose a variant. |
| setBasketCapacity(): void | | Update the basket capacity for all baskets. |
| Some private helper functions | | |

# Class: Main

Run interactive interface.
73 changes: 73 additions & 0 deletions src/main/java/com/booleanuk/core/Basket.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
package com.booleanuk.core;

import java.util.ArrayList;
import java.util.List;

public class Basket {
private static int capacity = 5;
private List<Item> items = new ArrayList<>();

public boolean addItem(String sku, double price, String name, String variant, int size) {
Item item = new Item(sku, price, name, variant, size);
return addItem(item);
}

public boolean addItem(Item item) {
if (canFitItem(item)) {
items.add(item);
return true;
}
return false;
}

public boolean canFitItem(Item item) {
if (items.size() + item.getSize() > capacity) {
System.out.println("You cannot fit more items in your basket.");
return false;
}
return true;
}

public boolean addItem(String sku, double price, String name, String variant) {
// Shorthand, assuming size=1
return addItem(sku, price, name, variant, 1);
}


public boolean removeItem(String sku) {
int indexToRemove = 0;
boolean foundItem = false;
for (int i=0; i<items.size(); i++) {
if (sku.equals(items.get(i).getSku())) {
indexToRemove = i;
foundItem = true;
break;
}
}
if (foundItem) {
items.remove(indexToRemove);
return true;
}
return false;
}

public double getTotalCost() {
double totalCost = 0;
for (Item item : items) {
totalCost += item.getPrice();
}
return totalCost;
}

public List<Item> getItems() {
return items;
}

public static void setCapacity(int newCapacity) {
capacity = newCapacity;
}

public static int getCapacity() {
return capacity;
}
}
41 changes: 41 additions & 0 deletions src/main/java/com/booleanuk/core/Item.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package com.booleanuk.core;

public class Item {
private String sku;
private double price;
private String name;
private String variant;
private int size;

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

public Item(String sku, double price, String name, String variant) {
this(sku, price, name, variant, 1);
}

public String getSku() {
return sku;
}

public double getPrice() {
return price;
}

public String getName() {
return name;
}

public String getVariant() {
return variant;
}

public int getSize() {
return size;
}
}
8 changes: 8 additions & 0 deletions src/main/java/com/booleanuk/core/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.booleanuk.core;

public class Main {
public static void main(String[] args) {
ShopHandler sh = new ShopHandler();
sh.placeOrder();
}
}
Loading
Loading