Skip to content

Ilias Kalamatas #46

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 2 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
26 changes: 26 additions & 0 deletions Example.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Example Domain Model

## User Stories

```
As a user,
So I can find a specific cohort,
I want to search a list of all cohorts by cohort name.
```

## Domain Model

| Classes | Methods | Scenario | Outputs |
|---------------|------------------------------------------------------|------------------------|---------|
| CohortManager | search(ArrayList<String> cohorts, String cohortName) | If name is in list | true |
| | | If name is not in list | false |


### CohortManager Class

| Methods | Member Variables | Scenario | Outputs |
|---------------------------|---------------------------|------------------------|---------|
| search(String cohortName) | ArrayList<String> cohorts | If name is in list | True |
| | | If name is not in list | False |


29 changes: 29 additions & 0 deletions domain-model.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Exercise 1
Translate the two following user stories into domain models.

## User Story 1
```
As a supermarket shopper,
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.
```

### Domain Model Suggestion

| Class | Method | Class Member | Result |
|---------|--------------------------------------------------|----------------------------------------|------------------|
| Basket | calculateCost(HashMap<String,Integer> priceList) | HashMap<String,Integer> itemQuantities | Total Cost (int) |

## User Story 2
```
As an organised individual,
So that I can evaluate my shopping habits,
I'd like to see an itemised receipt that includes the name and price of the products
I bought as well as the quantity, and a total cost of my basket.
```

### Domain Model Suggestion

| Class | Method | Class Member | Result |
|--------|---------------------------------------------------|----------------------------------------|----------------------------------------------------------------------------------------------------------------------|
| Basket | exportAnalysis(HashMap<String,Integer> priceList) | HashMap<String,Integer> itemQuantities | Itemised Receipt (HashMap<String,int[]> where the int array contains one value for quantity and one value for price) |
26 changes: 26 additions & 0 deletions src/main/java/com/booleanuk/core/Basket.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.booleanuk.core;

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

public class Basket {
HashMap<String,Integer> items;

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

public boolean add (String product, int price){
boolean flag = this.items.containsKey(product);
this.items.put(product,price);
return flag;
}

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

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

public class CohortManager {
List<String> cohorts;

public CohortManager() {
this.cohorts = new ArrayList<>();
this.cohorts.add("Experis C# 1");
this.cohorts.add("Experis C# 2");
this.cohorts.add("Experis Java 1");
this.cohorts.add("Experis Java 2");
}

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

public class Speaker {
public String sayHello(String name){
return "Hello, " + name + "!";
}
}
30 changes: 30 additions & 0 deletions src/test/java/com/booleanuk/core/BasketTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.booleanuk.core;

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

public class BasketTest {
@Test
public void shouldReturnFalse(){
Basket cart = new Basket();
Assertions.assertFalse(cart.add("tomato", 1));
}

@Test
public void shouldReturnTrue(){
Basket cart = new Basket();
cart.add("tomato", 1);
Assertions.assertTrue(cart.add("tomato",2));
}

@Test
public void shouldCalculateCorrectTotal(){
Basket cart = new Basket();
cart.add("tomato", 1);
cart.add("potato", 2);
cart.add("apple", 1);
cart.add("watermelon", 3);
cart.add("bananas", 2);
Assertions.assertEquals(9, cart.total());
}
}
7 changes: 7 additions & 0 deletions src/test/java/com/booleanuk/core/CohortManagerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,12 @@
import org.junit.jupiter.api.Test;

class CohortManagerTest {
@Test
public void searchWorksCorrectly() {
CohortManager cohortManager = new CohortManager();

Assertions.assertTrue(cohortManager.search("Experis Java 2"));
Assertions.assertFalse(cohortManager.search(""));
Assertions.assertFalse(cohortManager.search("Cohort 11"));
}
}
18 changes: 18 additions & 0 deletions src/test/java/com/booleanuk/core/SpeakerTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.booleanuk.core;

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

public class SpeakerTest {

@Test
public void shouldSayHelloCorrectly(){
Speaker speaker = new Speaker();

String name = "Dave";
String message = speaker.sayHello(name);
Assertions.assertEquals("Hello, Dave!", message);

Assertions.assertEquals("Hello, Nathan!", speaker.sayHello("Nathan"));
}
}