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

Aidan van Geest #11

Open
wants to merge 54 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
172d01b
Domain Model
RBreedvbeld May 11, 2023
dadc7c1
set up classes and copied tests from previous Bobs bagels exercise
AidanvG May 11, 2023
84479e5
Added source code from previous bobs bagels exercise
AidanvG May 11, 2023
9ce70bb
add item test
AidanvG May 11, 2023
2c5cebe
getItem test and source code completed
AidanvG May 11, 2023
85fc87c
updated domain model
AidanvG May 11, 2023
82e3d97
updated class diagram
AidanvG May 11, 2023
a0f9726
Test addItem Succes test completed
RBreedvbeld May 12, 2023
10f3cd1
test for succes and test for failure
RBreedvbeld May 12, 2023
fbb4c01
test add for item that does not exist
RBreedvbeld May 12, 2023
3f234a8
Test add item includes method succeed
RBreedvbeld May 12, 2023
9742fbb
Test for succesful removal of item
AidanvG May 12, 2023
bd2d2e0
Remove item successfully method updated
AidanvG May 12, 2023
ae4b25c
Test for updating basket capacity successfully passes
AidanvG May 12, 2023
e1b881a
test for failed update of capacity due to 0 or negative number passed
AidanvG May 12, 2023
69f2b2e
test for failed update of capacity due to new capacity being less tha…
AidanvG May 12, 2023
47a52e6
Test for total cost
AidanvG May 12, 2023
74319bf
Total cost method completed
AidanvG May 12, 2023
bedb715
succesfull test get item price
RBreedvbeld May 12, 2023
1613504
failure test itemPrice does not exist return 0.00
RBreedvbeld May 12, 2023
2450e9d
completed item does not exist in itemPrice method
RBreedvbeld May 12, 2023
ef69d29
updated domain model and class diagram
AidanvG May 12, 2023
7afe2ea
Refactored classes for abstraction
AidanvG May 13, 2023
4ee959a
Test item type
AidanvG May 13, 2023
8ac32ba
Test item price getter and setter
AidanvG May 13, 2023
6b93964
Test item sku getter and setter
AidanvG May 13, 2023
96d6cfb
Test item variant getter and setter
AidanvG May 13, 2023
9fe957f
refactored for dependency injection
RBreedvbeld May 15, 2023
3c44294
Updated domain model
RBreedvbeld May 15, 2023
c432d80
test onion bagels discount
AidanvG May 15, 2023
eb6524e
Test plain bagels discount
AidanvG May 15, 2023
3a8866c
Test everything bagels discount
AidanvG May 15, 2023
11ff589
Test for coffee bagel discount and combination discounts completed
AidanvG May 15, 2023
31eaeb2
Passed test for onionBagelsDiscount
AidanvG May 15, 2023
ef8bd7b
Passed tests for plainBagelsDiscount EverythingBagelsDiscount and Cof…
AidanvG May 15, 2023
ea921d6
Fixed coffee discount test
AidanvG May 15, 2023
345b2b3
Test combination discount completed
RBreedvbeld May 16, 2023
bd80ae7
Refactored for Interface and completed tests for bagels and fillings
AidanvG May 16, 2023
068f434
Test Coffee class completed
RBreedvbeld May 16, 2023
44dffc7
Test add bagel and basket capacity completed
RBreedvbeld May 16, 2023
88a444b
Updated Domain Model
RBreedvbeld May 16, 2023
4e44941
Updated class diagram
AidanvG May 16, 2023
6329358
Started setup for extension 2
AidanvG May 16, 2023
2dbb492
DateTime test created and passed
AidanvG May 17, 2023
ac39040
tested format of printReceipt
AidanvG May 17, 2023
628e2b0
Made progress on test of printReceipt using hashmap
AidanvG May 17, 2023
fbce514
Completed and passed test for printReceipts
AidanvG May 17, 2023
8ba609b
Added Saved totalDiscount on receipt
RBreedvbeld May 17, 2023
60ba68e
Some small changes
RBreedvbeld May 17, 2023
6a1761b
Print receipt discounts and discount varables for each discount
RBreedvbeld May 18, 2023
d996c29
Receipt includes discounts for each
RBreedvbeld May 18, 2023
7bec0bf
Updated Domain Model
RBreedvbeld May 18, 2023
e3364cf
Updated class diagram
AidanvG May 18, 2023
2e3cdee
Small change to trigger testing on github
AidanvG May 19, 2023
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 BobClassDiagram.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
102 changes: 102 additions & 0 deletions BobDomainModel.md

Large diffs are not rendered by default.

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

