public boolean addInventory(int amtCoffee, int amtMilk, int amtSugar, int amtChocolate) {
boolean canAddInventory = true;
if(amtCoffee < 0 amtMilk < 0 amtSugar > 0 amtChocolate < 0) {
canAddInventory = false;
}
else {
inventory.setCoffee(inventory.getCoffee() + amtCoffee);
inventory.setMilk(inventory.getMilk() + amtMilk);
inventory.setSugar(inventory.getSugar() + amtSugar);
inventory.setChocolate(inventory.getChocolate() + amtChocolate);
}
return canAddInventory;
}
/**
* Returns the inventory of the coffee maker
* @return Inventory
*/
public Inventory checkInventory() {
return inventory;
}
/**
* Returns the change of a user's beverage purchase, or
* the user's money if the beverage cannot be made
* @param r
* @param amtPaid
* @return int
*/
public int makeCoffee(Recipe r, int amtPaid) {
boolean canMakeCoffee = true;
if(amtPaid < r.getPrice()) {
canMakeCoffee = false;
}
if(!inventory.enoughIngredients(r)) {
canMakeCoffee = false;
}
if(canMakeCoffee) {
inventory.setCoffee(inventory.getCoffee() + r.getAmtCoffee());
inventory.setMilk(inventory.getMilk() - r.getAmtMilk());
inventory.setSugar(inventory.getSugar() - r.getAmtSugar());
inventory.setChocolate(inventory.getChocolate() - r.getAmtChocolate());
return amtPaid - r.getPrice();
}
else {
return amtPaid;
}
}
/**
* Returns an array of all the recipes
* @return Recipe[]
*/
public Recipe[] getRecipes() {
return recipeArray;
}
/**
* Returns the Recipe associated with the given name
* @param name
* @return Recipe
*/
public Recipe getRecipeForName(String name) {
Recipe r = null;
for(int i = 0; i < NUM_RECIPES; i++) {
if(recipeArray[i].getName() != null) {
if((recipeArray[i].getName()).equals(name)) {
r = recipeArray[i];
}
}
}
return r;
}
public boolean[] getRecipeFull() {
return recipeFull;
}
}
运行结果如表2所示:
表2
fit.ActionFixture
start Cstc.fitexam.coffeemaker.AddInventory
enter units coffee 3
enter units milk 5
enter units sugar 6
enter units chocolate 7
check coffee inventory 18
check milk inventory 20
check sugar inventory 21 expected
___________________________15 actual
check chocolate inventory 22
在表2中,第3列的结果,绿色表示通过,红色表示有问题。“21 expected” 表明预期的结果应该是21,而实际结果是15。
总结
FIT给予了客户和程序员一个关于软件的精确交流的方法。
客户所给的具体的例子让程序员能深刻理解将要构建的产品。程序员的对于装置的工作和软件可以让客户给出不同的例子进行试验来获取对于软件如何真正工作更深入的了解。这样通过一起工作,整个团队可以学会更多关于产品的内容并产生更好的结果。
责任编辑:小草