Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
41 changes: 41 additions & 0 deletions domain-model.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@


| Class | Variables | Methods | Scenario | Output |
|----------------------|------------------------------------------------------|-----------------------------------|-------------------------------------------------------------------------------------------------------------------|-----------|
| Basket | ArrayList<Item> items | boolean addItem(SKU SKU) | Variant exists in catalog and inventory, and is added. | true |
| | int capacity | | basket is full and can't add the item. Calls basketIsFullMessage() | false |
| | HashMap<SKU, Integer> quantityMap | | | |
| | | boolean removeItem(SKU SKU) | variant exists in basket, and is removed | true |
| | | | variant does not exist in basket and can't be removed. Calls itemNotInBasketMessage() | false |
| | | void basketIsFullMessage() | prints error message for user that basket is full | |
| | | boolean setCapacity(int capacity) | user wants to change the capacity to a reasonable amount | true |
| | | | user tries to change capacity to 0 or less | false |
| | | int getCapacity() | returns capacity of basket | capacity |
| | | void itemNotInBasketMessage() | prints error message for user that item doesn't exist in their basket | |
| | | float calculateCost() | total amount to pay is requested | totalCost |
| | | StringBuilder getReceipt() | iterates through items and calculates potential discounts. Important information is appended to StringBuilder obj | receipt |
| | | | | |
| | | | | |
| | | | | |
| Enum SKU | includes an enum variable for all variations of SKUs | | | |
| | | | | |
| | | | | |
| Item (abstract) | float price | float getPrice() | returns price of item | price |
| | String name | String getName() | returns name of item | name |
| | String variant | String getVariant() | returns variant of item | variant |
| | SKU SKU | enum getSKU() | returns SKU enum | SKU |
| | | | | |
| Bagel extends Item | | Bagel(SKU sku) | SKU refers to a bagel, and an instance is created | |
| | | | SKU does not refer to a bagel, and the instance is not created correctly | |
| Coffee extends Item | | Coffee(SKU sku) | SKU refers to a coffee, and an instance is created | |
| | | | SKU does not refer to a coffee, and the instance is not created correctly | |
| Filling extends Item | | Filling(SKU sku) | SKU refers to a filling, and an instance is created | |
| | | | SKU does not refer to a filling, and the instance is not created correctly | |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
Binary file added src/BobsBagelsClassDiagram.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
32 changes: 32 additions & 0 deletions src/main/java/com/booleanuk/core/Bagel.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.booleanuk.core;

public class Bagel extends Item {

public Bagel(SKU SKU) {
this.SKU = SKU;
switch (SKU) {
case BGLO:
this.price = 0.49F;
this.name = "Bagel";
this.variant = "Onion";
break;
case BGLP:
this.price = 0.39F;
this.name = "Bagel";
this.variant = "Plain";
break;
case BGLE:
this.price = 0.49F;
this.name = "Bagel";
this.variant = "Everything";
break;
case BGLS:
this.price = 0.49F;
this.name = "Bagel";
this.variant = "Sesame";
break;
}
}


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

import java.util.ArrayList;
import java.util.Scanner;

public class Basket {
ArrayList<Item> items;
protected int capacity = 20;

public Basket() {
items = new ArrayList<>();
}

public boolean addItem(SKU sku) {

// if no capacity, return false
if(items.size() >= capacity) {
basketIsFullMessage();
return false;
}

// add Bagel
if(sku == SKU.BGLE || sku == SKU.BGLO || sku == SKU.BGLP || sku == SKU.BGLS) {
items.add(new Bagel(sku));
}
// add Coffee
else if (sku == SKU.COFB || sku == SKU.COFW || sku == SKU.COFC || sku == SKU.COFL) {
items.add(new Coffee(sku));
}
// add Filling
else if(sku == SKU.FILB || sku == SKU.FILC || sku == SKU.FILE ||
sku == SKU.FILH || sku == SKU.FILS || sku == SKU.FILX) {
items.add(new Filling(sku));
}
// SKU not recognized, return false
else {
System.out.println("SKU doesn't exist in catalog.");
return false;
}
return true;
}

boolean removeBagel(SKU SKU) {
for(int i = 0; i < items.size(); i++) {
if(items.get(i).SKU == SKU) {
items.remove(i);
return true;
}
}
itemNotInBasket();
return false;
}

public void basketIsFullMessage() {
System.out.println("Basket is full.");
}

public void itemNotInBasket() {
System.out.println("Couldn't find that item in your basket.");
}

public float calculateCost() {
float totalCost = 0F;
for(Item item : items) {
totalCost += item.getPrice();
}
return totalCost;
}

public boolean setCapacity(int capacity) {
if(capacity > 0) {
this.capacity = capacity;
return true;
}
System.out.println("Invalid capacity entered.");
return false;
}

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

public class Coffee extends Item {

public Coffee(SKU SKU) {
this.SKU = SKU;
switch (SKU) {
case COFB:
this.price = 0.99F;
this.name = "Coffee";
this.variant = "Black";
break;
case COFW:
this.price = 1.19F;
this.name = "Coffee";
this.variant = "White";
break;
case COFC:
this.price = 1.29F;
this.name = "Coffee";
this.variant = "Capuccino";
break;
case COFL:
this.price = 1.29F;
this.name = "Coffee";
this.variant = "Latte";
break;
}
}
}
40 changes: 40 additions & 0 deletions src/main/java/com/booleanuk/core/Filling.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package com.booleanuk.core;

public class Filling extends Item {

public Filling(SKU SKU) {
this.SKU = SKU;
switch (SKU) {
case FILB:
this.price = 0.12F;
this.name = "Filling";
this.variant = "Bacon";
break;
case FILE:
this.price = 0.12F;
this.name = "Filling";
this.variant = "Egg";
break;
case FILC:
this.price = 0.12F;
this.name = "Filling";
this.variant = "Cheese";
break;
case FILX:
this.price = 0.12F;
this.name = "Filling";
this.variant = "Cream Cheese";
break;
case FILS:
this.price = 0.12F;
this.name = "Filling";
this.variant = "Smoked Salmon";
break;
case FILH:
this.price = 0.12F;
this.name = "Filling";
this.variant = "Ham";
break;
}
}
}
40 changes: 40 additions & 0 deletions src/main/java/com/booleanuk/core/Item.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package com.booleanuk.core;

enum SKU {
BGLO,
BGLP,
BGLE,
BGLS,
COFB,
COFW,
COFC,
COFL,
FILB,
FILE,
FILC,
FILX,
FILS,
FILH
}
public abstract class Item {
protected SKU SKU;
protected float price;
protected String name;
protected String variant;

public float getPrice() {
return price;
}

public String getName() {
return name;
}

String getVariant() {
return variant;
}

SKU getSKU() {
return SKU;
}
}
32 changes: 32 additions & 0 deletions src/main/java/com/booleanuk/extension/Bagel.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.booleanuk.extension;

public class Bagel extends Item {

public Bagel(SKU SKU) {
this.SKU = SKU;
switch (SKU) {
case BGLO:
this.price = 0.49F;
this.name = "Bagel";
this.variant = "Onion";
break;
case BGLP:
this.price = 0.39F;
this.name = "Bagel";
this.variant = "Plain";
break;
case BGLE:
this.price = 0.49F;
this.name = "Bagel";
this.variant = "Everything";
break;
case BGLS:
this.price = 0.49F;
this.name = "Bagel";
this.variant = "Sesame";
break;
}
}


}
Loading
Loading