// This class uses simple variables to represent the frequency counts. // Barry Cornelius, 19 June 2000 import java.io. BufferedReader; import java.io. IOException; public class VendingMachine { private BufferedReader iKeyboard; private int iBlackWithout; private int iBlackWith; private int iWhiteWithout; private int iWhiteWith; public VendingMachine(final BufferedReader pKeyboard) { iKeyboard = pKeyboard; } public void setFrequencyCountsToZero() { iBlackWithout = 0; iBlackWith = 0; iWhiteWithout = 0; iWhiteWith = 0; } //BJCHEREFIRST public void readInSelectionsAndUpdateFrequencyCounts() throws IOException { while (true) { final String tLine = iKeyboard.readLine(); if (tLine.equals("")) { break; } final int tDrinkSelection = Integer.parseInt(tLine); switch (tDrinkSelection) { case 1: { iBlackWithout += 1; } break; case 2: { iBlackWith += 1; } break; case 3: { iWhiteWithout += 1; } break; case 4: { iWhiteWith += 1; } break; default: { System.out.println("The value is out of range"); System.exit(1); } } } } //BJCHERECONT public void outputFrequencyCounts() { System.out.println("Black (no sugar): " + iBlackWithout); System.out.println("Black with sugar: " + iBlackWith); System.out.println("White (no sugar): " + iWhiteWithout); System.out.println("White with sugar: " + iWhiteWith); } }