Untitled

 avatar
unknown
java
a year ago
784 B
6
Indexable
import java.util.HashMap;
import java.util.Scanner;

public class Shop {

    static HashMap<String,Item> items = new HashMap<>();

    public Shop(){
        items.put("car", new Item(6,7));
        items.put("pc", new Item(7, 8));

    }

    public void buy(String name, int amount, User buyer){
        if(items.containsKey(name)) {
            Item itemToBuy = items.get(name);
            int price = (itemToBuy.getPrice()) * (itemToBuy.getAmount());
            if (price <= buyer.getAmountOfMoney()) {
                buyer.pay(price);
            } else {
                System.out.println(" you can not buy this item! ");
            }
        } else {
            System.out.println("This item does not exist in the store");
        }
    }


}
Editor is loading...
Leave a Comment