Work on the example.
This commit is contained in:
parent
b7554249e6
commit
851fe4b3e0
@ -3,5 +3,9 @@ package com.iluwatar;
|
||||
public class App {
|
||||
|
||||
public static void main( String[] args ) {
|
||||
Stew stew = new Stew(1, 2, 3, 4);
|
||||
stew.mix();
|
||||
stew.taste();
|
||||
stew.mix();
|
||||
}
|
||||
}
|
||||
|
37
private-class-data/src/main/java/com/iluwatar/Stew.java
Normal file
37
private-class-data/src/main/java/com/iluwatar/Stew.java
Normal file
@ -0,0 +1,37 @@
|
||||
package com.iluwatar;
|
||||
|
||||
public class Stew {
|
||||
|
||||
private int numPotatoes;
|
||||
private int numCarrots;
|
||||
private int numMeat;
|
||||
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;
|
||||
}
|
||||
|
||||
public void mix() {
|
||||
System.out.println(String.format("Mixing the stew we find: %d potatoes, %d carrots, %d meat and %d peppers",
|
||||
numPotatoes, numCarrots, numMeat, numPeppers));
|
||||
}
|
||||
|
||||
public void taste() {
|
||||
System.out.println("Tasting the stew");
|
||||
if (numPotatoes > 0) {
|
||||
numPotatoes--;
|
||||
}
|
||||
if (numCarrots > 0) {
|
||||
numCarrots--;
|
||||
}
|
||||
if (numMeat > 0) {
|
||||
numMeat--;
|
||||
}
|
||||
if (numPeppers > 0) {
|
||||
numPeppers--;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user