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
Binary file added classDiagram.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 domain-model.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Basket

| Member | Method | Scenario | Output |
|---------------------------------|-------------------------------|----------------------|---------------|
| Hashmap<String, Item> stockList | addItem(Item item) | Item does not exist | False |
| | | Item exist | True |
| | removeItem(Item item) | Item does not exist | False |
| | | Item exist | True |
| | listOfItems() | | List of items |
| | getTotalCost() | | double |
| | | Basket is not full | False |
| | changeCapasity(int capasity) | | int |
| | discountPrice() | | Double |


# Item

| Member | Method | Scenario | Output |
|--------|------------------|----------|--------|
| | GetPrice() | | double |
| | GetId() | | String |
| | GetType() | | String |
| | GetDescription() | | String |


# Receipt

| Member | Method | Scenario | Output |
|---------------|-------------------------------|----------|--------------------------|
| Basket basket | receiptBuilder(Basket basket) | | Hashmap<String, Integer> |
| | printReceipt(Basket basket) | | Stringbuilder |

20 changes: 20 additions & 0 deletions gleek
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
Basket
- capasity: Integer
- totalCost: Double
- basketList: Hashmap<String, Item>
- stockList: Hashmap<String, Item>
+ checkStock(): boolean
+ removeItem(item: Item): boolean
+ listOfItems(): Hashmap<String, Item>
+ getTotalCost(): Double
+ addItem(item: Item): boolean
+ isFull(): String
+ changeCapasity(capasity: Integer): Integer

Item
- id: String
- price: Double
- Type: String
- Description: String
+ getPrice(item: Item): Double

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

public class Bagel extends Item {
public Bagel(String id, double price, String type, String description) {
super(id, price, type, description);
}
}
121 changes: 121 additions & 0 deletions src/main/java/com/booleanuk/core/Basket.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
package com.booleanuk.core;

import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.HashMap;

public class Basket {

private int capasity = 20;
private double totalCost;

private ArrayList<Item> basketList = new ArrayList<>();

private HashMap<String, Item> stockList = new HashMap<>() {{
Item bagelOnion = new Bagel("BGLO", 0.49, "Bagel", "Onion");
put("BGLO", bagelOnion);
Item bagelPlain = new Bagel("BGLP", 0.39, "Bagel", "Plain");
put("BGLP", bagelPlain);
Item bagelEvery = new Bagel("BGLE", 0.49, "Bagel", "Everything");
put("BGLE", bagelEvery);
Item bagelSesame = new Bagel("BGLS", 0.49, "Bagel", "Sesame");
put("BGLS", bagelSesame);
Item coffeeBlack = new Coffee("COFB", 0.99, "Coffee", "Black");
put("COFB", coffeeBlack);
Item coffeeWhite = new Coffee("COFW", 1.19, "Coffee", "White");
put("COFW", coffeeWhite);
Item coffeeCapuccino = new Coffee("COFC", 1.29, "Coffee", "Capuccino");
put("COFC", coffeeCapuccino);
Item coffeeLatte = new Coffee("COFL", 1.29, "Coffee", "Latte");
put("COFL", coffeeLatte);
Item fillBacon = new Filling("FILB", 0.12, "Filling", "Bacon");
put("FILB", fillBacon);
Item fillEgg = new Filling("FILE", 0.12, "Filling", "Egg");
put("FILE", fillEgg);
Item fillCheese = new Filling("FILC", 0.12, "Filling", "Egg");
put("FILC", fillCheese);
Item fillCream = new Filling("FILX", 0.12, "Filling", "Cream Cheese");
put("FILX", fillCream);
Item fillSal = new Filling("FILS", 0.12, "Filling", "Smoked Salmon");
put("FILS", fillSal);
Item fillHam = new Filling("FILH", 0.12, "Filling", "Ham");
put("FILH", fillHam);
}};

public Basket() {
}

public int getCapasity() {
return capasity;
}

public ArrayList<Item> getBasketList() {
return basketList;
}

public HashMap<String, Item> getStockList() {
return stockList;
}

public boolean addToBasket(String id) {
if (basketList.size() != capasity) {
if (stockList.containsKey(id)) {
if(id.substring(0,2).equals("FI")) {
if(basketList.size() != 0) {
for (int i = 0; i <= basketList.size(); i++) {
if (basketList.get(i).getId().substring(0,2).equals("BG")) {
basketList.add(stockList.get(id));
return true;
} else {
System.out.println("You need a bagel to buy filling!");
return false;
}
}
} else {
System.out.println("You can't just buy fillings!");
return false;
}
}
basketList.add(stockList.get(id));
return true;
} else {
System.out.println("Item does not exist in our inventory.");
return false;
}
}
System.out.println("Cannot add more items!");
return false;
}

public boolean removeItem(String id) {
if(basketList.size() != 0) {
for (int i = 0; i < basketList.size(); i++) {
if (basketList.get(i).getId().equals(id)) {
basketList.remove(i);
return true;
} else {
System.out.println("Item not in basket!");
return false;
}
}
}
System.out.println("No items in basket!");
return false;
}

public ArrayList<Item> listOfItems() {
return basketList;
}

public double getTotalCost() {
for (int i = 0; i < basketList.size(); i++) {
totalCost += basketList.get(i).getPrice();
}
return totalCost;
}

public int changeCapasity(int c) {
this.capasity = c;
return c;
}
}
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 id, double price, String type, String description) {
super(id, price, type, description);
}
}
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 id, double price, String type, String description) {
super(id, price, type, description);
}
}
34 changes: 34 additions & 0 deletions src/main/java/com/booleanuk/core/Item.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package com.booleanuk.core;

