Assignment 12
Due Tuesday, November 6 at 9:20am on Canvas


Assignment 12.1: Rock Paper Scissors (10 pts)


  • Write a program to simulate a Rock, Paper, Scissors competition between two players.
  • Your file should be named RPS.java and should be uploaded to Canvas when you are finished.
  • First, the program will welcome them to the competition.
Let's play Rock-Paper-Scissors!
  • Then, the program will prompt each user to enter his or her name.
Player one, please enter your name: _
  • Next, the program will ask each user (referring to him or her by name) to enter "Rock," "Paper" or "Scissors."
Jorge, please enter "Rock", "Paper" or "Scissors": _
  • Important: Note the use of the player name above and the " marks.
  • The program will determine who the winner is and output one of three options:
Rock breaks scissors!
Paper covers rock!
Scissors cut paper!
  • How will the program determine the winner? Hint: if - else if - else statements and using logical operators (&&, ||, !).
  • After outputting the above statement, the program will announce the winner by name:
Jorge wins!
  • In the case of a tie, the program should announce that the result is a draw.
The game is a tie.
  • Important: You are required to use logical operators (&&, ||, !) as part of your if  and else if statements.
  • The program should also prompt the user to decide if they want to play again (Hint: use a while loop).
  • Your program should work identically to the following examples:
         Let's play Rock-Paper-Scissors!

Rock-Paper-Scissors Round 1!

Player one, please enter your name: Jorge
Player two, please enter your name: Jennifer
Jorge, enter "Rock", "Paper", or "Scissors": Rock
Jennifer, enter "Rock", "Paper", or "Scissors": Scissors
Rock breaks scissors!
Jorge wins!

Do you want to play again (y/n): y

Rock-Paper-Scissors Round 2!

Player one, please enter your name: Jorge
Player two, please enter your name: Jennifer
Jorge, enter "Rock", "Paper", or "Scissors": Scissors
Jennifer, enter "Rock", "Paper", or "Scissors": Scissors
It's a tie!

Do you want to play again (y/n): y

Rock-Paper-Scissors Round 3!

Player one, please enter your name: Wen
Player two, please enter your name: Amelia
Wen, enter "Rock", "Paper", or "Scissors": Rock
Amelia, enter "Rock", "Paper", or "Scissors": Paper
Paper covers rock!
Amelia wins!

Do you want to play again (y/n): n
Thanks for playing!


Assignment 12.2: Tallying Votes (10 pts)

  • Elections are a formal group-decision making process by which a population chooses a person to hold office, such as the mayor of a city.
  • Another use of elections is to accept or reject a political proposition. 
  • Most election results are tallied, or counted, using electronic voting.
  • Most electronic voting machines use a computer to take care of the chore of casting and counting votes.
  • This Tuesday, November 6 (the date your assignment is due) is election day.
  • In this assignment we will develop a program to count votes.
  • The user enters votes based on a simple menu that presents the candidates.
  • The user then inputs a single character (upper or lowercase A-C) to choose their candidate from the menu.
  • Entering an 'X' (without the quotes) will exit the tallying operation and present a summary of the votes.
  • Name the source code file Vote.java.
  • Present a list of candidates to the user and allow her to enter a single character as input, and no other input, as shown in the Example Output.
  • Feel free to chose any candidate names you like for the voters to select. You do not have to use the 3 candidates from my example output.
  • Use an indefinite loop to allow multiple users to vote on your voting machine.
  • After all the votes are entered and the user enters an 'X', exit the loop and report the vote count by candidate names and neatly aligned as shown in the Example Run.
  • Your program should also report an error message if the user enters a letter other than A-C or X, as shown below.
  • Please use proper style as demonstrated in class
  • When your program works identically to the example output below, submit it to Canvas.
Example Output:

***Voting Machine!***

Candidate A: Dalai Lama
Candidate B: Bernie Sanders
Candidate C: The Black Panther

Enter your choice (A-C) or X to exit: C
You chose candidate The Black Panther

Candidate A: Dalai Lama
Candidate B: Bernie Sanders
Candidate C: The Black Panther

Enter your choice (A-C) or X to exit: c
You chose candidate The Black Panther

Candidate A: Dalai Lama
Candidate B: Bernie Sanders
Candidate C: The Black Panther

Enter your choice (A-C) or X to exit: Z
Invalid input. Please enter A-C or X

Candidate A: Dalai Lama
Candidate B: Bernie Sanders
Candidate C: The Black Panther

Enter your choice (A-C) or X to exit: A
You chose candidate Dalai Lama

Candidate A: Dalai Lama
Candidate B: Bernie Sanders
Candidate C: The Black Panther

Enter your choice (A-C) or X to exit: B
You chose candidate Bernie Sanders

Candidate A: Dalai Lama
Candidate B: Bernie Sanders
Candidate C: The Black Panther

Enter your choice (A-C) or X to exit: a
You chose candidate Dalai Lama

Candidate A: Dalai Lama
Candidate B: Bernie Sanders
Candidate C: The Black Panther

Enter your choice (A-C) or X to exit: B
You chose candidate Bernie Sanders

Candidate A: Dalai Lama
Candidate B: Bernie Sanders
Candidate C: The Black Panther

Enter your choice (A-C) or X to exit: C
You chose candidate The Black Panther

Candidate A: Dalai Lama
Candidate B: Bernie Sanders
Candidate C: The Black Panther

Enter your choice (A-C) or X to exit: X

***Election Results!***
Dalai Lama: 2
Bernie Sanders: 2
The Black Panther: 3