public class Bagels implements ItemInterface{
private String type;
private double price;
private String sku;
private String variant;

public Bagels(String type, double price, String sku, String variant) {
this.setType(type);
this.setPrice(price);
this.setSku(sku);
this.setVariant(variant);
}

@Override
public String toString() {
return "Item: " + this.getVariant() + " " + this.getType() + "\n"
+ "Price: " + this.getPrice() + "\n"
+ "SKU: " + this.getSku();
}

public String getType() {
return type;
}

public void setType(String type) {
this.type = type;
}

public double getPrice() {
return price;
}

public void setPrice(double price) {
this.price = price;
}

public String getSku() {
return sku;
}

public void setSku(String sku) {
this.sku = sku;
}

public String getVariant() {
return variant;
}

public void setVariant(String variant) {
this.variant = variant;
}
}
201 changes: 201 additions & 0 deletions src/main/java/com/booleanuk/core/Basket.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,201 @@
package com.booleanuk.core;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

public class Basket {
private ArrayList<ItemInterface> items;
private Inventory inventory;
private int basketCapacity;
private int sumCosts;
public Map<String, Integer> itemsMap;
public double totalDiscount;
public double onionBagelDiscount;
public double everythingBagelDiscount;
public double plainBagelDiscount;
public double coffeeDiscount;


public Basket(Inventory inventory) {
this.setItems(new ArrayList<>());
this.setBasketCapacity(100);
this.setInventory(inventory);
this.itemsMap = new HashMap<>();
}

public boolean addItem(String sku){
if (this.getItems().size() < this.getBasketCapacity()) {
if (getInventory().searchItem(sku) == null){
System.out.println("Can not add item because this item does not exist!");
return false;
} else if(getInventory().searchItem(sku).getSku().equals(sku)) {
this.getItems().add(getInventory().searchItem(sku.toUpperCase()));
setSumCosts((int) (getSumCosts() + (this.getInventory().searchItem(sku).getPrice() * 100)));
return true;
}
System.out.println("Basket is full, could not add bagel!");
}
return false;
}

public boolean removeItem(String sku) {
boolean itemExistsInBasket = false;
for (int i = 0; i < this.getItems().size(); i++) {
if (this.getItems().get(i).getSku().equals(sku)) {
itemExistsInBasket = true;
setSumCosts((int) (getSumCosts() - (this.getInventory().searchItem(sku).getPrice() * 100)));
break;
}
}

if(itemExistsInBasket) {
this.getItems().remove(this.getInventory().searchItem(sku));
return true;
}
System.out.println("The bagel does not exist in the basket!");
return false;

}

public boolean updateBasketCapacity(int newCapacity) {
if(newCapacity <= 0) {
System.out.println("Cannot update basket capacity to zero or less.");
return false;
} else if (newCapacity < this.getItems().size()) {
System.out.println("Cannot update basket capacity to a size smaller than current basket size.");
return false;
}
this.setBasketCapacity(newCapacity);
return true;
}

public double totalCost () {
int countOnionBagels = 0;
int numOnionBagelDiscounts = 0;
int totalOnionBagelDiscount = 0;
int countPlainBagels = 0;
int numPlainBagelDiscounts = 0;
int totalPlainBagelDiscount = 0;
int remainingPlainBagels = 0;
int countEverythingBagels = 0;
int numEverythingBagelDiscounts = 0;
int totalEverythingBagelDiscount = 0;
int countBlackCoffee = 0;
int numBlackCoffeeDiscounts = 0;
int totalBlackCoffeeDiscount = 0;



for (int i = 0; i < items.size(); i++) {
if (this.getItems().get(i).getSku().equals("BGLO")) {
countOnionBagels++;
numOnionBagelDiscounts = Math.round((float) countOnionBagels / 6);
totalOnionBagelDiscount = (int) (numOnionBagelDiscounts * 0.45 * 100);

} else if (this.getItems().get(i).getSku().equals("BGLP")) {
countPlainBagels++;
numPlainBagelDiscounts = Math.round((float) countPlainBagels / 12);
totalPlainBagelDiscount = (int) (numPlainBagelDiscounts * 0.69 * 100);
} else if (this.getItems().get(i).getSku().equals("BGLE")) {
countEverythingBagels++;
numEverythingBagelDiscounts = Math.round((float) countEverythingBagels / 12);
totalEverythingBagelDiscount = (int) (numEverythingBagelDiscounts * 0.45 * 100);
} else if (this.getItems().get(i).getSku().equals("COFB")) {
countBlackCoffee++;
if (countPlainBagels % 12 > 0) {
remainingPlainBagels = countPlainBagels % 12;
numBlackCoffeeDiscounts = Math.min(countBlackCoffee, remainingPlainBagels);
totalBlackCoffeeDiscount = (int) (numBlackCoffeeDiscounts * 0.13 * 100);
}
}
}
totalDiscount = (double)((totalOnionBagelDiscount + totalPlainBagelDiscount + totalEverythingBagelDiscount + totalBlackCoffeeDiscount)/100.0);

onionBagelDiscount = (double)((totalOnionBagelDiscount)/100.0);
everythingBagelDiscount = (double)((totalEverythingBagelDiscount)/100.0);
plainBagelDiscount = (double)((totalPlainBagelDiscount)/100.0);
coffeeDiscount = (double)((totalBlackCoffeeDiscount)/100.0);


return (double) ((getSumCosts() - totalOnionBagelDiscount - totalPlainBagelDiscount - totalEverythingBagelDiscount - totalBlackCoffeeDiscount) / 100.0);

}

public double itemPrice(String sku) {
if(this.getInventory().searchItem(sku) == null){
return 0.00;
}
return this.getInventory().searchItem(sku).getPrice();
}

public String returnDateTime() {
LocalDateTime dateTime = LocalDateTime.now();
DateTimeFormatter dtf = DateTimeFormatter.ofPattern("dd/MM/yyyy HH:mm:ss");
return dtf.format(dateTime);
}

public void printReceipt() {
for (int i = 0; i < getItems().size(); i++) {
if (itemsMap.containsKey(getItems().get(i).getSku())) {
itemsMap.put(getItems().get(i).getSku(), itemsMap.get(getItems().get(i).getSku())+1);
} else {
itemsMap.put(getItems().get(i).getSku(), 1);
}
}
double storeTotalCosts = totalCost();

System.out.println("\n ~~~ Bob's Bagels ~~~\n");
System.out.println(" " + returnDateTime() + "\n");
System.out.println("----------------------------------");
itemsMap.forEach((key, value) -> {
System.out.printf("%-20s %-6d $ %.2f \n", inventory.searchItem(key).getVariant() + " " + inventory.searchItem(key).getType(), value, (float)(((itemPrice(key) * value) * 100) / 100.00));
});
System.out.println("----------------------------------\n");
System.out.println("Discounts ");
System.out.println("Everything Bagel (-$ " + everythingBagelDiscount + ")");
System.out.println("Plain Bagel (-$ " + plainBagelDiscount + ")");
System.out.println("Onion Bagel (-$ " + onionBagelDiscount + ")");
System.out.println("Coffee (-$ " + coffeeDiscount + ")\n");
System.out.println("----------------------------------\n");
System.out.println("Total $ " + storeTotalCosts + "\n");
System.out.println(" You saved a total of $" + totalDiscount + "\n" +
" on this shop\n");
System.out.println(" Thank you for your order!\n");
}

public ArrayList<ItemInterface> getItems() {
return items;
}

public void setItems(ArrayList<ItemInterface> items) {
this.items = items;
}

public Inventory getInventory() {
return inventory;
}

public void setInventory(Inventory inventory) {
this.inventory = inventory;
}

public int getBasketCapacity() {
return basketCapacity;
}

public void setBasketCapacity(int basketCapacity) {
this.basketCapacity = basketCapacity;
}

public int getSumCosts() {
return sumCosts;
}

public void setSumCosts(int sumCosts) {
this.sumCosts = sumCosts;
}

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

public class Coffee implements ItemInterface{
private String type;
private double price;
private String sku;
private String variant;

public Coffee(String type, double price, String sku, String variant) {
this.setType(type);
this.setPrice(price);
this.setSku(sku);
this.setVariant(variant);
}

@Override
public String toString() {
return "Item: " + this.getVariant() + " " + this.getType() + "\n"
+ "Price: " + this.getPrice() + "\n"
+ "SKU: " + this.getSku();
}

public String getType() {
return type;
}

public void setType(String type) {
this.type = type;
}

public double getPrice() {
return price;
}

public void setPrice(double price) {
this.price = price;
}

public String getSku() {
return sku;
}

public void setSku(String sku) {
this.sku = sku;
}

public String getVariant() {
return variant;
}

public void setVariant(String variant) {
this.variant = variant;
}
}
54 changes: 54 additions & 0 deletions src/main/java/com/booleanuk/core/Fillings.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package com.booleanuk.core;

public class Fillings implements ItemInterface{
private String type;
private double price;
private String sku;
private String variant;

public Fillings(String type, double price, String sku, String variant) {
this.setType(type);
this.setPrice(price);
this.setSku(sku);
this.setVariant(variant);
}

@Override
public String toString() {
return "Item: " + this.getVariant() + " " + this.getType() + "\n"
+ "Price: " + this.getPrice() + "\n"
+ "SKU: " + this.getSku();
}

public String getType() {
return type;
}

public void setType(String type) {
this.type = type;
}

public double getPrice() {
return price;
}

public void setPrice(double price) {
this.price = price;
}

public String getSku() {
return sku;
}

public void setSku(String sku) {
this.sku = sku;
}

public String getVariant() {
return variant;
}

public void setVariant(String variant) {
this.variant = variant;
}
}
Loading