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

Verified

Added on  2022/08/15

|3
|357
|17
Practical Assignment
AI Summary
This document presents a solution for a practical assignment involving a Java program designed to calculate a student's grade based on input marks. The program takes marks for four subjects, calculates the average, and then assigns a grade (A, B, C, or D) based on the average score. The document includes the Java code, a trace table demonstrating the program's execution step-by-step, and a description of the program's functionality. The assignment brief outlines the requirements for the practical project, including the need to create files for each exercise, complete the analysis, write pseudocode, and construct a trace table. This particular solution focuses on exercise 47 from the provided list of questions. The project emphasizes teamwork and requires students to submit their work in a compressed .zip file.
Document Page
Question 47: Program for grade
import java.util.Scanner;
public class Grade
{
public static void main(String args[])
{
int marks[] = new int[4];
int i;
float total=0, avg;
Scanner scanner = new Scanner(System.in);
for(i=0; i<4; i++) {
System.out.print("Enter Marks of Subject"+(i+1)+":");
marks[i] = scanner.nextInt();
total = total + marks[i];
}
scanner.close();
avg = total/6;
System.out.print("The student Grade is: ");
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
if(avg>=80)
{
System.out.print("A");
}
else if(avg>=60 && avg<80)
{
System.out.print("B");
}
else if(avg>=40 && avg<60)
{
System.out.print("C");
}
else
{
System.out.print("D");
}
}
}
Trace table
Ste Statement Notes marks[] total avg
Document Page
p
1 marks[]=int[4]; Initialise the value of
the array size
marks[]=int[4].
? ? ?
2 total=0; Initialise the value of
total=0.
? 0 ?
3 for(i=0;i<4;i++)
{marks[i]={98,84,76,9
4};
Start the for loop and
store the value of
marks[i]={98,84,76,9
4}.
{98,84,76,94} 0 ?
4 total = total + marks[i]; Calculate the value of
total by the equation
of
total=total+marks[i].
{98,84,76,94} 352 ?
5 avg = total/4; Calculate the value of
avg=total/4.
{98,84,76,94} 352 88
6 if(avg>=80)
{ System.out.print("A"
);}
if (avg>=80) then
System.out.print("A");
}
chevron_up_icon
1 out of 3
circle_padding
hide_on_mobile
zoom_out_icon
[object Object]