Solitaire is a card game that you play against yourself. When you play solitaire you either win or you lose. Solitaire players are very organised. As a result the Australian Solitaire Players Federation is also very organised. In this exam you are going to write code to help keep them organised by answering the three questions below.
Define a Java class to represent a person in a file called Person.java. A Person has the following attributes:
Your Person class should have the following methods:
When you compile and run the driver file you should see the output:
Person: anon is age: -1
Person: Jane Austen is age: 23
Person: Spiro Agnew is age: 76
Person: Sally Smith is age: 18
Person: Jane Austen is age: 23
Person: Spiro Agnew is age: 77
18
Jane Austen
77
Note that having your driver file work in the desired way does not guarantee you will pass all the tests - we will run more tests.
The Australian Solitaire Players Federation keeps track of all registered solitaire players in Australia. This is so they can help organise clubs and work out player rankings. Write a Java class to represent a solitaire Player. This class should extend the Person class from question 1 and have at least the following additional attributes:
Note that due to a quirk in the scoring of Solitaire it is possible for players to count more wins than games played! (it's due to a weird historical rule - nobody remembers why).
Of course because Player extends Person, Players also automatically have the name and age attributes of Person. Your Player class should have the following methods:
When you compile and run the driver file you should see the output:
Person: Sally Smith is age: 18 Id: 1 Ranking: 0
Person: Jane Austen is age: 23 Id: 2 Ranking: 6
Person: Spiro Agnew is age: 76 Id: 3 Ranking: 8
Person: Sarah Smith is age: 18 Id: 1 Ranking: 0
Person: Jane Austen is age: 23 Id: 2 Ranking: 4
Person: Spiro Agnew is age: 77 Id: 3 Ranking: 9
18
Jane Austen
77
9
0
2
Note how the id's increase automatically as the players are constructed and how the id's start at 1. As before, note that having your driver file work in the desired way does not guarantee you will pass all the tests - we will run more tests.
Last but not least, write a Java class file called Club.java that represents a solitaire club. A club keeps track of its members. Members can belong to more than one club (the Solitaire Players Federation is organised but not jealous!). Your class should have the following attribute:
It should have the following methods:
When you compile and run the driver file you should see the output:
Club 1
Person: Sally Smith is age: 18 Id: 1 Ranking: 0
Person: Jane Austen is age: 23 Id: 2 Ranking: 6
Person: Yasi Jones is age: 53 Id: 5 Ranking: 2
Club 2
Person: Sally Smith is age: 18 Id: 1 Ranking: 0
Person: Spiro Agnew is age: 76 Id: 3 Ranking: 8
Person: Jenny Lee is age: 33 Id: 4 Ranking: 8
Club 1
Person: Sally Smith is age: 18 Id: 1 Ranking: 1
Person: Jane Austen is age: 23 Id: 2 Ranking: 4
Person: Yasi Jones is age: 53 Id: 5 Ranking: 4
Club 2
Person: Sally Smith is age: 18 Id: 1 Ranking: 1
Person: Spiro Agnew is age: 76 Id: 3 Ranking: 10
Person: Jenny Lee is age: 33 Id: 4 Ranking: 9
true
false
Club 1
Person: Jane Austen is age: 23 Id: 2 Ranking: 4
Person: Yasi Jones is age: 53 Id: 5 Ranking: 4
Club 2
Person: Sally Smith is age: 18 Id: 1 Ranking: 1
Person: Spiro Agnew is age: 76 Id: 3 Ranking: 10
Person: Jenny Lee is age: 33 Id: 4 Ranking: 9
Highest Ranked Players
Person: Yasi Jones is age: 53 Id: 5 Ranking: 4
Person: Spiro Agnew is age: 76 Id: 3 Ranking: 10
As before note that having your driver file work in the desired way does not guarantee you will pass all the tests - we will run more tests.