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
39 changes: 39 additions & 0 deletions domain-model.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Domain model Bobs Bagels

### class Basket
```
1.
As a member of the public,
So I can order a bagel before work,
I'd like to add a specific type of bagel to my basket.
```
```
2.
As a member of the public,
So I can change my order,
I'd like to remove a bagel from my basket.
```
```
3.
As a member of the public,
So that I can not overfill my small bagel basket
I'd like to know when my basket is full when I try adding an item beyond my basket capacity.
```
```
4.
As a Bob's Bagels manager,
So that I can expand my business,
I’d like to change the capacity of baskets.
```
```
5.
As a member of the public
So that I can maintain my sanity
I'd like to know if I try to remove an item that doesn't exist in my basket.
```

| Variables | Methods | Scenario | Output |
|--------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------|
| `HashMap<String, Double\> Basket` <br> `HashMap<String, Double\> Bagel` | `add(String bagelType, double price)`<br> `remove(String bagelType)` <br>`exists(String bagelType)` | if there is capacity, adds bagel to basket, else basket is full<br> remove bagel only, if bagel exists in basket <br> | "Added <bagel\> to basket."<br> "Basket is full."<br> "<bagel\> is not in basket, can't remove. "<br> Removed <bagel\> <br> from basket." |
| `HashMap<Integer, Boolean\> basketCapacity` | `changeCap(int cap)` <br> `isManager(int passWord)` | if managercode is correct, change capacity. <br> | "Password correct, capacity is updated!" <br> "Password inccorect, capacity is not updated!" |

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

import java.util.HashMap;
import java.util.Map;
import java.util.function.BooleanSupplier;

public class Basket {
private Map<String, Double> items;
private int capacity;
private int managerCode = 1234;

public Basket() {
this.items = new HashMap<>();
this.capacity = 6;
}

public void add(String bagel, double price) {
if (!isFull());
{
items.put(bagel, price);
System.out.println("Added " + bagel +" to basket");
}
System.out.println("Basket is full.");
}
public boolean isFull() {
return items.size() >= capacity;
}

public boolean isNotEmpty(String bagel){
if (items.containsKey(bagel)) {
return true;
} else {
return false;
}
}
public void remove(String bagel) {
if (items.containsKey(bagel)) {
items.remove(bagel);
System.out.println("Removed " + bagel + " from basket.");
} System.out.println(bagel + " not in basket.");
}

public Map<String, Double> getItems() {
return items;
}

public boolean isManager(int password) {
return password == managerCode;
}

public int changeCap(int newCapacity, int password) {
if (isManager(password)) {
this.capacity = newCapacity;
System.out.println("Password correct, capacity is updated!");
return newCapacity;
} else {
System.out.println("Password incorrect, capacity is not updated!");
return this.capacity; // Return the current capacity if the password is incorrect
}
}

public int getCapacity() {
return capacity;
}
}

79 changes: 79 additions & 0 deletions src/test/java/com/booleanuk/core/BasketTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,84 @@
import org.junit.jupiter.api.Test;

class BasketTest {
@Test
public void addBagelToBasket() {
Basket basket = new Basket();
String sesame = "Sesame Bagel";
double price = 4.50;
basket.add(sesame, price);

Assertions.assertFalse(basket.isFull());
Assertions.assertEquals(basket.getItems().get(sesame), price);
}
@Test
public void checkIfBasketIsFull(){
Basket basket = new Basket();
String sesame = "Sesame Bagel";
double price1 = 4.50;
String redvelvet = "Everything Bagel";
double price2 = 5.50;
String jalapenoCheese = "jalapenoCheese Bagel";
double price3 = 5.50;
String cinnamon = "Cinnamon Bagel";
double price4 = 4.50;
String flaxseed = "Flaxseed Bagel";
double price5 = 3.50;
String oats = "Oat Bagel";
double price6 = 5.50;
String whole = "WholeGrain Bagel";
double price7 = 6.50;

basket.add(sesame, price1);
basket.add(redvelvet, price2);
basket.add(jalapenoCheese, price3);
basket.add(cinnamon, price4);
basket.add(flaxseed, price5);
basket.add(oats, price6);
basket.add(whole, price7);

Assertions.assertTrue(basket.isFull());
}
@Test
public void removeBagelFromBasket(){
Basket basket = new Basket();
String sesame = "Sesame Bagel";
double price = 4.50;

basket.add(sesame, price);
Assertions.assertTrue(basket.isNotEmpty(sesame));
basket.remove(sesame);
Assertions.assertFalse(basket.isNotEmpty(sesame));
}
@Test
public void existsBagelInCart(){
Basket basket = new Basket();
String sesame = "Sesame Bagel";
double price1 = 4.50;
String jalapenoCheese = "Jalapeno Cheese Bagel";
double price2 = 5.50;

basket.add(sesame, price1);
Assertions.assertTrue(basket.isNotEmpty(sesame));
Assertions.assertFalse(basket.isNotEmpty(jalapenoCheese));


}
@Test
public void isAuthorizedToChangeCap(){
Basket basket = new Basket();
int managerCode = 1234;

Assertions.assertTrue(basket.isManager(managerCode));
}

@Test
public void capacityIsChanged(){
Basket basket = new Basket();
int newCapacity = 10;
int managerCode = 1234;
basket.changeCap(newCapacity, managerCode);

Assertions.assertEquals(newCapacity, basket.getCapacity());
}
}