Skip to content

Tuva Aarseth #53

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
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
14 changes: 14 additions & 0 deletions EXERCISE1.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,13 @@ Here is how one might design a domain model for the above user story:
>
> Create your own domain model for the user story above, try to come up with a different solution than the model provided. You can use a table like the one above, a spreadsheet, pen and paper, whatever you'd like. Share your work in your cohorts classroom channel when you're done.

| Classes | Member variables | Methods | Scenario | Outcomes |
|----------------|-----------------------------|-----------------------|--------------|------|
| `CohortManager` | `ArrayList<String> cohorts` | `search(String name)` | Name in list | True |
| | | | | |



### Exercise

Follow the same process as above to translate these two user stories into domain models.
Expand All @@ -37,6 +44,13 @@ So that I can pay for products at checkout,
I'd like to be able to know the total cost of items in my basket.
```

| Classes | Member variables | Methods | Scenario | Outcomes |
|---------------|------------------|---------|----------|----------|
| `Supermarket` | | | | |
| | | | | |
| | | | | |


```
As an organised individual,
So that I can evaluate my shopping habits,
Expand Down
11 changes: 11 additions & 0 deletions domain-model.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
| Classes | Member variables | Methods | Scenario | Outcomes |
|---------------|-------------------------------------------------|--------------------------------------------------------------------|----------------------------------|-------------------------------------------------------|
| `Supermarket` | `HashMap<String product, Integer price> products` | `calculateTotal(HashMap<String product, Integer quantity> basket)` | Empty basket<br/>Items in basket | Return "Basket is empty"<br/>Return total cost of items |





| Classes | Member variables | Methods | Scenario | Outcomes |
|-----------|----------------------------------------------------------------------------------------------------------|-------------------------------------------|-----------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------|
| `Receipt` | `HashMap<String product, Integer price> products`<br/>`HashMap<String product, Integer quantity> basket` | `calculateTotal()`<br/><br/>`itemizeReceipt()` | Empty basket<br/>Products in basket<br/>Payment not complete<br/>Payment complete | Return "Basket is empty"<br/>Return total cost of products<br/>Return "Payment is not complete"<br/>Return itemized receipt |
29 changes: 29 additions & 0 deletions src/main/java/com/booleanuk/core/Basket.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.booleanuk.core;

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

public class Basket {
HashMap<String, Integer> items = new HashMap<>();

public Boolean add(String product, int price){
if (!items.isEmpty() && items.containsKey(product)){
return false;
} else {
items.put(product, price);
return true;
}
}

public Integer total(){
int total = 0;
if (items.isEmpty()){
return 0;
}else {
for (Map.Entry<String, Integer> set : items.entrySet()){
total+=set.getValue();
}
}
return total;
}
}
6 changes: 6 additions & 0 deletions src/main/java/com/booleanuk/core/CohortManager.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
package com.booleanuk.core;

import java.util.ArrayList;

public class CohortManager {
public Boolean search(ArrayList<String> cohorts, String name){
return cohorts.contains(name);
}


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

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

import java.util.ArrayList;
import java.util.HashMap;

public class BasketTest {


@Test
public void testItemInBasket(){
Basket basket = new Basket();
Assertions.assertTrue(basket.add("new", 40));
Assertions.assertFalse(basket.add("new", 30));
}

@Test
public void testTotal(){
Basket basket = new Basket();
Assertions.assertEquals(0, basket.total());

basket.add("new", 30);
basket.add("new2", 30);
Assertions.assertEquals(60, basket.total());
}
}
34 changes: 34 additions & 0 deletions src/test/java/com/booleanuk/core/CohortManagerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,40 @@
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

import java.util.ArrayList;

class CohortManagerTest {
// One way of doing it
/*
CohortManager cohortManager;

public CohortManagerTest(){
this.cohortManager = new CohortManager();
}
*/

// Another way of doing it
ArrayList<String> cohorts;

public CohortManagerTest(){
this.cohorts = new ArrayList<>();
this.cohorts.add("Something");
this.cohorts.add("Some2");
}

@Test
public void testSearchExists(){
CohortManager cohortManager = new CohortManager();
Assertions.assertFalse(cohortManager.search(cohorts, ""));
}

@Test
public void testSearchFindName(){
CohortManager cohortManager = new CohortManager();
Assertions.assertTrue(cohortManager.search(cohorts, "Some2"));
Assertions.assertFalse(cohortManager.search(cohorts, "Some3"));
}



}