代写硬币游戏TwoUp.
Instructions to Students
Answer the 2 questions.
Create a Netbeans JAVA project called Yourname2015CE01, for example
HarryPotter2015CE01. Create separate packages for each question
Create screen dumps of the resulting output of your program in NetBeans.
Each screen dump will be inserted into a Word document.
Combine all the screen dumps into a Word or PDF document called
Task01Yourname. e.g.Task01harrypotter
Ensure the front cover sheet of your document is correctly filled in.
Please for the assessment submission include the code as follows:
Submit assignment as compressed Netbeans project (with all question) called
Yourname2015CE01.zip via Student Web by the due date.
Questions
TwoUP game
TwoUP is a coin game that uses 2 coins. Both coins are tossed, and then the
outcome is recorded. When you toss 2 coins there are 4 possible outcomes. The
outcomes are:
Coin 1 | Coin 2 |
---|---|
H | H |
H | T |
T | H |
T | T |
When both coins display heads, it is called heads. When both coins display | |
tails, it is called tails. Then the coins display both head and tail OR tail | |
and head, it is called odds. | |
When the coins are tossed and heads is displayed, a user wins the same amount | |
of money that was bet. For example, if you bet $20 and heads is displayed you | |
receive your $20 back PLUS $20. That means you win $20. | |
When the coins are tossed and tails is displayed, a user loses the money that | |
was bet. For example, if you bet $20 and tails is displayed you lose your $20. | |
When the coins are tossed and odds is displayed, all bets are “frozen”. | |
This means the coins are tossed again. If heads is displayed on the second | |
toss, you win. If tails is displayed you lose. If odds is displayed all bets | |
are frozen and you toss again. | |
This is repeated until heads appears or tails appears or 5 odds are tossed. | |
If odds are tossed on 5 consecutive occasions, everyone loses accept the bank | |
who keeps the money that was bet. | |
A punter (user) has $200 to play TwoUP. The user will only bet in $10 and $20 | |
amounts for each game. | |
Simulate the game of TwoUP and find how many games are possible before the | |
punter loses all his/her money. | |
Generate a random number for the bet of the punter. | |
Only use a main class for this problem. |
Testing Result Program
Create a TestController class that contains a private attribute called tests.
The tests attribute is of type HashMap[Integer, Test].
The TestController constructor will initialise the HashMap.
The method populateTest(Test) accepts a Test object.
The key for the HashMap will be the test’s ID, which we can retrieve using the
test’s “get” method. We can then “put” the Test object in the HashMap.
Note: this method will only contain about 2 lines of code or less!
Create the TestTheTest class by creating 4 Test objects using the data given.
Test ID | Test Name | Test Score |
---|---|---|
897 | Programming | 42 |
898 | System Analysis and Design | 98 |
899 | Web Development | 20 |
900 | Android Programming | 16 |
Create a TestController object and use the populateTest(Test) method to | ||
populate the HashMap. | ||
Display the test results greater than or equal to 40 using an Iterator object. | ||
Also display the test results after sorting: |
- the objects by Test Score.
- the objects by Test Name.