Develop a program that receives as in input 3 Student names Input (3) test score
ID: 3543775 • Letter: D
Question
Develop a program that receives as in input 3 Student names
Input (3) test scores for each student
Calculate the average grade for each student
Assign a letter grade to each student based on the following: >90 = A, >80 = B, >70 = C, >60 = D, everything else is an F
Calculate the overall average for the class, i.e. for all students taken together
Print out each student's average, their letter grade, and the overall class average
You should use memory, decision, looping and array to solve this.
Explanation / Answer
import java.util.Scanner;
public class Grade
{
public static void main(String args[])
{
Scanner in=new Scanner(System.in);
System.out.println("Enter the first Student name");
String std1=in.nextLine();
System.out.println("Enter the second Student name");
String std2=in.nextLine();
System.out.println("Enter the third Student name");
String std3=in.nextLine();
System.out.println("enter the first student marks");
double[] arr1=new double[3];
double[] arr2=new double[3];
double[] arr3=new double[3];
for(int i=0;i<3;i++){ arr1[i]=in.nextDouble();}
System.out.println("enter the second student marks");
for(int i=0;i<3;i++){ arr2[i]=in.nextDouble();}
System.out.println("enter the third student marks");
for(int i=0;i<3;i++){ arr3[i]=in.nextDouble();}
System.out.println("------------------------------------------");
display(average(arr1),grade(average(arr1)),std1);
display(average(arr2),grade(average(arr2)),std2);
display(average(arr3),grade(average(arr3)),std3);
}
public static double average(double arr[])
{
double average;
average=(arr[0]+arr[1]+arr[2] )/3;
return average;
}
public static String grade(double average)
{
if(average>90)return "A";
else if(average<=90 && average>80)return "B";
else if(average<=80 && average>70) return "C";
else if(average<=70 && average>60) return "D";
else return"F";
}
public static void display(double average,String grade,String name)
{
System.out.println("average of "+name+" ="+average+" Average grade is="+grade);
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.