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

Melvin Uthayaseelan #113

Open
wants to merge 44 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
f9e0f16
Making test
uthmel Aug 16, 2024
b75c058
Making source
uthmel Aug 16, 2024
a9dfdf8
trying to make bageltest
uthmel Aug 16, 2024
d9a83a9
testbagel()
uthmel Aug 16, 2024
1b56199
BagelTest function
uthmel Aug 16, 2024
e7c7d2d
testaddBagel
uthmel Aug 16, 2024
4bc6672
failed test and added source for Basket
uthmel Aug 16, 2024
bbf41ff
tried and fail removeBagel test
uthmel Aug 16, 2024
58f3220
added source code for removeBagel
uthmel Aug 16, 2024
17ca714
added isFulltest and failed
uthmel Aug 16, 2024
559e9a3
Fixed soruce code and test for isFull()
uthmel Aug 16, 2024
db76f9a
adding test fir removeBagelIfNotExist
uthmel Aug 18, 2024
d7c99e8
fixing testRemoveBagelIfNotExist()
uthmel Aug 19, 2024
3fbf7d7
fixing sourcecode
uthmel Aug 19, 2024
0314b04
Making testGetBalance()
uthmel Aug 19, 2024
f76f033
Making testGetBalance()
uthmel Aug 19, 2024
b2982f7
Making testGetBalance()
uthmel Aug 19, 2024
be93fee
making testGetTotalCost
uthmel Aug 19, 2024
e5482dd
making testGetTotalCost
uthmel Aug 19, 2024
8236432
failing testAddBagelThatDoesNotExist()
uthmel Aug 19, 2024
b84be71
fixed test and source code
uthmel Aug 19, 2024
1ef8afe
fixed test and source code
uthmel Aug 19, 2024
82f3cc4
made more files to test for each class. This is for clarity. Fixed so…
uthmel Aug 19, 2024
46a88ad
made more files to test for each class. This is for clarity. Fixed so…
uthmel Aug 19, 2024
e65ddc5
pushed domain_model
uthmel Aug 20, 2024
2247630
test pushing extension 1
uthmel Aug 20, 2024
3d85a95
adding files to extension
uthmel Aug 20, 2024
cee662b
adding files to extension
uthmel Aug 20, 2024
2972ff4
adding files to extension
uthmel Aug 20, 2024
5bf445a
adding files to extension
uthmel Aug 20, 2024
e83dd8e
adding files for extension tests
uthmel Aug 20, 2024
c022212
adding files for extension tests
uthmel Aug 20, 2024
f476a74
trying testing with bagel in extension
uthmel Aug 20, 2024
2513c6e
trying adding rest of the files for extension
uthmel Aug 20, 2024
c9f97c8
Trying to make testTotalCoatWithoutDiscounts
uthmel Aug 20, 2024
d0a7017
testing standard criteria check
uthmel Aug 20, 2024
6d8d406
trying to pass the standard criteria
uthmel Aug 20, 2024
7ed3590
trying to pass the standard criteria
uthmel Aug 20, 2024
0b9ce65
trying to pass the standard criteria
uthmel Aug 20, 2024
26aeb01
trying to pass the standard criteria
uthmel Aug 20, 2024
9391a88
Refactored some names of the methods for clarity
uthmel Aug 21, 2024
addea08
Refactored some names of the methods for clarity
uthmel Aug 21, 2024
1eb7ade
The core works now. Just a comit to show it.
uthmel Aug 22, 2024
e835ac4
last comit to check
uthmel Aug 27, 2024
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 Bops_Bagel_OOP_Class_diagram.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
39 changes: 39 additions & 0 deletions domain_model.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
| Classes | Attributes | Methods | Scenarios | Outputs |
|-----------|------------------------------|-----------------------------|---------------------------------|-----------------------------|
| Basket | ArrayList<Item> listOfBasket | addItem(Item item) | If basket is not full | Added item to the basket |
| | Int capacity | | If basket is full | Error: Basket is full |
| | Inventory inventory | | | |
| | | removeBagel(Item item) | If Item exist | Removes item from basket |
| | | | If item not exist | Error: Item does not exist |
| | | | | |
| | | getTotalCost() | Calculating the cost | double price |
| | | | | |
| | | getListOfBasket() | Always | List of items in the basket |
| | | | | |
| | | setCapacity() | Always | void |
| | | | | |
| | | getCapacity() | Always | returns basketcapacity |
| | | | | |
| | | | | |
| Item | String sku | getSku() | Always | String sku |
| | double price | | | |
| | String name | getPrice() | If item exist | double price |
| | | | | |
| | | getName() | If item exist | String name |
| | | | | |
| Bagel | Bagelvariant variant | getVariant() | If variant exist | enum variant |
| | Filling filling | | | |
| | | getFilling() | If filling exist | Getting filling from Bagel |
| | | | | |
| | | setFilling() | If filling exist | Setting new filling |
| | | | | |
| Inventory | Map<String, Item> items | getItem(String sku) | If item is available | Getting String sku |
| | | | | |
| | | isItemAvailable(String sku) | If item available | true |
| | | | If item not available | false |
| | | | | |
| | | addItem(Item item) | Adding an item to the inventory | Added to the hashmap |
| | | | | |
| Coffee | String coffeeType | getCoffeeType() | Always | Return coffeetype as string |
| | | | | |
| Filling | String fillingType | getFillingType() | Retrieving the fillingType | String fillingType |
29 changes: 29 additions & 0 deletions src/main/java/com/booleanuk/core/Bagel.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.booleanuk.core;

// A bagel can only have one filling.

public class Bagel extends Item {
private BagelVariant variant;
private Filling filling;

public Bagel(String sku, double price, String name, BagelVariant variant) {
super(sku, price, name);
this.variant = variant;
}

public Filling getFilling() {
return filling;
}

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

public BagelVariant getVariant() {
return variant;
}

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

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

public class Basket {
public ArrayList<Item> listOfBasket;
public int capacity;
private Inventory inventory;


public Basket(int capacity, Inventory inventory) {
this.listOfBasket = new ArrayList<>();
this.capacity = capacity;
this.inventory = inventory;

}

public Inventory getInventory() {
return inventory;
}

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

public void addItem(Item item) {
if (inventory.isItemAvailable(item.getSku())) {
if (listOfBasket.size() < capacity) {
listOfBasket.add(item);
System.out.println("Added " + item.getName() + " to the basket. Price: " + item.getPrice());
if (item instanceof Bagel) {
Bagel bagel = (Bagel) item;
Filling filling = bagel.getFilling();
if (filling != null) {
System.out.println("Added filling: " + filling.getName() + " | Price: " + filling.getPrice());
}
}

} else {
System.out.println("Basket is full! Cannot add more items.");
}
} else {
System.out.println("Item with SKU " + item.getSku() + " is not available in the inventory.");
}
}



public String removeItem(Item item) {
if (listOfBasket.contains(item)) {
listOfBasket.remove(item);
return "The bagel was successfully removed";
} else {
return "The bagel does not exist in the basket";
}
}

public List<Item> getListOfBasket(){
return listOfBasket;

}

public double getTotalCost() {
double totalCost = 0;
for (Item item : listOfBasket) {
totalCost += item.getPrice();


if (item instanceof Bagel) {
Bagel bagel = (Bagel) item;
Filling filling = bagel.getFilling();
if (filling != null) {
totalCost += filling.getPrice();
}

}
}
System.out.println("Total cost calculated: " + totalCost);
return totalCost;
}

public void setCapacity(int capacity) {
this.capacity = capacity;
}

public int getCapacity() {
return capacity;
}
}




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

public class Coffee extends Item {
private String coffeeType;

public Coffee(String sku, double price, String name, String coffeeType) {
super(sku, price, name);
this.coffeeType = coffeeType;
}

public String getCoffeeType() {
return coffeeType;
}



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


public class Filling extends Item {
private String fillingType;

public Filling(String sku, double price, String name, String fillingType) {
super(sku, price, name);
this.fillingType = fillingType;
}

public String getFillingType() {
return fillingType;
}

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


import java.util.HashMap;
import java.util.Map;

public class Inventory {
private Map<String, Item> items;

public Inventory() {
items = new HashMap<>();
addItem(new Bagel("BGLO", 0.49, "Bagel", Bagel.BagelVariant.ONION));
addItem(new Bagel("BGLP", 0.39, "Bagel", Bagel.BagelVariant.PLAIN));
addItem(new Bagel("BGLE", 0.49, "Bagel", Bagel.BagelVariant.EVERYTHING));
addItem(new Bagel("BGLS", 0.49, "Bagel", Bagel.BagelVariant.SESAME));
addItem(new Coffee("COFB", 0.99, "Coffee", "Black"));
addItem(new Coffee("COFW", 1.19, "Coffee", "White"));
addItem(new Coffee("COFC", 1.29, "Coffee", "Capuccino"));
addItem(new Coffee("COFL", 1.29, "Coffee", "Latte"));
addItem(new Filling("FILB", 0.12, "Filling", "Bacon"));
addItem(new Filling("FILE", 0.12, "Filling", "Egg"));
addItem(new Filling("FILC", 0.12, "Filling", "Cheese"));
addItem(new Filling("FILX", 0.12, "Filling", "Cream Cheese"));
addItem(new Filling("FILS", 0.12, "Filling", "Smoked Salmon"));
addItem(new Filling("FILH", 0.12, "Filling", "Ham"));
}

private void addItem(Item item) {
items.put(item.getSku(), item);
}

public Item getItem(String sku) {
return items.get(sku);
}

public boolean isItemAvailable(String sku) {
return items.containsKey(sku);
}

}

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

public abstract class Item {
private String sku;
private double price;
private String name;

public Item(String sku, double price, String name) {
this.sku = sku;
this.price = price;
this.name = name;
}

public String getSku() {
return sku;
}



public double getPrice() {
return price;
}



public String getName() {
return name;
}


}


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

public class Main {
public static void main(String[] args) {
Basket basket = new Basket(10, new Inventory());
Bagel bagel1 = new Bagel("BGLO", 0.49, "Bagel", Bagel.BagelVariant.ONION);
basket.addItem(bagel1);
Bagel bagel2 = new Bagel("BGLO", 0.49, "Bagel", Bagel.BagelVariant.ONION);
basket.addItem(bagel2);
Filling baconFilling = new Filling("FILB", 0.12, "Filling", "Bacon");
bagel1.setFilling(baconFilling);

Coffee coffee = new Coffee("COFB",0.99,"Coffee","Black");
basket.addItem(coffee);


double result = basket.getTotalCost();
System.out.println(result);
}
}
Loading
Loading