420-D01-SU Practical Project 2 - Average Grade Calculation Program

Verified

Added on  2022/08/15

|3
|306
|22
Practical Assignment
AI Summary
This assignment solution addresses the problem of calculating the average of a series of grades, specifically focusing on the requirements of Practical Project 2 (420-D01-SU). The solution includes a complete Java program designed to calculate the average of a specified number of grades, as outlined in the assignment brief. The program prompts the user to input the number of grades and then iteratively takes each grade as input. It then calculates the sum of all grades and computes the average. The solution also features a detailed step-by-step analysis, pseudocode, and a trace table demonstrating the program's execution and variable states. This comprehensive approach ensures a clear understanding of the algorithm's logic and functionality, making it a valuable resource for students studying computer science and algorithm design. The document is contributed by a student on Desklib, a platform providing AI-based study tools.
Document Page
Question 39: Program for calculating average of 1000 grades
import java.util.Scanner;
class Calc
{
public static void main (String args[])
{
int i;
double total=0;
double avg;
System.out.println ("How many numbers you want to enter :");
Scanner sc = new Scanner (System.in);
int n= sc.nextInt ();
double [] marks=new double[n];
for (i=0; i<marks.length; i++) {
System.out.println ("Enter the element number "+ (i+1) +": ");
marks [i] = sc.nextDouble ();
}
sc.close ();
for (i=0; i<marks.length; i++) {
tabler-icon-diamond-filled.svg

Paraphrase This Document

Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser
Document Page
total= total+marks[i];
}
avg = total/marks.length;
System.out.format ("The average of the grade is: %.3f", avg);
}
}
Step Statement Notes total n marks[] avg
1 total=0; Initialise the value of
total=0.
0 ? ? ?
2 n=2; Initialise the value of
n=2.
0 2 ? ?
3 marks[]={98,86} Add the value of array
marks[]={98,86}.
0 2 {98,86} ?
4 for(i=0;i<marks.length;
i++)
Start the for loop until
the i<marks.length.
0 2 {98,86} ?
5 total=total+marks[i]; calculate the value of
total by the equation of
total=total+marks[i].
184 2 {98,86} ?
6 avg=total/marks.length; calculate the value of
avg by the equation of
avg=total/marks.length;
184 2 {98,86} 92
7 System.out.println(avg) Print the value of avg.
Trace table
Document Page
chevron_up_icon
1 out of 3
circle_padding
hide_on_mobile
zoom_out_icon
[object Object]