Java Assignment 5
You have until Tuesday, April 10 to complete this assignment and have it submitted in the pass-in folder on the G: drive. There is a folder called “Java - Assignment 05” where you are to place all your Java files for this assignment.
Problem 1
Write a program that will input the three numbers of a combination lock and test them to see if the lock should open. The lock will open if the numbers are within 3 of the actual combination. After you take in the 3 numbers from the user, tests if the combination they entered is valid with ONE if-else statement (remember the operator). Here is the example output if the combination is 10-20-25.
Enter the first number: 13
Enter the second number: 21
Enter the third number: 22
The lock opens!!!!
Problem 2
Write a program that implements a guessing game. The program picks a random number from 1 to 10. The program then prompts the user to guess a number and continues asking until the correct number is guessed. Here is an example:
Guess a number between 1 and 10:3
Incorrect, guess again: 5
Incorrect, guess again: 7
Incorrect, guess again: 2
Correct, the number was 2.
Problem 3
Now that you have completed the guessing game, create a more advanced game. The goal of this game is to guess a number between 1 and 50. If the user enters a guess that is within 10 of the actual answer, the program tells them that they are HOT. If they enter a number that is within 3 of the answer, it tells them that they are VERY HOT. If they input anything else, they are COLD. Here is an example of the program running (the correct answer is 17):
Guess a number between 1 and 50: 40
You’re COLD, guess again: 10
You’re HOT, guess again: 20
You’re VERY HOT, guess again: 17
Correct, the number was 17.
Problem 4
Write a program that asks the user to enter 10 numbers and stores them into an array. The program should then print out the numbers in reverse order using a loop. Here is an example:
Please type 10 integers: 4 80 74 34 2 8 91 182 7 21
The numbers in reverse order are: 21 7 182 91 8 2 34 74 80 4
Problem 5
It’s time to begin writing our Java tic-tac-toe game. Each week there will be a new task to add to the program. This week, you are to begin writing the program by creating an array of 9 integers that represent the positions in the tic-tac-toe board. I will explain this in class, so you have a better understanding. Once you have the array created, assign values to the board and print the contents of the board out. The values for the board are in this table:
Board Value / Integer In ArrayX / 10
O / 100
Empty Square / 0
This is an example of an array that represents a board:
10 / 0 / 0 / 100 / 0 / 10 / 10 / 100 / 0Here is an example of what the above array would look like when printed to the screen:
+---+---+---+
| X | | |
+---+---+---+
| O | | X |
+---+---+---+
| X | O | |
+---+---+---+