import java.util.HashMap;

public class Item {
private String id;
private double price;
private String type;
private String description;

public Item(String id, double price, String type, String description) {
this.id = id;
this.price = price;
this.type = type;
this.description = description;
}

public String getId() {
return id;
}

public double getPrice() {
return price;
}

public String getType() {
return type;
}

public String getDescription() {
return description;
}

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

import com.booleanuk.core.Basket;

public class Discount {

public double discountPrice(Basket basket) {
int bagelCount = 0;
int coffeeCount = 0;
for (int i = 0; i < basket.getBasketList().size(); i++) {
if (basket.getBasketList().get(i).getId().substring(0, 1).equals("B")) {
bagelCount++;
} else if (basket.getBasketList().get(i).getId().substring(0, 1).equals("C")) {
coffeeCount++;
}
}

int remain;
double totalDiscount = 0;

remain = bagelCount / 12; // 18 = 1,5;

if (remain >= 1) {
totalDiscount += 3.99;
bagelCount = bagelCount - 12;
}

remain = bagelCount / 6;

if(remain >= 1) {
totalDiscount += 2.49;
bagelCount = bagelCount - 6;
}

if (bagelCount >= 1 && coffeeCount >= 1) {
totalDiscount += 1.25;
bagelCount--;
coffeeCount--;
}

if(bagelCount != 0) {
for (int i = 0; i < basket.getBasketList().size(); i++) {
if (basket.getBasketList().get(i).getId().substring(0,1).equals("B")) {
for (int j = 0; j < bagelCount; i++) {
totalDiscount += basket.getBasketList().get(i).getPrice();
bagelCount--;
}
}
}
}

if(coffeeCount != 0) {
for (int i = 0; i < basket.getBasketList().size(); i++) {
if (basket.getBasketList().get(i).getId().substring(0,1).equals("C")) {
for (int j = 0; j < coffeeCount; i++) {
totalDiscount += basket.getBasketList().get(i).getPrice();
coffeeCount--;
}
}
}
}
return totalDiscount;
}
}
83 changes: 83 additions & 0 deletions src/main/java/com/booleanuk/extension/Receipt.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
package com.booleanuk.extension;

import com.booleanuk.core.Basket;
import com.booleanuk.core.Item;

import java.text.DecimalFormat;
import java.time.format.DateTimeFormatter;
import java.util.HashMap;

public class Receipt {

public HashMap<String, Integer> receiptBuilder(Basket basket) {
HashMap<String, Integer> boughtItems = new HashMap<>();

int quantityBagel = 0;
int quantityFilling = 0;
int quantityCoffee = 0;

for (int i = 0; i < basket.getBasketList().size(); i++) {
if (basket.getBasketList().get(i).getId().substring(0, 1).equals("B")) {
if (!boughtItems.containsKey(basket.getBasketList().get(i).getDescription())) {
quantityBagel++;
boughtItems.put(basket.getBasketList().get(i).getId(), quantityBagel);
} else {
boughtItems.remove(basket.getBasketList().get(i).getId(), quantityBagel);
quantityBagel++;
boughtItems.put(basket.getBasketList().get(i).getId(), quantityBagel);
}
}

if (basket.getBasketList().get(i).getId().substring(0, 1).equals("F")) {
if (!boughtItems.containsKey(basket.getBasketList().get(i).getDescription())) {
quantityFilling++;
boughtItems.put(basket.getBasketList().get(i).getId(), quantityFilling);
} else {
boughtItems.remove(basket.getBasketList().get(i).getId(), quantityFilling);
quantityFilling++;
boughtItems.put(basket.getBasketList().get(i).getId(), quantityFilling);
}
}

if (basket.getBasketList().get(i).getId().substring(0, 1).equals("C")) {
if (!boughtItems.containsKey(basket.getBasketList().get(i).getDescription())) {
quantityCoffee++;
boughtItems.put(basket.getBasketList().get(i).getId(), quantityCoffee);
} else {
boughtItems.remove(basket.getBasketList().get(i).getId(), quantityCoffee);
quantityCoffee++;
boughtItems.put(basket.getBasketList().get(i).getId(), quantityCoffee);
}
}
}
return boughtItems;
}

public StringBuilder printReceipt(Basket basket) {
StringBuilder sb = new StringBuilder();
HashMap<String, Integer> list = receiptBuilder(basket);
DecimalFormat df = new DecimalFormat();
String desc = "";
String type = "";
double price = 0;

sb.append("~~~ Bob's Bagels ~~~\n");
sb.append(java.time.ZonedDateTime.now().format(DateTimeFormatter.ofPattern("MM/dd/yyyy hh:mm\n")));
sb.append("\n----------------------------\n");

for (String name : list.keySet()) {
for (int i = 0; i < basket.getStockList().size(); i++) {
Item item = basket.getStockList().get(name);
price = item.getPrice();
desc = item.getDescription();
type = item.getType();
}
sb.append(desc + " " + type + " " + list.get(name).toString() + " " + df.format(price * list.get(name)) + "£\n");
}
sb.append("\n----------------------------\n");
sb.append("Total cost: " + df.format(basket.getTotalCost()) + "£\n");
System.out.println(sb);
return sb;
}
}

Loading
Loading