Write a progtram that calculates the total grade for three classroom exercises a
ID: 3747685 • Letter: W
Question
Write a progtram that calculates the total grade for three classroom exercises as a percentage. Use the DecimalFormat class to output the value as a percent. The score 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 he total points possible. Sample input and output is shown as follows:
Name of exercise 1:
Group Project
Score received for exercise 1:
10
Total points possible for exercise 1:
10
Name of exercise 2:
Homework
Score received for exercise 2
7
Total points possible for exercise 2:
12
Name of exercise 3:
Presentation
Score received for exercise 3:
5
Total points possible for exercise 3:
8
Exercise Score Total Possible
Group Project 10 10
Homework 7 12
Presentation 5 8
Total 22 30
Explanation / Answer
Exercises.java
import java.text.DecimalFormat;
import java.util.Scanner;
public class Exercises {
public static void main(String[] args) {
int ex[]=new int[3];
int aex[]=new int[3];
String nex[]=new String[3];
int tot=0,atot=0;
//DecimalFormat class is used to format the output
DecimalFormat df=new DecimalFormat("#.##");
/*
* Creating an Scanner class object which is used to get the inputs
* entered by the user
*/
Scanner sc = new Scanner(System.in);
for(int i=0;i<3;i++)
{
//Getting the input entered by the user
System.out.print("Name of exercise "+(i+1)+":");
nex[i]=sc.nextLine();
System.out.print("Score received for exercise "+(i+1)+":");
ex[i]=sc.nextInt();
System.out.print("Total points possible for exercise "+(i+1)+":");
aex[i]=sc.nextInt();
sc.nextLine();
}
System.out.println("Exercise Score Total Possible");
for(int i=0;i<3;i++)
{
System.out.printf("%10s %d %d ",nex[i],ex[i],aex[i]);
tot+=ex[i];
atot+=aex[i];
}
System.out.println("Total "+tot+" "+atot);
System.out.println("Percentage :"+df.format(((double)tot/atot)*100)+"%");
}
}
________________
Output:
Name of exercise 1:Group Project
Score received for exercise 1:10
Total points possible for exercise 1:10
Name of exercise 2:Homework
Score received for exercise 2:7
Total points possible for exercise 2:12
Name of exercise 3:Presentation
Score received for exercise 3:5
Total points possible for exercise 3:8
Exercise Score Total Possible
Group Project 10 10
Homework 7 12
Presentation 5 8
Total 22 30
Percentage :73.33%
_______________Could you plz rate me well.Thank You
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.