This assignment is to practice arrays therefore you should u
This assignment is to practice arrays, therefore you should use arrays to read in all data.
Create a program to compute final grades for a class. Professor assigns 10 homework assignment, 2 projects and a final exam. He computes an average for the 10 homework assignments, and an average for the two projects. He then averages those two grades together with the final exam grade to get a final grade for the course. Once again this assignment is to practice arrays, therefore you should use arrays to not only to store the output, but also to read in the project and homework grades.
Print out in a neat chart each student’s id number, homework average, project average, final exam grade and final average.
There are 10 students in the class.
Solution
StudentFinalGrade.java
import java.util.Scanner;
public class StudentFinalGrade {
public static void main(String[] args) {
//Scanner class object is used to read the inputs entered by the user
Scanner sc=new Scanner(System.in);
//Creating the arrays
int homework[]=new int[10];
int projects[]=new int[2];
int hw_sum=0,project_sum=0,tot=0;
int final_exam_grade[]=new int[10];
double avg_hw_project[]=new double[10];
double project_avg[]=new double[10];
double final_average[]=new double[10];
//Getting the 10 students home work marks,project marks,final exam marks
for(int i=0;i<10;i++)
{
System.out.println(\"Student#\"+(i+1));
//This for loop will get the student home work marks
for(int j=0;j<10;j++)
{
//Getting home work marks
System.out.print(\"Home work#\"+(j+1)+\" :\");
homework[j]=sc.nextInt();
//Adding home work marks
hw_sum+=homework[j];
}
//Calculating the average home work marks
avg_hw_project[i]=hw_sum/10;
//Geting the project marks
for(int k=0;k<2;k++)
{
System.out.print(\"Project#\"+(k+1)+\": \" );
projects[k]=sc.nextInt();
//Adding the project marks
project_sum+=projects[k];
}
//Calculating the average project marks
project_avg[i]=project_sum/2;
//Getting the final exam score
System.out.print(\"Enter Student#\"+(i+1)+\" final exam score :\");
final_exam_grade[i]=sc.nextInt();
//Calculating the final average score
final_average[i]=(avg_hw_project[i]+project_avg[i]+final_exam_grade[i])/3;
hw_sum=0;
project_sum=0;
System.out.println(\"__________________________\");
}
//Displaying the student id,home work average,project average,final exam grade,final average in tabular form.
System.out.println(\"Students Id\\tHomeWork Average\\tProject Average\\tFinal Exam Grade\\tFinal Average\");
for(int i=0;i<10;i++)
{
System.out.printf(\"%d\\t\\t%.2f\\t\\t\\t%.2f\\t\\t\\t%d\\t\\t\\t%.2f\\t\ \",(i+1),avg_hw_project[i],project_avg[i],final_exam_grade[i],final_average[i]);
}
}
}
_____________________________________
Output:
Student#1
Home work#1 :67
Home work#2 :78
Home work#3 :76
Home work#4 :77
Home work#5 :88
Home work#6 :98
Home work#7 :87
Home work#8 :76
Home work#9 :65
Home work#10 :56
Project#1: 67
Project#2: 76
Enter Student#1 final exam score :66
__________________________
Student#2
Home work#1 :66
Home work#2 :65
Home work#3 :54
Home work#4 :45
Home work#5 :56
Home work#6 :67
Home work#7 :78
Home work#8 :87
Home work#9 :76
Home work#10 :65
Project#1: 54
Project#2: 56
Enter Student#2 final exam score :67
__________________________
Student#3
Home work#1 :76
Home work#2 :65
Home work#3 :56
Home work#4 :67
Home work#5 :76
Home work#6 :65
Home work#7 :54
Home work#8 :43
Home work#9 :45
Home work#10 :56
Project#1: 67
Project#2: 76
Enter Student#3 final exam score :65
__________________________
Student#4
Home work#1 :56
Home work#2 :67
Home work#3 :78
Home work#4 :87
Home work#5 :76
Home work#6 :65
Home work#7 :54
Home work#8 :45
Home work#9 :56
Home work#10 :67
Project#1: 78
Project#2: 87
Enter Student#4 final exam score :76
__________________________
Student#5
Home work#1 :65
Home work#2 :54
Home work#3 :43
Home work#4 :56
Home work#5 :67
Home work#6 :77
Home work#7 :76
Home work#8 :65
Home work#9 :54
Home work#10 :45
Project#1: 56
Project#2: 67
Enter Student#5 final exam score :76
__________________________
Student#6
Home work#1 :65
Home work#2 :54
Home work#3 :56
Home work#4 :67
Home work#5 :76
Home work#6 :65
Home work#7 :56
Home work#8 :76
Home work#9 :65
Home work#10 :55
Project#1: 67
Project#2: 76
Enter Student#6 final exam score :65
__________________________
Student#7
Home work#1 :56
Home work#2 :67
Home work#3 :76
Home work#4 :65
Home work#5 :55
Home work#6 :78
Home work#7 :88
Home work#8 :87
Home work#9 :76
Home work#10 :67
Project#1: 78
Project#2: 89
Enter Student#7 final exam score :98
__________________________
Student#8
Home work#1 :87
Home work#2 :76
Home work#3 :65
Home work#4 :56
Home work#5 :67
Home work#6 :78
Home work#7 :87
Home work#8 :76
Home work#9 :65
Home work#10 :56
Project#1: 67
Project#2: 78
Enter Student#8 final exam score :87
__________________________
Student#9
Home work#1 :76
Home work#2 :65
Home work#3 :56
Home work#4 :67
Home work#5 :78
Home work#6 :87
Home work#7 :76
Home work#8 :66
Home work#9 :67
Home work#10 :78
Project#1: 87
Project#2: 78
Enter Student#9 final exam score :88
__________________________
Student#10
Home work#1 :87
Home work#2 :76
Home work#3 :65
Home work#4 :56
Home work#5 :67
Home work#6 :78
Home work#7 :88
Home work#8 :87
Home work#9 :76
Home work#10 :67
Project#1: 76
Project#2: 65
Enter Student#10 final exam score :56
__________________________
Students Id HomeWork Average Project Average Final Exam Grade Final Average
1 76.00 71.00 66 71.00
2 65.00 55.00 67 62.33
3 60.00 71.00 65 65.33
4 65.00 82.00 76 74.33
5 60.00 61.00 76 65.67
6 63.00 71.00 65 66.33
7 71.00 83.00 98 84.00
8 71.00 72.00 87 76.67
9 71.00 82.00 88 80.33
10 74.00 70.00 56 66.67
______________________Thank You




