Write pseudo code for the following problem(s)...pick one. JAVA You are to calcu
ID: 3871658 • Letter: W
Question
Write pseudo code for the following problem(s)...pick one. JAVA
You are to calculate the batting average for a baseball player. The program will input the number of at bats and the total number of hits.
You are to calculate the percentage of votes obtained by a candidate. The program will input the total votes cast for all candidates and the votes for your candidate.
You are to calculate the GPA for a student. The program will input 10 exam scores and then display the current GPA for the scores.
Explanation / Answer
PSEUDO CODE:
Input: totalVotes, candidateVotes as Integers
Process:
percentage as Double
percentage = candidateVotes/totalVotes
percentage = percentage * 100
Output: Percentage is percentage
PROGRAM CODE:
package com;
import java.util.Scanner;
public class VoteAverageGenerator {
public static void main(String[] args) {
double total = 0, votes = 0, percentage;
Scanner reader = new Scanner(System.in);
System.out.print("Enter total votes: ");
total = reader.nextInt();
System.out.print(" Enter votes of candidate: ");
votes = reader.nextInt();
percentage = (votes/total)*100;
System.out.println(" Percentage is " + percentage);
}
}
OUTPUT:
Enter total votes: 150
Enter votes of candidate: 75
Percentage is 50.0
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.