import java.io.*; class UseDrinksMachine7f { // Shows use of instanceof public static void main(String[] args) throws NumberFormatException, IOException { DrinksMachine machine1 = new DrinksMachineA(25); DrinksMachine machine2 = new DrinksMachineB(80); DrinksMachine cheaper; BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); int amount; String reply; System.out.print("How much do you want to put in a machine? "); amount = Integer.parseInt(in.readLine()); cheaper = DrinksMachineFuncs.cheapestMachine(machine1,machine2); cheaper.addMoney(amount); System.out.print("When you press the coke button on the cheaper machine "); System.out.println("you get: "+cheaper.pressCoke()); if(cheaper instanceof DrinksMachineB) { System.out.print("And when you press the change button on it you get: "); reply=((DrinksMachineB) cheaper).pressChange(); System.out.println(reply); } else System.out.println("There is no change button on this machine"); } }