Files
java-design-patterns/private-class-data/src/main/java/com/iluwatar/privateclassdata/Stew.java

44 lines
942 B
Java
Raw Normal View History

package com.iluwatar.privateclassdata;
2015-05-23 15:45:30 +03:00
2015-05-23 16:07:04 +03:00
/**
*
* Mutable stew class
*
*/
2015-05-23 15:45:30 +03:00
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--;
}
}
2015-05-23 15:45:30 +03:00
}