CMPS 144 Fall 2022
Prog. Assg. #5: Taxman
Due: 11:59pm, December 10

Background

Taxman is a solitaire game in which the player tries to "earn" more income than (s)he "pays" in taxes. For some positive integer n chosen at the beginning of the game, each positive integer in the range [1..n] eventually is earned as income or is paid in taxes.

The term active describes any number that has not yet been earned as income or paid in taxes. The game begins with all the numbers (i.e., 1 through n) being active. On each turn, the player must choose an active number k that has at least one active proper divisor.1 As a result of that choice, k is credited to the player as income and all its active proper divisors are paid as taxes. All these proper divisors, as well as k itself, become inactive.

At such time that no active number has an active proper divisor, all remaining active numbers are paid as residual taxes and the game comes to an end.

The player's goal is to accumulate more in income than is paid in taxes.


Assignment

The following Java classes are provided:


User Dialog with PlayTaxman

$ java PlayTaxman
Welcome to the Taxman Game
Enter the maximum income amount: 20
Income: {}
Taxes : {}
Active: {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20}
OpCntr: 135

Current score: you have 0 and taxman has 0

Choose a number as income: 19

Taxes paid on income 19: {1}
Income: {19}
Taxes : {1}
Active: {2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 20}
OpCntr: 339

Current score: you have 19 and taxman has 1

Choose a number as income: 14

Taxes paid on income 14: {2, 7}
Income: {14, 19}
Taxes : {1, 2, 7}
Active: {3, 4, 5, 6, 8, 9, 10, 11, 12, 13, 15, 16, 17, 18, 20}
OpCntr: 549

Current score: you have 33 and taxman has 10

Choose a number as income: 8

Taxes paid on income 8: {4}
Income: {8, 14, 19}
Taxes : {1, 2, 4, 7}
Active: {3, 5, 6, 9, 10, 11, 12, 13, 15, 16, 17, 18, 20}
OpCntr: 730

Current score: you have 41 and taxman has 14

Choose a number as income: 20

Taxes paid on income 20: {5, 10}
Income: {8, 14, 19, 20}
Taxes : {1, 2, 4, 5, 7, 10}
Active: {3, 6, 9, 11, 12, 13, 15, 16, 17, 18}
OpCntr: 965

Current score: you have 61 and taxman has 29

Choose a number as income: 12

Taxes paid on income 12: {3, 6}
Income: {8, 12, 14, 19, 20}
Taxes : {1, 2, 3, 4, 5, 6, 7, 10}
Active: {9, 11, 13, 15, 16, 17, 18}
OpCntr: 1174

Current score: you have 73 and taxman has 38

Choose a number as income: 15

Error: your choice is invalid; try again

Income: {8, 12, 14, 19, 20}
Taxes : {1, 2, 3, 4, 5, 6, 7, 10}
Active: {9, 11, 13, 15, 16, 17, 18}
OpCntr: 1298

Current score: you have 73 and taxman has 38

Choose a number as income: 18

Taxes paid on income 18: {9}

Game is over; you must pay residual taxes...
Income: {8, 12, 14, 18, 19, 20}
Taxes : {1, 2, 3, 4, 5, 6, 7, 9, 10, 11, 13, 15, 16, 17}
Active: {}
OpCntr: 1598

Final score: you earned 91 and paid 119 in taxes.


Footnote

[1] Where m and k are positive integers, m is said to be a proper divisor of k if m < k and k % m = 0.

Submitting Your Work

Use the CMPS 144 Student File Submission/Retrieval Utility to submit your Taxman.java file into the prog5 folder. Be sure to include comments in the header that identify you, any persons with whom you collaborated, and any defects that you are aware of.