117
2016-06-07 18:15:14
14
public class Shop () {
public main () throws Exception () {
Location emart = Market.getEmartInstance();
Car car = Motor.getInstance(Car.class);
car.setDestination(emart);
while (!car.isArrived()) {
car.drive();
}
Cart cart = car.getCart(1);
Location milkLocation = emart.locateMilk();
int milkCount = this.getMilkCount(emart);
Item milks = emart.getItem(Milk.class, milkCount);
cart.addItem(Milks);
emart.purchase(cart);
car.pushCart(cart);
Location home = Location.getHomeInstance();
car.setDestination(home);
while (!car.isArrived()) {
car.drive();
}
}
private int getMilkCount (Market market) {
if (market.hasItem(Egg.class)) {
return 6;
} else {
return 1;
}
}
}