Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 44eca07

Browse files
committed
first commit with gradle, working on getting it to compile for some reason doesn't know overrides
1 parent 7b5b4cf commit 44eca07

File tree

11 files changed

+486
-0
lines changed

11 files changed

+486
-0
lines changed

build.gradle

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
apply plugin: 'java'
2+
apply plugin: 'eclipse'
3+
4+
sourceCompatibility = 1.5
5+
version = '1.0'
6+
jar {
7+
manifest {
8+
attributes 'Implementation-Title': 'Spring Vending Machine kata', 'Implementation-Version': version
9+
}
10+
}
11+
12+
repositories {
13+
mavenCentral()
14+
}
15+
16+
dependencies {
17+
compile group: 'commons-collections', name: 'commons-collections', version: '3.2'
18+
compile 'org.springframework:spring-core:4.0.4.RELEASE'
19+
testCompile group: 'junit', name: 'junit', version: '4.+'
20+
}
21+
22+
test {
23+
systemProperties 'property': 'value'
24+
}
25+
26+
uploadArchives {
27+
repositories {
28+
flatDir {
29+
dirs 'repos'
30+
}
31+
}
32+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package halterman.spring.vending;
2+
3+
import java.util.ArrayList;
4+
5+
public class Candy implements VendItem {
6+
7+
@Override
8+
public ArrayList<String> vend(ArrayList<String> itemBinList, double currentAmount) {
9+
10+
if (currentAmount >= 0.50) {
11+
itemBinList.add("Candy");
12+
}
13+
14+
return itemBinList;
15+
}
16+
17+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package halterman.spring.vending;
2+
3+
import java.util.ArrayList;
4+
5+
public class Chips implements VendItem {
6+
7+
@Override
8+
public ArrayList<String> vend(ArrayList<String> itemBinList, double currentAmount) {
9+
10+
if (currentAmount >= 0.75) {
11+
itemBinList.add("Chips");
12+
}
13+
14+
return itemBinList;
15+
}
16+
17+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package halterman.spring.vending;
2+
3+
public class CoinCalculator implements VendingCalc {
4+
private double totalAmount;
5+
6+
@Override
7+
public void insertCoin(double coinAmount) {
8+
if (coinAmount != 0.01)
9+
totalAmount += coinAmount;
10+
}
11+
12+
@Override
13+
public double calcTotalAmount() {
14+
return totalAmount;
15+
}
16+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package halterman.spring.vending;
2+
3+
import java.util.ArrayList;
4+
5+
public class Soda implements VendItem {
6+
7+
@Override
8+
public ArrayList<String> vend(ArrayList<String> itemBinList, double currentAmount) {
9+
10+
if (currentAmount >= 1.25) {
11+
itemBinList.add("Soda");
12+
}
13+
14+
return itemBinList;
15+
}
16+
17+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package halterman.spring.vending;
2+
3+
import java.util.ArrayList;
4+
5+
public interface VendItem {
6+
7+
public ArrayList<String> vend(ArrayList<String> itemBinList, double currentAmount);
8+
9+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package halterman.spring.vending;
2+
3+
public interface VendingCalc {
4+
public void insertCoin(double coinAmount);
5+
6+
public double calcTotalAmount();
7+
}
Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
package halterman.spring.vending;
2+
3+
import java.text.NumberFormat;
4+
import java.util.ArrayList;
5+
6+
public class VendingMachine {
7+
8+
private Double currentAmount = 0.0;
9+
private Double coinReturnAmount = 0.0;
10+
private ArrayList<String> returnSlotCoins = new ArrayList<String>();
11+
private String display = "";
12+
private ArrayList<String> itemBinList = new ArrayList<String>();
13+
private ArrayList<String> coinList = new ArrayList<String>();
14+
private VendingCalc coinCalc;
15+
private VendItem soda;
16+
private VendItem chips;
17+
private VendItem candy;
18+
19+
public VendingMachine() {
20+
coinCalc = new CoinCalculator();
21+
soda = new Soda();
22+
chips = new Chips();
23+
candy = new Candy();
24+
}
25+
26+
public void update() {
27+
setCurrentAmount(coinCalc.calcTotalAmount());
28+
updateDisplay();
29+
}
30+
31+
public ArrayList<String> returnCoins() {
32+
setCoinReturnAmount(currentAmount);
33+
returnSlotCoins.addAll(coinList);
34+
coinList.removeAll(coinList);
35+
setCurrentAmount(0.00);
36+
updateDisplay();
37+
38+
return returnSlotCoins;
39+
}
40+
41+
public void insertCoin(String coin, double coinAmount) {
42+
if (coinIsPenny(coin)) {
43+
pennyFallsToReturnSlot(coin, coinAmount);
44+
} else {
45+
coinAdded(coin, coinAmount);
46+
}
47+
}
48+
49+
public void sodaButton() {
50+
itemBinList = soda.vend(itemBinList, currentAmount);
51+
updateChangeAmount();
52+
}
53+
54+
public void chipsButton() {
55+
itemBinList = chips.vend(itemBinList, currentAmount);
56+
updateChangeAmount();
57+
}
58+
59+
public void candyButton() {
60+
itemBinList = candy.vend(itemBinList, currentAmount);
61+
updateChangeAmount();
62+
}
63+
64+
public Double getCoinReturnAmount() {
65+
return coinReturnAmount;
66+
}
67+
68+
public ArrayList<String> getReturnSlotCoins() {
69+
return returnSlotCoins;
70+
}
71+
72+
public String display() {
73+
return display;
74+
}
75+
76+
public ArrayList<String> getItemBinList() {
77+
return itemBinList;
78+
}
79+
80+
private void setDisplay(String display) {
81+
this.display = display;
82+
}
83+
84+
private void setCurrentAmount(Double currentAmount) {
85+
this.currentAmount = currentAmount;
86+
}
87+
88+
private void updateDisplay() {
89+
NumberFormat nf = NumberFormat.getInstance();
90+
nf.setMinimumFractionDigits(2);
91+
String stringConversion = nf.format(currentAmount);
92+
setDisplay("$" + stringConversion);
93+
}
94+
95+
private void updateChangeAmount() {
96+
if (currentAmount >= 1.25) {
97+
setCurrentAmount(currentAmount - 1.25);
98+
}
99+
}
100+
101+
private void setCoinReturnAmount(Double coinReturnAmount) {
102+
this.coinReturnAmount = coinReturnAmount;
103+
}
104+
105+
private void coinAdded(String coin, double coinAmount) {
106+
coinList.add(coin);
107+
coinCalc.insertCoin(coinAmount);
108+
}
109+
110+
private void pennyFallsToReturnSlot(String coin, double coinAmount) {
111+
returnSlotCoins.add(coin);
112+
setCoinReturnAmount(coinAmount);
113+
}
114+
115+
private boolean coinIsPenny(String coin) {
116+
return coin.equals("Penny");
117+
}
118+
119+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<some-element/>

0 commit comments

Comments
 (0)