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

Mattias Hedbom #137

Open
wants to merge 41 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
3395af2
domain model completed
Jan 10, 2025
b9b3378
domain model, small adjustment
Jan 10, 2025
0df4efe
domain model, small adjustment
Jan 10, 2025
e5493fa
created all classes, also made som changes to the domain model
Jan 13, 2025
bb73d7c
Created the initial test for the seePrice() method in menu
Jan 13, 2025
e0df841
Created the initial seePrice() method
Jan 13, 2025
cf181db
Completed the seePrice() method/ test.
Jan 13, 2025
e47f0ea
initial method for showAllFillingsWithCosts() method
Jan 13, 2025
61539e3
Needed to add String typeOfItem to Item class, needed to list all fil…
Jan 13, 2025
e0c590a
Needed to add String typeOfItem to Item class, needed to list all fil…
Jan 13, 2025
f117ed5
completed method for showAllFillingsWithCosts()
Jan 13, 2025
ce17b92
completed method for isContainedInInventory()
Jan 13, 2025
33bbf21
initial method for isContainedInInventory completed
Jan 13, 2025
b2e74a3
Method for isContainedInInventory completed
Jan 13, 2025
b0c59a1
Updated the fields and the constructor for the basket-class
Jan 13, 2025
4b2f21b
Initial test for addItem() in basket-class completed
Jan 13, 2025
69ecfae
Initial method for addItem() in basket-class completed
Jan 13, 2025
7f1af65
Method for addItem() in basket-class completed, also added an extra t…
Jan 13, 2025
90de7a8
Initial method for removeItem() in basket-class completed
Jan 13, 2025
091017c
Initial method for removeItem() in basket-class completed
Jan 13, 2025
daa655c
Test for removeItem() in basket-class completed
Jan 13, 2025
20d515a
Method for removeItem() in basket-class completed
Jan 13, 2025
8976d17
Initial test for changeSizeOfBasket() in basket-class completed
Jan 13, 2025
58a3ec8
Initial method for changeSizeOfBasket() in basket-class completed. Al…
Jan 13, 2025
170742e
Method/ Test for changeSizeOfBasket() in basket-class completed.
Jan 13, 2025
dc14257
Initial Test for totalCost() in basket-class completed.
Jan 13, 2025
8f7593f
Initial method for totalCost() in basket-class completed.
Jan 13, 2025
91c47d2
Method / Test for totalCost() in basket-class completed.
Jan 13, 2025
69cc924
Domain model adjusted for extension 1. Tests made for method totalCos…
Jan 13, 2025
3dd314c
Forgot to write the code for the extension in the extension folder, t…
Jan 14, 2025
2efdac5
Forgot the discount for 1bagel and 1 coffee, added another test for this
Jan 14, 2025
2acf2ba
Forgot the discount for 1bagel and 1 coffee, completed the method to …
Jan 14, 2025
a31de45
Added the class diagrams, the one made before the extension and the o…
Jan 14, 2025
2ac4d45
made a small adjustment to the receipt class
Jan 14, 2025
ca5b30c
Created the test for the second extension, also created the Extension…
Jan 14, 2025
7aaddbf
redid the domain model for the receipt class, added two more methods:
Jan 14, 2025
7cab442
Test made for the costWithDiscounts() method
Jan 14, 2025
bed4182
method costWithDiscounts() completed
Jan 14, 2025
d5148b0
Discovered that I needed two parameters in my costWithDiscounts() met…
Jan 14, 2025
bb6e0ec
Method printReceipt() completed
Jan 14, 2025
271a052
Forgot to update the classDiagram for the extension part when I recen…
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 src/classDiagramBeforeExtension.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 src/classDiagramWithExtension.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
89 changes: 89 additions & 0 deletions src/domain-model.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
# Bob's bagels

## Menu
| Method | Member variable | Scenario | Result |
|-----------------------------------|-----------------------------|-------------------------------------------|--------------------------|
| | ArrayList<item> itemsOnMenu | | |
| seePrice(Item anItem) | | The item exist in the inventory | String show price |
| | | The item dont exist in the inventory | String error message |
| | | | |
| showAllFillingsWithCosts() | | List all fillings in that are on the menu | String with all fillings |
| | | | |
| | | | |
| isContainedInInventory(Item item) | | item is contained in the inventory | True |
| | | item is not contained in the inventory | False |


## Basket
| Method | Member variable | Scenario | Result |
|---------------------------------|-------------------------------|-----------------------------------|---------------------------------------------|
| addItem(Item anItem) | ArrayList<Item> itemsInBasket | basket is full | String Error message |
| | int size | basket is not full | String success message |
| | | | |
| removeItem(Item anItem) | | item is not contained in basket | String Error message |
| | | item is contained in basket | String success message |
| | | | |
| changeSizeOfBasket(int newSize) | | entering acceptable size | True |
| | | entering non-acceptable size | False |
| | | | |
| totalCost() | | basket consists of atleast 1 item | Double total cost of basket |
| | | basket dont consist any items | 0 |
| | | | |
| //EXTENSION | | | |
| totalCostWithDiscounts() | | discounts are received | Double total cost of basket minus discounts |
| | | discounts are not received | Double total cost of basket |


