Starting from:
$35

$29

Project #3 Solution

Task #1:

Write a Java program that asks user to enter an integer that is greater than or equal to 2 (if invalid input, ask user to try 3 times and after 3rd time, exit the program), then use a method isPrime to test if this number is a prime number or not (a prime number is only divisible by 1 and itself, for example, 5 is a prime number as it’s only divisible by 1 and 5, 6 is not a prime number as it’s divisible by 1, 2, 3, 6). The isPrime method should take an integer as an argument and returns true if the argument is a prime number, or false otherwise. Test the program with 2, 5, 6, 19, 51, 53, 297, 301.




Task #2
Write a program that lets the user play the game of Rock, Paper, Scissors against the computer. The program should work as follows.

When the program begins, a random number in the range of 1 through 3 is generated. If the number is 1, then the computer has chosen rock. If the number is 2, then the computer has chosen paper. If the number is 3, then the computer has chosen scissors. (don’t display the computer’s choice yet.)
Then ask the user to enter his/her choice of “rock”, “paper”, or “scissors” at the keyboard (you can use a method to display a menu here if you prefer.)
The computer’s choice is displayed.
A winner is selected according to the following rules: the rock smashes the scissors, scissors cuts paper, and paper raps rock. If both players make the same choice, it’s a tie.
Suggest that each of the above steps is programmed as a method. So the main method may read as:

… computerGenereateNumber( …);

… getUserChoice(…);

… displayComputerChoice(…);

… selectWinner(…);

…displayWinnerOrMsg(…);




Note: you may choose different method names, decide for each method appropriate parameters/arguments; and may use more than above methods (and/or delete one or two from above list such as deleting displayWinnerOrMsg method.)

Test the program by playing the game at least 3 times with the user entering different choices.




Submission instruction

Create script files for all required test runs. Copy and paste the test run results captured in script file to the end of each Java program as block comments. Submit the Java program for Task #1 and the Java program for Task #2 to blackboard along the project #3 link.




Grading criteria

Correctness (2 x 10 = 20 points) Use of methods (2 x 10 = 20 points) Program quality (2 x 5 = 10 points) Note: program quality includes proper use of comments, readability, etc.




Special Notes: Please keep in mind University’s academic integrity policy – you may fail the class immediately if you copied a program from the Internet.

More products