Skip to content

Commit

Permalink
Setup drinkautomat.
Browse files Browse the repository at this point in the history
  • Loading branch information
Dougnkong committed Dec 17, 2020
1 parent 287b3c3 commit cf8526e
Show file tree
Hide file tree
Showing 27 changed files with 367 additions and 262 deletions.
11 changes: 11 additions & 0 deletions README.mkd
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@

# Drink automat

***In this project some basic functionalities (changing coins, filling in coins, filling out coins and delivering an order and change) of a drink machine are implemented.***

## Requirements
All tools with which you can execute Java code.

## How to test the Project
The entire tests can be found in the class testDrinkAutomat in folder ../drinkAutomat/src/drinkAutomatTest/testDrinkAutomat.java.
When you run this class, all tests are run automatically. Explanations for each test can be found in the test itself.
Binary file modified out/production/drinkAutomat/drinkAutomat/common/Automat.class
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified out/production/drinkAutomat/drinkAutomat/model/DrinkAutomat.class
Binary file not shown.
Binary file not shown.
Binary file modified out/production/drinkAutomat/drinkAutomatTest/testAutomate.class
Binary file not shown.
Binary file not shown.
13 changes: 0 additions & 13 deletions readme.txt

This file was deleted.

9 changes: 7 additions & 2 deletions src/drinkAutomat/common/Automat.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
package drinkAutomat.common;

import drinkAutomat.model.Coin;
import drinkAutomat.model.CoinAndQuantity;

import java.util.List;

public abstract class Automat {
///TODO

protected abstract void fillInWithCoin(List<Coin> coins);
//protected abstract void fillIntWithDrink();

/**
* TODO
* Implement: protected abstract void fillIntWithDrink();
*/
protected abstract void fillOut(List<CoinAndQuantity> restCoinToGiveBack);

protected abstract List<CoinAndQuantity> changeCoin(int sum);
}
20 changes: 0 additions & 20 deletions src/drinkAutomat/common/Coin.java

This file was deleted.

23 changes: 23 additions & 0 deletions src/drinkAutomat/common/CoinValue.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package drinkAutomat.common;

/**
* The coin is initialised in cents.
*/
public enum CoinValue {
ONE_EURO(100),
TWO_EURO(200),
FIFTY_CENT(50),
TEN_CENT(10),
TWENTY_CENT(20);

private final int coinValue;

CoinValue(int value) {
this.coinValue = value;
}

public int getValue() {
return this.coinValue;
}

}
22 changes: 0 additions & 22 deletions src/drinkAutomat/common/ErrorMessage.java

This file was deleted.

4 changes: 4 additions & 0 deletions src/drinkAutomat/common/ProductType.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ public abstract class ProductType {
protected String name;
protected double price;

/**
* @param name general name for drink product.
* @param price general price of drink.
*/
public ProductType(String name, double price) {
this.name = name;
this.price = price;
Expand Down
23 changes: 23 additions & 0 deletions src/drinkAutomat/model/Coin.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package drinkAutomat.model;

import drinkAutomat.common.CoinValue;

public class Coin {

CoinValue coinValue;

/**
* @param coinValue represents the real coin value.
*/
public Coin(CoinValue coinValue) {
this.coinValue = coinValue;
}

public CoinValue getCoinValue() {
return coinValue;
}

public void setCoinValue(CoinValue coinValue) {
this.coinValue = coinValue;
}
}
17 changes: 12 additions & 5 deletions src/drinkAutomat/model/CoinAndQuantity.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
package drinkAutomat.model;

import drinkAutomat.common.Coin;
import drinkAutomat.common.CoinValue;

/**
* This class is used to store change coins.
*/
public class CoinAndQuantity implements Comparable<CoinAndQuantity> {

protected Coin type;
protected CoinValue type;
protected int quantity;

public CoinAndQuantity(Coin coin, int quantity) {
/**
* @param coin
* @param quantity gives the number of coins for type coin
*/
public CoinAndQuantity(CoinValue coin, int quantity) {

this.type = coin;
this.quantity = quantity;
Expand All @@ -25,7 +32,7 @@ public void reduceCoinNumber(int quantity) {
this.quantity -= quantity;
}

public Coin getType() {
public CoinValue getType() {
return type;
}

Expand All @@ -34,6 +41,6 @@ public int compareTo(CoinAndQuantity o) {

CoinAndQuantity f = (CoinAndQuantity) o;

return this.type.getCoinType() - f.type.getCoinType();
return this.type.getValue() - f.type.getValue();
}
}
5 changes: 5 additions & 0 deletions src/drinkAutomat/model/Compartment.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

import drinkAutomat.common.ProductType;

/**
* Generic class for compartment in the drink machine.
* Each compartment will take the name of specific drink.
* @param <T>
*/
public class Compartment<T extends ProductType> {

private T common;
Expand Down
18 changes: 12 additions & 6 deletions src/drinkAutomat/model/DrinkAndChange.java
Original file line number Diff line number Diff line change
@@ -1,20 +1,26 @@
package drinkAutomat.model;

import drinkAutomat.common.Coin;
import drinkAutomat.common.CoinValue;
import drinkAutomat.common.Drink;

import java.util.HashMap;
import java.util.List;


/**
* This is used to return the drink and the change for the user.
*/
public class DrinkAndChange {

HashMap<Coin, Integer> change;
HashMap<CoinValue, Integer> change;
Drink drink;

/**
* @param drink ordered.
* @param changes rest after buying.
*/
public DrinkAndChange(Drink drink, List<CoinAndQuantity> changes) {
this.drink = drink;
this.change = new HashMap<Coin, Integer>();
this.change = new HashMap<CoinValue, Integer>();

for (CoinAndQuantity change : changes) {

Expand All @@ -27,11 +33,11 @@ public String getDrinkName() {
return drink.getName();
}

public HashMap<Coin, Integer> getChange() {
public HashMap<CoinValue, Integer> getChange() {
return change;
}

public void setChange(HashMap<Coin, Integer> change) {
public void setChange(HashMap<CoinValue, Integer> change) {
this.change = change;
}
}
Loading

0 comments on commit cf8526e

Please sign in to comment.