Desperaqtly need help
807601May 5 2008 — edited May 27 2008Object-Oriented Programming Fundamentals
Semester 1, 2008
Assignment 2
Due Date: 9.30am, 19th May 2008
Delays caused by computer downtime cannot be accepted as a valid reason for a late submission without penalty. Students must plan their work to allow for both scheduled and unscheduled downtime.
Submission Details
You must submit an electronic version of your assignment on latcs6 using the submit command. Ensure you submit all required files. Files should be submitted one file at a time. For example, the file GamesDriver.java would be submitted with the command:
> submit OOF GamesDriver.java
This is an individual assignment. You are not permitted to work as a group when writing this assignment.
Copying, Plagiarism: Plagiarism is the submission of somebody else?s work in a manner that gives the impression that the work is your own. The Department of Computer Science and Computer Engineering treats plagiarism very seriously. When it is detected, penalties are strictly imposed. Refer to the unit guide for further information and strategies you can employ to avoid a charge of academic misconduct. All reports and source code will be electronically checked for plagiarism.
Return of Assignment: You will receive a marking sheet with a mark break down within three weeks of submission.
Please Note: While you are free to develop the code for this assignment on any operating system, your solution must run on the latcs6 system.
Assignment Objectives
This assignment requires analysis, design, implementation and testing of a problem with four (plus one bonus) distinct tasks. Its general aims are:
? to design programs that conform to given specifications
? to implement programs in Java
? to practise combining multiple classes and methods into a whole program.
Problem Description
Computer games are one of the most popular uses of home computers. The development of popular commercial computer games involves large programming projects that take many months, if not years, to complete and employ many programmers. This assignment involves developing several simple games within the context of a text-based menu system to demonstrate a number of programming principles used in large games as well as in many other types of software.
Task 1
In Task 1, you are simply required to set up the framework of the program. In a launcher class called GamesDriver, first create a method that displays the following menu to the screen (exactly as shown).
*************************
GAMES MENU
----------
E) Elimination
C) Calculator 21
G) Crag
Y) Yacht
Q) Quit
*************************
Please select a game:
Next, create a method that repeatedly displays this menu, and prompts the user for a choice. For each of the choices, a separate method should be called. If the user chooses ?Q?, the program should terminate. If the user inputs any invalid choice, the method should notify the user that it was an invalid choice and display the menu again. The input should not be case sensitive; e.g. to go to the Yacht menu the user can enter either uppercase ?Y? or lowercase ?y?.
For each choice ?E?, ?C?, ?G? and ?Y?, the program must call an appropriate method. Each of these methods will allow the user to play the appropriate game. After the game is completed, it will then ask the user if they wish to play the game again:
Would you like to play a new game?
[N]ew game
[Q]uit
At the moment, the games have not been written and therefore these methods should display a message to the user that the game is not implemented. As you complete Tasks 2 to 5, update the methods to call the appropriate games. Note that in the game of Elimination the player either wins or loses. In the case that they lose the game, they should be asked if they want to replay the same game:
Would you like to play the game again or play a new game?
[P]lay again
[N]ew game
[Q]uit
If they won the game, then the normal choice should be displayed.
As with the main menu, the selections in all cases must be case insensitive. In all cases if the user selects Q or q they should be taken back to the main menu so that they can play a different type of game.
Note that your code should be neat, correctly indented and documented.
Task 2 ? Elimination
In this task you are required to write the program code that allows a player to play a game of Elimination [1].
In the game of Elimination the computer generates a random 5 digit integer. It is the player?s goal to reduce this number to 0 in four steps. The player is allowed to use the subtraction and division operators and 2 digit integers to complete the task.
An example run through the game follows (user input is indicated in bold type):
Playing Elimination ? starting value is 20580
- 80
- 80 = 20500
/ 50
/ 50 = 410
/41
/ 41 = 10
-10
- 10 = 0
You Win!
The program must generate the original five digit number. It then takes input from the user for each of the four rounds. After each correct input from the player, the program shows the player?s choice and calculates and displays the new subtotal. If the user succeeds in reducing the random number to 0 then the program displays that they have won, if not, then it displays that they have lost. As discussed in Task 1, in the case that the user loses they must be given the choice of playing the same game again (that is, with the same starting value).
The program must check numerous things in the process of playing Elimination:
? The randomly generated number must have 5 digits and no leading zeroes (that is the number could not be 01234).
? The user?s input must consist of two parts: an operator and a two digit number. The program must check that the first part of the input is a subtraction or division operator and that the integer is indeed a two digit number (in this case leading zeroes are allowed, the number may be between 0 and 99 inclusive). The user?s input may or may not have white space between the operator and the number.
? In the case of a division operator being input, the program must check that the current value of the number divided by the specified two-digit number results in a whole number. For example, in the example above when dividing by 41, there is no remainder. If the player had entered /40 instead, there would be a remainder from that division and it would not be allowed.
? In any case of error, the line of user input should be ignored and the player must enter their selection for the step again.
Tips: Math.random() is a useful method for generating random numbers.
The modulus operator (%) is useful for checking whether a number is divisible by another number.
Note that your code should be neat, correctly indented and documented.
Task 3 ? Calculator 21
In this task you are required to write the program code that allows a player to play a game of Calculator 21 [1].
The game of Calculator 21 uses two dice. (Dice are small cubes with different values on each of their 6 sides. Usually these values are the numbers from 1 to 6). In most dice games, a die is thrown and the value landing face up is used in the game. Write a Die class that represents a single die (singular of dice). Each Die object is constructed with an initial face value. Code using the die class should be able to retrieve the current value showing for a die, and using another method re-throw the die.
In Calculator 21, the user has two dice which they throw. In each round the two dice are thrown and the user must use the addition and subtraction operators and one of the two current face values to try to change a running total (which starts at 0) until it becomes 21. The aim of the game is to reach 21 in the least amount of throws.
An example run through the game follows (user input is indicated in bold type):
Playing Calculator 21
You threw 4 and 5
+ 5
+ 5 = 5
You threw 1 and 5
+5
+ 5 = 10
You threw 5 and 1
+5
+ 5 = 15
You threw 1 and 2
+ 2
+ 2 = 17
You threw 3 and 6
+6
+ 6 = 23
You threw 4 and 1
-1
- 1 = 22
You threw 1 and 5
- 1
- 1 = 21
You Win!
It took you 7 moves
The program must generate and display the dice values in each round. It then takes input from the user for each of the rounds. After each correct input from the player, the program shows the players choice and calculates and displays the new subtotal. When the user succeeds in reaching 21 then the program displays that they have won and the number of moves that it took them.
The Program must check numerous things in the process of playing Calculator 21:
? The user?s input must consist of two parts: an operator and an integer. The program must check that the first part of the input is an addition or subtraction operator and that the integer entered is indeed one of the two dice values thrown in that round. The user?s input may or may not have white space between the operator and the number.
? In any case of error, the line of user input should be ignored and the player must enter their selection for the step again.
Note that your code should be neat, correctly indented and documented.
Task 4 ? Crag
In this task you are required to write a class called CragGame that allows a player to play a game of Crag [1].
The game of Crag uses three dice (reuse your Die class from Task 2). There are 13 rounds in crag and the aim is to score the highest possible total value for the 13 rounds. The player has 13 different ways of calculating a round?s score but they can only use each technique once in each game. Each technique therefore will be used exactly once in each game.
In each round the player throws three dice. They can then choose to throw any of the three dice one more time. Once they have the final face values for that round they select which technique will be used to score that round. The possible techniques are as follows:
1. Ones (add up all the face values displaying one ? maximum is 3)
2. Twos (add up all the face values displaying two ? maximum is 6)
3. Threes (add up all the face values displaying three ? maximum is 9)
4. Fours (add up all the face values displaying four ? maximum is 12)
5. Fives (add up all the face values displaying five ? maximum is 15)
6. Sixes (add up all the face values displaying six ? maximum is 18)
7. Odd straight (If the face values are 1, 3 and 5 score 20, otherwise score 0)
8. Even straight (If the face values are 2, 4 and 6 score 20, otherwise score 0)
9. Low straight (If the face values are 1, 2 and 3 score 20, otherwise score 0)
10. High straight (If the face values are 4, 5 and 6 score 20, otherwise score 0)
11. Three of a kind (If the face values all show the same number score 25, otherwise score 0)
12. Thirteen (If the sum of the face values is thirteen and all the face values are different score 26, otherwise score 0)
13. Crag (If the sum of the face values is thirteen and two of the face values are the same score 50, otherwise score 0)
A partial example run through the game follows (user input is indicated in bold type):
Round: 1
------------------------
1: Ones -
2: Twos -
3: Threes -
4: Fours -
5: Fives -
6: Sixes -
7: Odd Straight -
8: Even Straight -
9: Low Straight -
10: High Straight -
11: Three of a kind -
12: Thirteen -
13: Crag -
------------------------
Total: 0
------------------------
You have thrown:
Die 1: 6
Die 2: 3
Die 3: 4
Do you want to throw die 1 again [Y/N]: n
Do you want to throw die 2 again [Y/N]: n
Do you want to throw die 3 again [Y/N]: n
The dice show:
Die 1: 6
Die 2: 3
Die 3: 4
Record this against which entry [1-13]:
------------------------
1: Ones -
2: Twos -
3: Threes -
4: Fours -
5: Fives -
6: Sixes -
7: Odd Straight -
8: Even Straight -
9: Low Straight -
10: High Straight -
11: Three of a kind -
12: Thirteen -
13: Crag -
------------------------
Total: 0
------------------------
12
Round: 2
------------------------
1: Ones -
2: Twos -
3: Threes -
4: Fours -
5: Fives -
6: Sixes -
7: Odd Straight -
8: Even Straight -
9: Low Straight -
10: High Straight -
11: Three of a kind -
12: Thirteen 26
13: Crag -
------------------------
Total: 26
------------------------
You have thrown:
Die 1: 4
Die 2: 5
Die 3: 3
Do you want to throw die 1 again [Y/N]: y
Do you want to throw die 2 again [Y/N]: n
Do you want to throw die 3 again [Y/N]: n
The dice show:
Die 1: 4
Die 2: 5
Die 3: 3
Record this against which entry [1-13]:
------------------------
1: Ones -
2: Twos -
3: Threes -
4: Fours -
5: Fives -
6: Sixes -
7: Odd Straight -
8: Even Straight -
9: Low Straight -
10: High Straight -
11: Three of a kind -
12: Thirteen 26
13: Crag -
------------------------
Total: 26
------------------------
3
Round: 3
------------------------
1: Ones -
2: Twos -
3: Threes 3
4: Fours -
5: Fives -
6: Sixes -
7: Odd Straight -
8: Even Straight -
9: Low Straight -
10: High Straight -
11: Three of a kind -
12: Thirteen 26
13: Crag -
------------------------
Total: 29
------------------------
You have thrown:
Die 1: 2
Die 2: 5
Die 3: 6
Do you want to throw die 1 again [Y/N]: Y
Do you want to throw die 2 again [Y/N]: y
Do you want to throw die 3 again [Y/N]: N
The dice show:
Die 1: 6
Die 2: 2
Die 3: 6
Record this against which entry [1-13]:
------------------------
1: Ones -
2: Twos -
3: Threes 3
4: Fours -
5: Fives -
6: Sixes -
7: Odd Straight -
8: Even Straight -
9: Low Straight -
10: High Straight -
11: Three of a kind -
12: Thirteen 26
13: Crag -
------------------------
Total: 29
------------------------
6
...
Record this against which entry [1-13]:
------------------------
1: Ones 1
2: Twos 4
3: Threes 3
4: Fours 8
5: Fives 5
6: Sixes 12
7: Odd Straight 0
8: Even Straight 20
9: Low Straight 0
10: High Straight 0
11: Three of a kind 0
12: Thirteen 26
13: Crag 0
------------------------
Total: 79
------------------------
11
The total score is 79
The program must generate and display the dice values in each round. When you implement the Crag game use separate variables for each of the three dice. It then takes input from the user for each of the rounds. After each correct input from the player, the program shows the updated score card. Each round is labelled with its appropriate value.
The program must do and check numerous things in the process of playing Crag:
? The user makes two types of input in this game. They must enter a character ?y? or ?n? to determine whether to throw each dice again. After the face values for the dice are finalised for a round they must also select which scoring technique to use for the round. The program must check that only a ?y? or ?n? are selected when choosing to throw the dice again. The program must also check whether or not the scoring technique they select is allowed. That is that the technique number is between 1 and 13 and that the selected scoring technique has not been used already during the game.
? Calculating the score with each technique may be quite lengthy. Breaking the code down into small helper methods will help to manage the tasks.
Note that your code should be neat, correctly indented and documented.
Bonus Task 5 ? Yacht
(This task is not required. It is a bonus question as you will need to read ahead to cover arrays. It is possible to achieve 100% on the assignment without attempting this task. Bonus marks can carry over into any non-exam component, though it is not possible to achieve more than 100% in the total of the non-exam components.)
In this task you are required to write a class called YachtGame that allows a player to play a game of Yacht [1].
The game of Yacht is similar to Crag but uses five dice (reuse your Die class from Task 2). There are 12 rounds in Yacht and the aim is to score the highest possible total value for the 12 rounds. The player has 12 different ways of calculating a round?s score but they can only use each technique once in each game. Each technique therefore will be used exactly once in each game.
In each round the player throws five dice. They can then choose to throw any of the five dice two more times. Once they have the final face values for that round they select which technique will be used to score that round. The possible techniques are as follows:
1. Ones (add up all the face values displaying one ? maximum is 5)
2. Twos (add up all the face values displaying two ? maximum is 10)
3. Threes (add up all the face values displaying three ? maximum is 15)
4. Fours (add up all the face values displaying four ? maximum is 20)
5. Fives (add up all the face values displaying five ? maximum is 25)
6. Sixes (add up all the face values displaying six ? maximum is 30)
7. Little straight (If the face values are 1, 2, 3, 4 and 5 score 15, otherwise score 0)
8. Big straight (If the face values are 2, 3, 4, 5 and 6 score 20, otherwise score 0)
9. Full house (If three of the face show the same number and the other two face values show the same number add up all the face values, otherwise score 0 (eg. 3, 3, 2, 3, 2 would score 13))
10. Four of a kind (If four of the dice show the same number, add up the four face values of the similar dice, otherwise score 0 (e.g. 2, 2, 2, 3, 2 would score 8))
11. Choice (Any face values are allowed, add up the face values)
12. Yacht (If all five of the dice show the same number score 50,, otherwise score 0)
The first round from an example game follows (user input is indicated in bold type):
Round: 1
-------------------------
1: Ones -
2: Twos -
3: Threes -
4: Fours -
5: Fives -
6: Sixes -
7: Little Straight -
8: Big Straight -
9: Full House -
10: Four of a Kind -
11: Choice -
12: Yacht -
-------------------------
Total: 0
-------------------------
You have thrown:
Die 1: 2
Die 2: 1
Die 3: 4
Die 4: 2
Die 5: 2
Do you want to throw die 1 again [Y/N]: n
Do you want to throw die 2 again [Y/N]: y
Do you want to throw die 3 again [Y/N]: y
Do you want to throw die 4 again [Y/N]: n
Do you want to throw die 5 again [Y/N]: n
You have thrown:
Die 1: 2
Die 2: 4
Die 3: 6
Die 4: 2
Die 5: 2
Do you want to throw die 1 again [Y/N]: n
Do you want to throw die 2 again [Y/N]: y
Do you want to throw die 3 again [Y/N]: n
Do you want to throw die 4 again [Y/N]: n
Do you want to throw die 5 again [Y/N]: n
The dice show:
Die 1: 2
Die 2: 3
Die 3: 6
Die 4: 2
Die 5: 2
Record this against which entry [1-12]:
-------------------------
1: Ones -
2: Twos -
3: Threes -
4: Fours -
5: Fives -
6: Sixes -
7: Little Straight -
8: Big Straight -
9: Full House -
10: Four of a Kind -
11: Choice -
12: Yacht -
-------------------------
Total: 0
-------------------------
2
The program must generate and display the dice values in each round. When you implement the Yacht game you must use an array to store the five dice. It then takes input from the user for each of the rounds. After each correct input from the player, the program shows the updated score card. Each round is labelled with its appropriate value.
The program must do and check numerous things in the process of playing Yacht:
? The user makes two types of input in this game. They must enter a character ?y? or ?n? to determine whether to throw each dice again. After the face values for the dice are finalised for a round they must also select which scoring technique to use for the round. The program must check that only a ?y? or ?n? are selected when choosing to throw the dice again. The program must also check whether or not the scoring technique they select is allowed. That is that the technique number is between 1 and 12 and that the selected scoring technique has not been used already during the game.
? Calculating the score with each technique may be quite lengthy. Breaking the code down into small helper methods will help to manage the tasks.
Note that your code should be neat, correctly indented and documented.
Marking Scheme Overview
You must demonstrate your program to a marker during your lab class in Week 13 of semester. This is compulsory, and you will receive 0 for the implementation if you do not demonstrate your program.
Implementation (Execution of code) 70% (Do all parts of the programs execute correctly? Note your programs must compile and run to carry out this implementation marking. )
Code Design and Structure 20% (Does the program conform to specifications? Does the program solve the problem in a well-designed manner? Does the program follow good programming practices?)
Layout and Documentation of Code 10% (Does the indentation of the code follow the Coding Standard? Do the identifiers conform to this standard? Does the code contain appropriate comments?)
Task 5 bonus marks 20% (Does task 5 perform correctly?)
References:
Gyles Brandeth, Everyman?s Indoor Games, Dent Publishing, London, 1981.
Walter Savitch, Java: An introduction to Computer Science and Programming (Third Edition), Pearson Education, 2004.
This assignment constitutes 15% of your overall mark in CSE1OOF.
this is a programm for my assignment i am totally unaware of the assignment as i am really in deep trouble can anybody please help me to complete my assignment it will really help me to pass in my finals please help me