Hi,
I need some help with a school project. This is what I have done so far:
(Sorry about the wall of code)

public abstract class State {

    private double drinkPrice;
    private double amountPutIn;
    private String selection;


    public State() {
    }

    public State(double drinkPrice, double amountPutIn, String selection) {
        this.drinkPrice = drinkPrice;
        this.amountPutIn = amountPutIn;
        this.selection = selection;
    }

    public double getDrinkPrice(){
        return drinkPrice;
    }
    
    public void setDrinkPrice(double drinkPrice){
        this.drinkPrice = drinkPrice;
    }

    public double getAmountPutIn() {
        return amountPutIn;
    }

    public void setAmountPutIn(double amountPutIn) {
        this.amountPutIn = amountPutIn;
    }

    public String getSelection(){
        return selection;
    }

    public void setSelection(String selection){
        this.selection = selection;
    }

    public abstract void makeSelection(String selection, CoffeeMachine coffeemachine);
}

This State class is fine I think for the moment.

public class SelectDrink extends State {

    @Override
    public void makeSelection(String selection, CoffeeMachine coffeemachine) {
        if (selection.equals(CoffeeMachine.COFFEE)){
            selection = super.setSelection();
        } else if (selection.equals(CoffeeMachine.CHOCOLATE)){
            selection = super.setSelection();
        } else {
            selection = super.setSelection();
        }
    }
}

I need help figuring out what to put inside the parentheses in super.setSelection();

public class CoffeeMachine {

    public static final String COFFEE = "Coffee";
    public static final String CHOCOLATE = "Chocolate";
    public static final String TEA = "Tea";
    
    HashMap<String, Integer> drinkPrice = new HashMap<String, Integer>();

    public CoffeeMachine() {
        drinkPrice.put(COFFEE, 20);
        drinkPrice.put(CHOCOLATE, 15);
        drinkPrice.put(TEA, 10);
    }

    public int getPrice(String selection) {
        return drinkPrice.get();
    }
}

And here I need help with the getPrice method. I need to get the value from the HashMap for any of the three coffee, chocolate and tea.

I attached the handed out description of the project. The state diagram and the State Transition and Action table I made myself.

I would greatly appreciate any help or pointers in the right direction.

Anyone? I'm really stuck :S

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.