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.
The student's task is to complete this class.
In order for the PlayTaxman application to work properly, all the public methods in Taxman need to satisfy their specifications. However, within limits, the student is free to implement them as (s)he sees fit.
For example, while it is expected that your solution will make use of instances of SetIntRange, it is not necessary that your choices of instance variables of type SetIntRange match exactly what is suggested. (Indeed, none among the activeDivSet, incomeTotal, or taxesTotal variables is necessary. Your instructor's solution makes use of them, mostly because he believes that runtime performance would suffer without them. But slight improvements in runtime performance are of little importance in the context of a program that interacts with a user.)
$ 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. |