import java.util.Scanner; import java.util.Iterator; /* This is a Java application (i.e., a class with a main() method) that ** uses an instance of the Taxman class to play a game of that name using ** console input/output. ** ** @author R. McCloskey ** @version December 2022 */ public class PlayTaxman { public static void main(String[] args) { Taxman taxman; Scanner s = new Scanner(System.in); System.out.println("Welcome to the Taxman Game"); System.out.print("Enter the maximum income amount: "); int n = Integer.parseInt(s.nextLine().trim()); taxman = new Taxman(n); do { System.out.println(taxman); System.out.printf("\nCurrent score: you have %d and taxman has %d\n", taxman.incomeEarned(), taxman.taxesPaid()); System.out.print("\nChoose a number as income: "); int income = Integer.parseInt(s.nextLine().trim()); if (taxman.isLegalChoice(income)) { taxman.makeChoice(income); System.out.printf("\nTaxes paid on income %d: %s\n", income, taxman.imageOfNewTaxes()); } else { System.out.println("\nError: your choice is invalid; try again\n"); } } while (taxman.legalChoicesExist()); System.out.println("\nGame is over; you must pay residual taxes..."); taxman.payResidualTaxes(); System.out.println(taxman); System.out.printf("\nFinal score: you earned %d and paid %d in taxes.\n", taxman.incomeEarned(), taxman.taxesPaid()); } }