Write a program that determines the letter grade each student in a class receive
ID: 3764687 • Letter: W
Question
Write a program that determines the letter grade each student in a class receives. The program should read the list of student names, first exam scores, midterm exam scores, and final exam scores from a file. The final grade is determined by taking 20% of the first exam, 30% of the midterm exam, and 50% of the final exam. The program should print to the screen the student’s name and the letter grade they should receive for the course. Use a value-returning function to determine the letter grade. Letter Grades should be determined according to the following: Grading Scale:
100 – 90%……….A
89 - 80%……….B
79 - 70%……….C
Explanation / Answer
import java.io.BufferedReader;
import java.io.FileReader;
import java.util.Iterator;
import java.util.Map;
import java.util.HashMap;
import java.util.ArrayList;
import java.util.Set;
import java.awt.Font;
import java.awt.Graphics;
public class Data {
public static void main(String args[]){
try{
BufferedReader br=new BufferedReader(new FileReader("data.txt"));
String line=br.readLine();
int marks1=0;
int marks2=0;
int marks3=0;
String name="";
while(line!=null)
{
String array[]=line.split(" ");
int i=0;
if(i<array.length){
name=array[i];
marks1=Integer.parseInt(array[++i]);
marks2=Integer.parseInt(array[++i]);
marks3=Integer.parseInt(array[++i]);
}
line=br.readLine();
if(((((20*marks1)/100+(30*marks2/100)+(50*marks3/100))/(marks1+marks2+marks3))*100)>=90 &&((((20*marks1)/100+(30*marks2/100)+(50*marks3/100))/(marks1+marks2+marks3))*100)<=100)
{
System.out.println(name+": A");
}
else if(((((20*marks1)/100+(30*marks2/100)+(50*marks3/100))/(marks1+marks2+marks3))*100)>=80 &&((((20*marks1)/100+(30*marks2/100)+(50*marks3/100))/(marks1+marks2+marks3))*100)<=89)
{
System.out.println(name+": B");
}
else if(((((20*marks1)/100+(30*marks2/100)+(50*marks3/100))/(marks1+marks2+marks3))*100)>=70 &&((((20*marks1)/100+(30*marks2/100)+(50*marks3/100))/(marks1+marks2+marks3))*100)<=79)
{
System.out.println(name+": C");
}
else if(((((20*marks1)/100+(30*marks2/100)+(50*marks3/100))/(marks1+marks2+marks3))*100)>=60 &&((((20*marks1)/100+(30*marks2/100)+(50*marks3/100))/(marks1+marks2+marks3))*100)<=69)
{
System.out.println(name+": C");
}
else if(((((20*marks1)/100+(30*marks2/100)+(50*marks3/100))/(marks1+marks2+marks3))*100)>=50 &&((((20*marks1)/100+(30*marks2/100)+(50*marks3/100))/(marks1+marks2+marks3))*100)<=59)
{
System.out.println(name+": D");
}
else
{
System.out.println(name+": E");
}
}
}
catch (Exception e) {
System.out.println(e);
}
}
}
// Please note you did not mention logic to calculate percentage like total maximum marks. So I have used what I feel right. If you want any different logic then mention in comments. Only need to change in one line.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.