Write a program that calculates the total grade for three cl
Write a program that calculates the total grade for three classroom exercises as a percentage. Use the DecimalFormat class to output the values as a percent. The scores should be summarized in a table. Accept the assignment information in this order:
Name of assignment (may include spaces)
Points earned (integer)
Points possible (integer)
Output should look similar to the following (bold italics indicates input)
Name of Assignment: Group Project Points
Points Earned: 10
Points Possible: 10
Name of Assignment: Homework
Points Earned: 7
Points Possible: 12
Name of Assignment: Presentation
Points Earned: 5
Points Possible: 8
Assignment Pts Earned Pts Possible
Group Project 10 10
Homework 7 12
Presentation 5 8
Total 22 30
Score 73.3%
Solution
import java.text.DecimalFormat;
 import java.util.Scanner;
 public class CalculateGrade
 {
   
    public static void main(String[] args)
    {
        Scanner input = new Scanner(System.in);
        String[] Name of assignment = new String[3];
        int[] Points earned = new int[3];
        int[] Points possible = new int[3];      
        int Total = 0, totalPoints possible = 0;
       
        for(int i = 0; i < 3; i++)
        {
            System.out.println(\"Name of exercise \" + (i + 1) + \":\");
            Name of assignment[i] = input.nextLine();
           
            System.out.println(\"points earned \" + (i + 1) + \":\");
            Points earned[i] = input.nextInt();
            Total += Points earned[i];
           
            System.out.println(\"points possible \" + (i + 1) + \":\");
            Points possible[i] = input.nextInt();
            totalPoints possible += Points possible[i];
           
            input.nextLine();          
        }
       
        input.close();
        DecimalFormat myFormat = new DecimalFormat(\"#.00%\");
       
        //formatting output      
        System.out.printf(\"%n%-20s %-10s %-10s%n\", \"Assignment\", \"pts earned\", \"pts Possible\");
        System.out.printf(\"%-20s %-10d %-10d%n\", Name of assignment[0], Points earned[0], Points possible[0]);
        System.out.printf(\"%-20s %-10d %-10d%n\", Name of assignment[1], Points earned[1], Points possible[1]);
        System.out.printf(\"%-20s %-10d %-10d%n\", Name of assignment[2], Points earned[2], Points possible[2]);
        System.out.printf(\"%-20s %-10d %-10d%n\", \"Total\", Total, totalPoints possible);
       
        System.out.print(\"\ Your total is \" + Total + \" out of \" + totalPoints possible);
        System.out.println(\", or \" + myFormat.format((double)Total / totalPoints possible) + \".\");
   }
 }


