Skip to content
Closed
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
108 changes: 108 additions & 0 deletions src/main/java/com/booleanuk/core/Basket.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
package com.booleanuk.core;

import com.booleanuk.core.Items.Bagel;
import com.booleanuk.core.Items.Item;

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


public class Basket {

public static int capacity = 8;

private Inventory storeInventory;

private List<Item> itemsInBasket = new ArrayList<>();


public Basket(){

}

public int getCapacity() {
return capacity;
}

public boolean setCapacity(int capacity) {
if(capacity>0) {
Basket.capacity = capacity;
return true;
}

return false;
}

public Inventory getStoreInventory() {
return storeInventory;
}

public void setStoreInventory(Inventory storeInventory) {
this.storeInventory = storeInventory;
}

public List<Item> getItemsInBasket() {
return itemsInBasket;
}

public void setItemsInBasket(List<Item> itemsInBasket) {
this.itemsInBasket = itemsInBasket;
}

public double sum(){



double sum = 0;
for (Item item : itemsInBasket) {
sum+=item.getPrice();
}

return sum;

}
public boolean add(Item i)throws NullPointerException{
if(i.getID() == null || i.getID().isEmpty() || i.getVariant().isEmpty() || i.getPrice()<=0)
return false;

return this.itemsInBasket.add(i);
}

public boolean remove(Item i){

return this.itemsInBasket.remove(i);

}

public boolean isFull() {
return this.itemsInBasket.size() == capacity;
}

public Item getItem(Item i){
return i;
}

public double costOfBagel(Item i){

return i.getPrice();
}

public Bagel getBagel(){

for (Item i: this.itemsInBasket){
if (i instanceof Bagel)
return (Bagel)i;
}

return null;
}



public boolean hasDiscount(){

return false;
}


}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@


| Classes | Methods | Scenario | Outputs |
| --------- | --------------------------------------- | ------------------------- | ---------------- |
| | | | |
| Member | boolean addToBasket(String ID) | id exists | true |
| | | id dosen't exist | false |
| | | id is null | false |
| Member | boolean removeFromBasket(String ID) | id exists | true |
| | | id dosen't exist | false |
| | | id is null | false |
| Member | boolean isBasketFull() | basket is full | true |
| | | basket is not full | false |
| Customer | double getTotalCost() | items in basket | total cost |
| | | no items in basket | 0 |
| Customer | double getCostOfBagel(String ID) | ID exists | cost of bagel |
| | | ID dosen't exist | 0 |
| | | ID is null | 0 |
| Customer | boolean chooseFilling(String ID) | ID exists | true |
| | | ID dosen't exist | false |
| | | ID is null | null |
| Manager | boolean ChangeCapacity(int newCapacity) | newCapacity is positive | true |
| | | newCapacity is negative | false |
| Manager | boolean addItemToStore(Item i) | item is valid type | true |
| | | item is null | false |
| Basket | double sum() | basket has items | total cost |
| | | basket is empty | 0 |
| Basket | boolean add(Item i) | Item is valid | true |
| | | item is null | false |
| Basket | boolean remove(Item i) | Item exists | true |
| | | item dosen't exist | false |
| Inventory | Item getSpecificItem(String ID) | ID is valid | Item |
| | | ID dosen't exist | null |
| | | ID is null | null |
| Inventory | int getQuantity(Item i) | we have many of that item | integer quantity |
| | | we have 0 | 0 |
| Basket | boolean hasDiscount() | enough items for discount | true |
| | | no items | false |

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

import com.booleanuk.core.Items.Bagel;
import com.booleanuk.core.Items.Coffee;
import com.booleanuk.core.Items.Filling;
import com.booleanuk.core.Items.Item;

import java.util.HashMap;
import java.util.HashSet;
import java.util.Set;

import static com.booleanuk.core.Items.BagelVariants.ONION;
import static com.booleanuk.core.Items.CoffeeVariants.BLACK;
import static com.booleanuk.core.Items.FillingVariants.CREAM_CHEESE;

public class Inventory {


private HashMap<Item, Integer> items = new HashMap<>();
private Set<Item> keys;

public Inventory(){
Item bagel = new Bagel( ONION);
Item filling = new Filling(CREAM_CHEESE);
Item coffee = new Coffee(BLACK);
items.put(bagel,1);
items.put(coffee,1);
items.put(filling,1);
this.keys = items.keySet();
}

public Inventory(HashMap<Item,Integer> items){

this.items = items;
this.keys = items.keySet();
}


public Set<Item> getAllItems(){

return items.keySet();

}

public Item getSpecificItem(String ID){
Item specificItem = null;
for(Item item : keys){
if(item.getID().equals(ID)) {
specificItem = item;
break;
}
}

return specificItem;

}

public int getQuantity(Item i){

return items.get(i);
}
public boolean add(Item item, int quantity){

if(quantity<0)
return false;

if(items.containsKey(item)) {
int oldQuantity = items.get(item);
items.put(item,oldQuantity+quantity);
}
else{
items.put(item,quantity);
}
keys = items.keySet();

return true;

}







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

import java.util.List;

import static com.booleanuk.core.Items.BagelVariants.*;

public class Bagel implements Item{


private double price;
private String ID;
private Enum<BagelVariants> variant;
private Filling filling;

public Bagel(){

}

public Bagel(Enum<BagelVariants> variant){
this.variant = variant;
this.price = setPrice(variant);
this.ID = setId(variant);

}

public Filling getFilling() {
return filling;
}

public void setFilling(Filling filling) {
this.filling = filling;
}

public double getPrice() {
return this.price;
}
public double setPrice(Enum<BagelVariants> variant){
return variant.equals(PLAIN) ? 0.39 : 0.49;
}

public String getID() {
return this.ID;
}

public String getVariant() {
return this.variant.name();
}

private String setId(Enum<BagelVariants> variant){

return variant.equals(ONION)? "BGLO" :
variant.equals(PLAIN)? "BGLP":
variant.equals(EVERYTHING) ? "BGLE" : "BGLS";
}
}
8 changes: 8 additions & 0 deletions src/main/java/com/booleanuk/core/Items/BagelVariants.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.booleanuk.core.Items;

public enum BagelVariants {
ONION,
PLAIN,
EVERYTHING,
SESAME,
}
47 changes: 47 additions & 0 deletions src/main/java/com/booleanuk/core/Items/Coffee.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package com.booleanuk.core.Items;

import static com.booleanuk.core.Items.CoffeeVariants.*;

public class Coffee implements Item{


private double price;
private String ID;
private Enum<CoffeeVariants> variant;

public Coffee(){

}

public Coffee(Enum<CoffeeVariants> variant) {
this.variant = variant;
this.ID = setId(variant);
this.price = setPrice(variant);
}

@Override
public double getPrice() {
return this.price ;
}

@Override
public String getID() {
return this.ID;
}

@Override
public String getVariant() {
return this.variant.name();
}
public double setPrice(Enum<CoffeeVariants>variant){

return variant.equals(BLACK) ? 0.99
: variant.equals(WHITE) ? 1.19 : 1.29;
}
private String setId(Enum<CoffeeVariants> coffeeVariant){

return coffeeVariant.equals(BLACK)? "COFB" :
coffeeVariant.equals(WHITE)? "COFW":
coffeeVariant.equals(CAPUCCINO) ? "COFC" : "COFL";
}
}
9 changes: 9 additions & 0 deletions src/main/java/com/booleanuk/core/Items/CoffeeVariants.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.booleanuk.core.Items;

public enum CoffeeVariants {

BLACK,
WHITE,
CAPUCCINO,
LATTE,
}
Loading
Loading