Finished the example.

This commit is contained in:
Ilkka Seppälä 2015-05-23 15:52:50 +03:00
parent 851fe4b3e0
commit 2eaf939691
4 changed files with 54 additions and 4 deletions

View File

@ -7,5 +7,8 @@ public class App {
stew.mix();
stew.taste();
stew.mix();
ImmutableStew immutableStew = new ImmutableStew(2, 4, 3, 6);
immutableStew.mix();
}
}

View File

@ -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()));
}
}

View File

@ -8,10 +8,10 @@ public class Stew {
private int numPeppers;
public Stew(int numPotatoes, int numCarrots, int numMeat, int numPeppers) {
this.numPotatoes = numPotatoes;
this.numCarrots = numCarrots;
this.numMeat = numMeat;
this.numPeppers = numPeppers;
this.numPotatoes = numPotatoes;
this.numCarrots = numCarrots;
this.numMeat = numMeat;
this.numPeppers = numPeppers;
}
public void mix() {

View 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;
}
}