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

Dag Andreas Foss Folvell #50

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
47 changes: 8 additions & 39 deletions src/main/java/com/booleanuk/core/Basket.java
Original file line number Diff line number Diff line change
@@ -1,62 +1,31 @@
package com.booleanuk.core;

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

public class Basket {
List<Game> games = new ArrayList<>();
List<Drink> drinks = new ArrayList<>();
List<Book> books = new ArrayList<>();
List<Item> items = new ArrayList<>();

public void add(Game game) {
this.games.add(game);
}

public void add(Drink drink) {
this.drinks.add(drink);
}

public void add(Book book) {
this.books.add(book);
public void add(Item item){
this.items.add(item);
}

public int getTotal() {
int total = 0;

for (Game game : this.games) {
total += game.getPrice();
for (Item item : this.items) {
total += item.getPrice();
}

for (Drink drink : this.drinks) {
total += drink.getPrice();
}

for (Book book : this.books) {
total += book.getPrice();
}

return total;
}

public boolean isInBasket(String name) {
for (Game game : this.games) {
if (game.getName().equals(name)) {
for (Item item: this.items) {
if (item.getName().equals(name)) {
return true;
}
}

for (Drink drink : this.drinks) {
if (drink.getName().equals(name)) {
return true;
}
}

for (Book book : this.books) {
if (book.getName().equals(name)) {
return true;
}
}

return false;
}
}
2 changes: 1 addition & 1 deletion src/main/java/com/booleanuk/core/Book.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.booleanuk.core;

public class Book {
public class Book implements Item {
String name;
int price;

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/booleanuk/core/Drink.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.booleanuk.core;

public class Drink {
public class Drink implements Item {
String name;
int price;

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/booleanuk/core/Game.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.booleanuk.core;

public class Game {
public class Game implements Item {
String name;
int price;

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

public interface Item {
int getPrice();
String getName();
}