Homework 7
Arrays Programs
The purpose of this assignment is to give you practice at programming with arrays and to apply your knowledge of arrays in more creative ways, by defining more complete application-level programs that need arrays to perform their function most effectively.
Driver's License Exam
The local Driver's License Office has asked you to write a program that grades the written portion of the driver's license exam. The exam has 20 multiple choice questions. Here are the correct answers:
1. B 6. A 11. B 16. C 2. D 7. B 12. C 17. C 3. A 8. A 13. D 18. C 4. A 9. C 14. A 19. D 5. C 10. D 15. D 20. AYour program should store the correct answers given above in an array. It should then ask the user to enter the answers for a student. These twenty answers should also be stored in another array. After the student's answers have been entered, the program should compute correct and incorrect answers and should display a message indicating whether the student passed the exam, or failed the exam. A student must answer 15 or more of the questions to pass the exam. The program should then display the total number of correctly answered questions, the total number of incorrectly answered questions, and a list showing the question numbers of the incorrectly answered questions. A program that meets the above specification and is well documented and structured will receive 90% of the credit for this question. The remaining 10% may be earned by adding the ability to handle multiplie students or to retrieve the student answers from a text file instead of interactively from the user. Extra credit will be awarded for including both of these additional features.
Lottery Application
Write a program that simulates a lottery. The program should have an array of five integers named lottery, and should generate a random number in the range of 0 through 9 for each element in the array. The user should enter five digits which should be stored in an array named user. The program is to compare the corresponding elements in the two arrays and keep a count of the digits that match. For example, the following shows the lottery array and the user array with sample numbers stored in each. There are two matching digits (elements at indices 2 and 4).
lottery array 7 4 9 1 3
user array 4 2 9 7 3The program should display the random numbers stored in the lottery array and the number of user digits matching the lotter digits. If all the digits match, display a message proclaiming the user as a grand prize winner.
Tic-Tac-Toe Game
This third array program is for extra credit.
Write a program that allows two players to play a game of tic-tac-toe. Use a two-dimensional char array with 3 rows and 3 columns as the game board. Each element of the array should be initialized with an '*'. The program should run a loop that
- Displays the contents of the board array.
- Allows player 1 to select a location on the board for an X. The program should ask the user to enter a row and a column number.
- Allows player 2 to select a location on the board for an O. The program should ask the user to enter a row and a column number.
- Determines whether a player has won, or a tie has occurred. If a player has won, the program should declare that player the winner. If a tie has occurred, the program should say that and end.
Player 1 winds when there are three X's in a row on the game board. The X's can appear in a row, in a column, or diagonally across the board. A tie occurs when all of the locations on the board are full, but there is no winner.
Turn-in
Programs will be turned in by copying the Java source file to the Assignment Inbox area of the Shared Workspaces under the Instructor/Class-Section for this course. Please create a folder named Program7 and place your source files within that folder.