## Items
| Method | Member Variable | Scenario | Result |
|---------------------|---------------------|----------|--------|
| | Double price | | |
| | String abbreviation | | |
| | String name | | |
| | String typeOfItem | | |
| getters and setters | | | |


## Coffee
| Method | Member Variable | Scenario | Result |
|---------------------|---------------------|----------|--------|
| | Float price | | |
| | String abbreviation | | |
| | String name | | |
| getters and setters | | | |


## Bagel
| Method | Member Variable | Scenario | Result |
|---------------------|---------------------|----------|--------|
| | Float price | | |
| | String abbreviation | | |
| | String name | | |
| getters and setters | | | |


## Filling
| Method | Member Variable | Scenario | Result |
|---------------------|---------------------|----------|--------|
| | Float price | | |
| | String abbreviation | | |
| | String name | | |
| getters and setters | | | |



// EXTENSION
## Receipt

| Method | Member Variable | Scenario | Result |
|----------------------------------------------|----------------------------------------------|-----------------------------------|---------------------------------------------|
| | HashMap<Item, Integer> itemsThatArePurchased | | |
| | String dateOfPurchase | | |
| printReceipt() | | basket consists of atleast 1 item | String receipt returned and is also printed |
| | | basket dont contain any items | String Error message |
| | | | |
| totalCostWithDiscounts() | | discounts are received | Double total cost of basket minus discounts |
| | | discounts are not received | Double total cost of basket |
| | | | |
| costWithDiscounts(Item anItem, int quantity) | | discounts are received | Double cost of item minus discounts |
| | | discounts are not received | Double cost of item |
7 changes: 7 additions & 0 deletions src/main/java/com/booleanuk/core/BaconFilling.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.booleanuk.core;

public class BaconFilling extends Filling{
public BaconFilling(Double price, String abbreviation, String name, String typeOfItem){
super(price, abbreviation, name, typeOfItem);
}
}
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(Double price, String abbreviation, String name, String typeOfItem){
super(price, abbreviation, name, typeOfItem);
}
}
56 changes: 56 additions & 0 deletions src/main/java/com/booleanuk/core/Basket.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package com.booleanuk.core;

import java.util.ArrayList;

