In: Computer Science
Lab 02
Final Grade Calculator
**** I need it in JAVA ****
**** write comments with the code ****
Objective:
Write a program that calculates a final grade! The program should read in a file and then calculates the final grade based on those scores.
Files read into this system are expected to follow this format:
<Section0>\n
<Grade0 for Section0>\n
<Grade1 for Section0>\n
…
<GradeX for Section0>\n
<Section1>\n
<Grade0 for Section1>\n
…
<GradeY for Section1>
<Section2>
…
<SectionZ>
perfectGrades.txt: https://cse.sc.edu/~shephejj/csce146/Labs/GraderFileIO/perfectGrades.txt
grades01.txt: https://cse.sc.edu/~shephejj/csce146/Labs/GraderFileIO/grades01.txt
grades02.txt: https://cse.sc.edu/~shephejj/csce146/Labs/GraderFileIO/grades02.txt
Create the following:
Class named SectionType with the following:
Class named Student with the following:
Create class Grader with the following:
Example Dialog:
Welcome to the Grader Program
Enter a file name or "quit" to exit
grades01.txt
Lab Average: 92.5
Lab Report Average: 90.0
Homework Average: 75.0
Exam 01: 65.0
Exam 02: 75.0
Final Exam: 80.0
Raw Total: 79.75
Adjusted: 80.0
Grade: B
Enter a file name or "quit" to exit
grades02.txt
Lab Average: 94.5
Lab Report Average: 100.0
Homework Average: 92.4
Exam 01: 65.0
Exam 02: 85.0
Final Exam: 90.0
Raw Total: 90.43
Adjusted: 91.0
Grade: A
Enter a file name or "quit" to exit
perfectGrades.txt
Lab Average: 100.0
Lab Report Average: 100.0
Homework Average: 100.0
Exam 01: 100.0
Exam 02: 100.0
Final Exam: 100.0
Raw Total: 100.0
Adjusted: 100.0
Grade: A
Enter a file name or "quit" to exit
quit
Goodbye
Code
import java.util.Scanner;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
class SectionType
{
public static String LABS="LABS";
public static String LAB_REPORTS="LAB REPORTS";
public static String HOMEWORK="HOMEWORK";
public static String EXAM01="EXAM 1";
public static String EXAM02="EXAM 2";
}
class Student
{
private int
labSum,labCount,labRSum,labRCount,hwSum,hwCount,exam01,exam02,finalExam;
public Student()
{
labSum=0;labCount=0;labRSum=0;labRCount=0;hwSum=0;hwCount=0;exam01=0;exam02=0;finalExam=0;
}
public void readGradeFile(String FileName)
{
BufferedReader reader;
try
{
String regex = "\\d+";
reader = new BufferedReader(new FileReader(FileName));
String sec;
String line = reader.readLine();
sec=line;
line = reader.readLine();
while (line != null)
{
if(line.matches(regex))
addGrade(sec, Integer.parseInt(line));
else
sec=line;
line = reader.readLine();
}
reader.close();
} catch (IOException e)
{
System.out.println(FileName+" not found!!\n");
}
}
public double getLabAverage()
{
return labSum/labCount;
}
public double getLabReportAverage()
{
return labRSum/labRCount;
}
public double getHomeworkAverage()
{
return hwSum/hwCount;
}
public int getExam01()
{
return exam01;
}
public int getExam02()
{
return exam02;
}
public int getFinal()
{
return finalExam;
}
public double getGradeNumeric()
{
double higestExamScore;
if(getExam01()>getExam02())
higestExamScore=getExam01();
else
higestExamScore=getExam02();
return
(getLabAverage()*0.1+getLabReportAverage()*0.1+getHomeworkAverage()*0.2+higestExamScore*0.3+getFinal()*0.3);
}
public double getGradeRounded()
{
return Math.ceil(getGradeNumeric());
}
public String getGradeLetter()
{
double grade=getGradeRounded();
if(grade>=90)
return "A";
else if(grade>=85 && grade<90)
return "B+";
else if(grade>=80 && grade<85)
return "B";
else if(grade>=75 && grade<80)
return "C+";
else if(grade>=70 && grade<75)
return "C";
else if(grade>=65 && grade<70)
return "D+";
else if(grade>=60 && grade<65)
return "D";
return "F";
}
@Override
public String toString()
{
String str="";
str+="Lab Average: "+getLabAverage()+
"\nLab Report Average: "+getLabReportAverage()+
"\nHomework Average: "+getHomeworkAverage()+
"\nExam 01: "+getExam01()+
"\nExam 02: "+getExam02()+
"\nFinal Exam: "+getFinal()+
"\nRaw Total: "+getGradeNumeric()+
"\nAdjusted: "+getGradeRounded()+
"\nGrade: "+getGradeLetter();
return str;
}
public void addGrade(String sec,int grade)
{
if(sec.equals(SectionType.LABS))
{
labSum+=grade;
labCount++;
}
else if(sec.equals(SectionType.LAB_REPORTS))
{
labRSum+=grade;
labRCount++;
}
else if(sec.equals(SectionType.HOMEWORK))
{
hwSum+=grade;
hwCount++;
}
else if(sec.equals(SectionType.EXAM01))
{
exam01+=grade;
}
else if(sec.equals(SectionType.EXAM02))
exam02+=grade;
else
finalExam+=grade;
}
}
public class Grader
{
public static void main(String[] args)
{
Scanner sc=new Scanner(System.in);
String filename;
System.out.println("Welcome to the Grader Program");
while(true)
{
System.out.println("Enter a file name or \"quit\" to exit");
filename=sc.next();
if(filename.equalsIgnoreCase("quit"))
break;
else
{
Student s1=new Student();
s1.readGradeFile(filename);
System.out.println(s1);
}
}
}
}
outputa
If you have any query regarding the code please ask me in the
comment i am here for help you. Please do not direct thumbs down
just ask if you have any query. And if you like my work then please
appreciates with up vote. Thank You.