Skip to content

Commit 2eaf939

Browse files
committed
Finished the example.
1 parent 851fe4b commit 2eaf939

File tree

4 files changed

+54
-4
lines changed

4 files changed

+54
-4
lines changed

private-class-data/src/main/java/com/iluwatar/App.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,8 @@ public static void main( String[] args ) {
77
stew.mix();
88
stew.taste();
99
stew.mix();
10+
11+
ImmutableStew immutableStew = new ImmutableStew(2, 4, 3, 6);
12+
immutableStew.mix();
1013
}
1114
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package com.iluwatar;
2+
3+
public class ImmutableStew {
4+
5+
private StewData data;
6+
7+
public ImmutableStew(int numPotatoes, int numCarrots, int numMeat, int numPeppers) {
8+
data = new StewData(numPotatoes, numCarrots, numMeat, numPeppers);
9+
}
10+
11+
public void mix() {
12+
System.out.println(String.format("Mixing the immutable stew we find: %d potatoes, %d carrots, %d meat and %d peppers",
13+
data.getNumPotatoes(), data.getNumCarrots(), data.getNumMeat(), data.getNumPeppers()));
14+
}
15+
}

private-class-data/src/main/java/com/iluwatar/Stew.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ public class Stew {
88
private int numPeppers;
99

1010
public Stew(int numPotatoes, int numCarrots, int numMeat, int numPeppers) {
11-
this.numPotatoes = numPotatoes;
12-
this.numCarrots = numCarrots;
13-
this.numMeat = numMeat;
14-
this.numPeppers = numPeppers;
11+
this.numPotatoes = numPotatoes;
12+
this.numCarrots = numCarrots;
13+
this.numMeat = numMeat;
14+
this.numPeppers = numPeppers;
1515
}
1616

1717
public void mix() {
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package com.iluwatar;
2+
3+
public class StewData {
4+
5+
private int numPotatoes;
6+
private int numCarrots;
7+
private int numMeat;
8+
private int numPeppers;
9+
10+
public StewData(int numPotatoes, int numCarrots, int numMeat, int numPeppers) {
11+
this.numPotatoes = numPotatoes;
12+
this.numCarrots = numCarrots;
13+
this.numMeat = numMeat;
14+
this.numPeppers = numPeppers;
15+
}
16+
17+
public int getNumPotatoes() {
18+
return numPotatoes;
19+
}
20+
21+
public int getNumCarrots() {
22+
return numCarrots;
23+
}
24+
25+
public int getNumMeat() {
26+
return numMeat;
27+
}
28+
29+
public int getNumPeppers() {
30+
return numPeppers;
31+
}
32+
}

0 commit comments

Comments
 (0)