Finished the example.
This commit is contained in:
parent
851fe4b3e0
commit
2eaf939691
@ -7,5 +7,8 @@ public class App {
|
|||||||
stew.mix();
|
stew.mix();
|
||||||
stew.taste();
|
stew.taste();
|
||||||
stew.mix();
|
stew.mix();
|
||||||
|
|
||||||
|
ImmutableStew immutableStew = new ImmutableStew(2, 4, 3, 6);
|
||||||
|
immutableStew.mix();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,15 @@
|
|||||||
|
package com.iluwatar;
|
||||||
|
|
||||||
|
public class ImmutableStew {
|
||||||
|
|
||||||
|
private StewData data;
|
||||||
|
|
||||||
|
public ImmutableStew(int numPotatoes, int numCarrots, int numMeat, int numPeppers) {
|
||||||
|
data = new StewData(numPotatoes, numCarrots, numMeat, numPeppers);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void mix() {
|
||||||
|
System.out.println(String.format("Mixing the immutable stew we find: %d potatoes, %d carrots, %d meat and %d peppers",
|
||||||
|
data.getNumPotatoes(), data.getNumCarrots(), data.getNumMeat(), data.getNumPeppers()));
|
||||||
|
}
|
||||||
|
}
|
@ -8,10 +8,10 @@ public class Stew {
|
|||||||
private int numPeppers;
|
private int numPeppers;
|
||||||
|
|
||||||
public Stew(int numPotatoes, int numCarrots, int numMeat, int numPeppers) {
|
public Stew(int numPotatoes, int numCarrots, int numMeat, int numPeppers) {
|
||||||
this.numPotatoes = numPotatoes;
|
this.numPotatoes = numPotatoes;
|
||||||
this.numCarrots = numCarrots;
|
this.numCarrots = numCarrots;
|
||||||
this.numMeat = numMeat;
|
this.numMeat = numMeat;
|
||||||
this.numPeppers = numPeppers;
|
this.numPeppers = numPeppers;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void mix() {
|
public void mix() {
|
||||||
|
32
private-class-data/src/main/java/com/iluwatar/StewData.java
Normal file
32
private-class-data/src/main/java/com/iluwatar/StewData.java
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
package com.iluwatar;
|
||||||
|
|
||||||
|
public class StewData {
|
||||||
|
|
||||||
|
private int numPotatoes;
|
||||||
|
private int numCarrots;
|
||||||
|
private int numMeat;
|
||||||
|
private int numPeppers;
|
||||||
|
|
||||||
|
public StewData(int numPotatoes, int numCarrots, int numMeat, int numPeppers) {
|
||||||
|
this.numPotatoes = numPotatoes;
|
||||||
|
this.numCarrots = numCarrots;
|
||||||
|
this.numMeat = numMeat;
|
||||||
|
this.numPeppers = numPeppers;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getNumPotatoes() {
|
||||||
|
return numPotatoes;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getNumCarrots() {
|
||||||
|
return numCarrots;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getNumMeat() {
|
||||||
|
return numMeat;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getNumPeppers() {
|
||||||
|
return numPeppers;
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user