Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a program that calculates the total grade for three classroom exercises as

ID: 639665 • Letter: W

Question

    Write a program that calculates the total grade for three classroom exercises as a percentage. The score should be summarized in a table. Input the assignment information in this order:

-Name of assignment (may be spaces)
-points earned (ionterger)
-total points possible (interger)

The percentage in the sum total points earned divided by the total points possible.
The output has the following format:
-The assignment name is left justified
-The score is left justified
-The total points is left justified
-the percentage is right justified, with 2 decimal digits and a percent sign

==========

Sample input and output shown as follows:

Please enter name of assign 1: Group Project
Please enter points earned: 10
Please enter total points possible: 10

Please enter name of assign 2: String homework
Please enter points earned: 7
Please enter total points possible: 12

Please enter name of assign 3: Formatting
Please enter points earned: 5
Please enter total points possible: 8

This report is writtern by (your name):
Assignment       Score       Total points     Percent

GroupProject........10...................10..........100.00%
String homework....7...................12.............xx.xx%
Formatting..............5.....................8............xx.xx%

Totals......................22..................30

Your total is 22 out of 30, or 77.33%

Explanation / Answer

import java.text.DecimalFormat;
import java.util.Scanner;


public class CalculateGrade
{
/*Write a program that calculates the total grade for three classroom exercises as a
percentage. Use the DecimalFormat class to output the value as a percent. The
scores should be summarized in a table. Input the assignment information in this
order: name of assignment (may include spaces), points earned (integer), and total
points possible (integer). The percentage is the sum of the total points earned divided
by the total points possible. Sample input and output is shown as follows:
  
Exercise Score Total Possible
Group Project 10 10
Homework 7 12
Presentation 5 8
Total 22 30
  
Your total is 22 out of 30, or 73.33%.
*/
public static void main(String[] args)
{
Scanner input = new Scanner(System.in);
String[] nameOfAssignment = new String[3];
int[] pointsEarned = new int[3];
int[] pointsPossible = new int[3];
int totalPointsEarned = 0, totalPointsPossible = 0;
  
//getting all the needed inputs
for(int i = 0; i < 3; i++)
{
System.out.println("Name of exercise " + (i + 1) + ":");
nameOfAssignment[i] = input.nextLine();
  
System.out.println("Score received for exercise " + (i + 1) + ":");
pointsEarned[i] = input.nextInt();
totalPointsEarned += pointsEarned[i];
  
System.out.println("Total points possible for exercise " + (i + 1) + ":");
pointsPossible[i] = input.nextInt();
totalPointsPossible += pointsPossible[i];
  
input.nextLine();   
}
  
input.close();
DecimalFormat myFormat = new DecimalFormat("#.00%");
  
//formatting output   
System.out.printf("%n%-20s %-10s %-10s%n", "Exercise", "Score", "Total Possible");
System.out.printf("%-20s %-10d %-10d%n", nameOfAssignment[0], pointsEarned[0], pointsPossible[0]);
System.out.printf("%-20s %-10d %-10d%n", nameOfAssignment[1], pointsEarned[1], pointsPossible[1]);
System.out.printf("%-20s %-10d %-10d%n", nameOfAssignment[2], pointsEarned[2], pointsPossible[2]);
System.out.printf("%-20s %-10d %-10d%n", "Total", totalPointsEarned, totalPointsPossible);
  
System.out.print(" Your total is " + totalPointsEarned + " out of " + totalPointsPossible);
System.out.println(", or " + myFormat.format((double)totalPointsEarned / totalPointsPossible) + ".");

}
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote