Assignment 13
Due Thursday, May 24 at 1:20pm on Canvas

Assignment 13.1: 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.
  • In this assignment we will develop a program to count votes.
  • Write a Java program that tallies, or counts, 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.
  • When your program works identically to the example output below, submit it to Canvas.
Your Output Should Look Indentical to the Following.

***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



Assignment 13.2: Little Boy Blue Again (10 pts)

Denslow-little-boy-blue2.jpg Open Blue.java from Assignment 12.

Alter the while loop in your program to be a for loop.

When your output is identical to the while loop version's, submit your program to Canvas.







Your Output Should Look Like the Following. Note that some values have been omitted for brevity.

1
2
Little Boy Blue
4
Come Blow Your Horn
Little Boy Blue
7
8
Little Boy Blue
Come Blow Your Horn
11
Little Boy Blue
13
14
The Sheep's in the Meadow. The Cow's in the Corn.
16
17
Little Boy Blue
19
Come Blow Your Horn
Little Boy Blue
22
...
149
The Sheep's in the Meadow. The Cow's in the Corn.


Assignment 13.3: i and j (10 pts)
  • Create a new Java file called IJ.java.
  • In this assignment, we are going to write another program that uses a for loop. 
  • Within the loop, make the variable i go from -5.0 to 5.0, counting by 0.5
  • Inside the body of the loop, set another variable j to be the current value of i raised to the fourth power
  • For output, you will need to display the current values of both i and j in a chart, as shown below.
  • Note that above the values, you should print out i above the i column and j above the j column.
  • Also, you should display the values to exactly one decimal point.
  • You will need to use tab, System.out.printf and the Math.pow(base,exp) method here.
  • When you are finished, upload your source code to Canvas.
Your Output Should Look Indentical to the Following:

i          j
-5.0       625.0
-4.5       410.1
-4.0       256.0
-3.5       150.1
-3.0       81.0
-2.5       39.1
-2.0       16.0
-1.5       5.1
-1.0       1.0
-0.5       0.1
0.0        0.0
0.5        0.1
1.0        1.0
1.5        5.1
2.0        16.0
2.5        39.1
3.0        81.0
3.5        150.1
4.0        256.0
4.5        410.1
5.0        625.0