public class Basket {
private ArrayList<Item> itemsInBasket;
private int size;

public Basket(ArrayList<Item> itemsInBasket, int size){
this.itemsInBasket = itemsInBasket;
this.size = size;
}

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

public void setSize(int size) {
this.size = size;
}

public String addItem(Item itemToAdd){
if(this.itemsInBasket.size() < this.size){
this.itemsInBasket.add(itemToAdd);
return itemToAdd.getName() + " was added to your basket!";
}
return "Basket is full!";
}

public String removeItem(Item itemToRemove){
for(Item item : itemsInBasket){
if(item.getName().equals(itemToRemove.getName())){
itemsInBasket.remove(item);
return itemToRemove.getName() + " was removed from the basket!";
}
}
return "Item do not exist in basket!";
}

public boolean changeSizeOfBasket(int newSize){
if(newSize > 0 && newSize >= this.itemsInBasket.size()){
setSize(newSize);
return true;
}
return false;
}

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

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

public class BlackCoffee extends Coffee{
public BlackCoffee(Double price, String abbreviation, String name, String typeOfItem){
super(price, abbreviation, name, typeOfItem);
}
}
7 changes: 7 additions & 0 deletions src/main/java/com/booleanuk/core/CappucinoCoffee.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.booleanuk.core;

public class CappucinoCoffee extends Coffee{
public CappucinoCoffee(Double price, String abbreviation, String name, String typeOfItem){
super(price, abbreviation, name, typeOfItem);
}
}
7 changes: 7 additions & 0 deletions src/main/java/com/booleanuk/core/CheeseFilling.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.booleanuk.core;

public class CheeseFilling extends Filling{
public CheeseFilling(Double price, String abbreviation, String name, String typeOfItem){
super(price, abbreviation, name, typeOfItem);
}
}
8 changes: 8 additions & 0 deletions src/main/java/com/booleanuk/core/Coffee.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.booleanuk.core;

public class Coffee extends Item{
public Coffee(Double price, String abbreviation, String name, String typeOfItem){
super(price, abbreviation, name, typeOfItem);

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

public class CreamCheeseFilling extends Filling{
public CreamCheeseFilling(Double price, String abbreviation, String name, String typeOfItem){
super(price, abbreviation, name, typeOfItem);
}
}
7 changes: 7 additions & 0 deletions src/main/java/com/booleanuk/core/EggFilling.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.booleanuk.core;

public class EggFilling extends Filling{
public EggFilling(Double price, String abbreviation, String name, String typeOfItem){
super(price, abbreviation, name, typeOfItem);
}
}
7 changes: 7 additions & 0 deletions src/main/java/com/booleanuk/core/EverythingBagel.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.booleanuk.core;

public class EverythingBagel extends Bagel{
public EverythingBagel(Double price, String abbreviation, String name, String typeOfItem){
super(price, abbreviation, name, typeOfItem);
}
}
8 changes: 8 additions & 0 deletions src/main/java/com/booleanuk/core/Filling.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.booleanuk.core;

public class Filling extends Item{
public Filling(Double price, String abbreviation, String name, String typeOfItem){
super(price, abbreviation, name, typeOfItem);

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

public class HamFilling extends Filling{
public HamFilling(Double price, String abbreviation, String name, String typeOfItem){
super(price, abbreviation, name, typeOfItem);
}
}
4 changes: 4 additions & 0 deletions src/main/java/com/booleanuk/core/Inventory.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package com.booleanuk.core;

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

public class Item {
private Double price;
private String abbreviation;
private String name;
private String typeOfItem;

public Item(Double price, String abbreviation, String name, String typeOfItem){
this.price = price;
this.abbreviation = abbreviation;
this.name = name;
this.typeOfItem = typeOfItem;
}

public String getTypeOfItem() {
return typeOfItem;
}

public Double getPrice() {
return price;
}

public String getAbbreviation() {
return abbreviation;
}

public String getName() {
return name;
}
}
7 changes: 7 additions & 0 deletions src/main/java/com/booleanuk/core/LatteCoffee.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.booleanuk.core;

public class LatteCoffee extends Coffee{
public LatteCoffee(Double price, String abbreviation, String name, String typeOfItem){
super(price, abbreviation, name, typeOfItem);
}
}
41 changes: 41 additions & 0 deletions src/main/java/com/booleanuk/core/Menu.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package com.booleanuk.core;

import java.util.ArrayList;

public class Menu {
private ArrayList<Item> itemsOnMenu;

public Menu(ArrayList<Item> itemsOnMenu){
this.itemsOnMenu = itemsOnMenu;
}

public String seePrice(Item itemToCheck){
for(Item anItem : itemsOnMenu){
if(anItem.getName().equals(itemToCheck.getName())){
return "The item costs: " + itemToCheck.getPrice();
}
}

return "Item dont exist on the menu!";
}

public String showAllFillingsWithCosts(){
String allFillingsWithPrices = "";
for(Item anItem : this.itemsOnMenu){
if(anItem.getTypeOfItem().equals("Filling")){
allFillingsWithPrices += anItem.getName() + ", " + anItem.getPrice() + "$\n";

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use stringbuilder in place of concatenating strings in a loop, as strings are immutable, so a new string will be created at each iteration

}
}
return allFillingsWithPrices;
}


public Boolean isContainedInInventory(Item itemToCheck){
for(Item anItem : itemsOnMenu){
if(anItem.getName().equals(itemToCheck.getName())){
return true;
}
}
return false;
}
}
7 changes: 7 additions & 0 deletions src/main/java/com/booleanuk/core/OnionBagel.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.booleanuk.core;

public class OnionBagel extends Bagel{
public OnionBagel(Double price, String abbreviation, String name, String typeOfItem){
super(price, abbreviation, name, typeOfItem);
}
}
7 changes: 7 additions & 0 deletions src/main/java/com/booleanuk/core/PlainBagel.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.booleanuk.core;

public class PlainBagel extends Bagel{
public PlainBagel(Double price, String abbreviation, String name, String typeOfItem){
super(price, abbreviation, name, typeOfItem);
}
}
7 changes: 7 additions & 0 deletions src/main/java/com/booleanuk/core/SesameBagel.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.booleanuk.core;

public class SesameBagel extends Bagel{
public SesameBagel(Double price, String abbreviation, String name, String typeOfItem){
super(price, abbreviation, name, typeOfItem);
}
}
7 changes: 7 additions & 0 deletions src/main/java/com/booleanuk/core/SmokedSalmonFilling.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.booleanuk.core;

public class SmokedSalmonFilling extends Filling{
public SmokedSalmonFilling(Double price, String abbreviation, String name, String typeOfItem){
super(price, abbreviation, name, typeOfItem);
}
}
7 changes: 7 additions & 0 deletions src/main/java/com/booleanuk/core/WhiteCoffee.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.booleanuk.core;

public class WhiteCoffee extends Coffee{
public WhiteCoffee(Double price, String abbreviation, String name, String typeOfItem){
super(price, abbreviation, name, typeOfItem);
}
}
Loading