Question

In: Computer Science

Lab 02 Final Grade Calculator **** I need it in JAVA **** **** write comments with...

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>

  • Sections denote the type of grades, and corresponding grades follow.
  • Each section and grade are separated using the end line character (“\n”).
  • The sections can either be LABS, LAB REPORTS, HOMEWORK, EXAM 1, EXAM 2, or FINAL
  • Labs, Lab Reports, and Homework have multiple grades which need to be averaged. Also, the number of grades for these sections cannot be assumed.
  • Exam 1, Exam 2, and Final only have one grade
  • The sections may appear in any order
  • Here are some files to test: perfectGrades.txt, grades01.txt, grades02.txt

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:

  • Constants (Make sure they’re static)
    • LABS – a String representing the section denoted by “LABS”
    • LAB_REPORTS – a String representing the section denoted by “LAB REPORTS”
    • HOMEWORK – a String representing the section denoted by “HOMEWORK”
    • EXAM01 – a String representing the section denoted by “EXAM 1”
    • EXAM02 – a String representing the section denoted by “EXAM 2”
    • FINAL – a String representing the section denoted by “FINAL”

Class named Student with the following:

  • Instance Variables
    • labSum: a decimal value that is the sum of all labs in a file
    • labCount: a decimal value that is the total number of lab grades in a file
    • labRSum: a decimal value that is the sum of all lab reports in a file
    • labRCount: a decimal value that is the total number of lab report grades in a file
    • hwSum: a decimal value that is the sum of all homework in a file
    • hwCount: a decimal value that it the total number of homework in a file
    • exam01: a decimal value that is the grade for exam 1
    • exam02: a decimal value that is the grade for exam 2
    • finalExam: a decimal value that is the grade for the final
  • Constructors
    • Default: Set all values to 0.0
  • Other Methods
    • getLabAverage: returns the division of labSum and labCount
    • getLabReportAverage: returns the division of labRSum and labRCount
    • getHomeworkAverage: returns the division of hwSum and hwCount
    • getExam01: returns the value of exam01
    • getExam02: returns the value of exam02
    • getFinal: returns the value of finalExam
    • addGrade: this method returns nothing and takes in a String corresponding to the type of grade, and a decimal value that is the grade. If the section is either lab, lab report, or homework then the value is added to the corresponding sum and the corresponding count is increased by 1. However, if the section is any of the exams then the value is assigned to that exam grade.
    • getGradeNumeric: this method returns the raw grade which is calculated by: Lab Average x 10% + Lab Report Average x 10% + Homework Average x 20% + Highest Exam Score x 30% + 2nd Highest Exam Score x 30%.
    • getGradeRounded: this method returns the raw grade rounded up to the nearest whole number. HINT: the Math class has a ceiling method.
    • getGradeLetter: returns a String that corresponds to the earned grade. This is determined by calculating the rounded grade and then returns:
      • A = Grade >= 90%
      • B+ = 90% < Grade >= 85%
      • B = 85% < Grade >= 80%
      • C+ = 80% < Grade >= 75%
      • C = 75% < Grade >= 70%
      • D+ = 70% < Grade >= 65%
      • D = 65% < Grade >= 60%
      • F = 60% < Grade
    • readGradeFile: This method takes in a file name, and then reads and processes the grader file. As stated early, grades are separated by sections and thus are added based on the current section. HINT: Keep track of the current section and add grades based on that current section. When a new section is encountered then switch section.
    • toString: returns a string with the lab average, lab report average, homework average, exam01 grade, exam02 grade, final exam grade, raw grade, rounded grade, and letter grade.

Create class Grader with the following:

  • This is front end meant to create an instance of Student, and provide a means to read a grade file. After it has read the file it should print out the results.

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

Solutions

Expert Solution

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.


Related Solutions

I need the JAVA code for a 4 function calculator app on andriod studio - The...
I need the JAVA code for a 4 function calculator app on andriod studio - The requirements are the following : - The only buttons needed are 0-9, *, /, +, -, a clear, and enter button - Implement the onclicklistener on the main activity - The calcuator should use order of operations (PEMDAS) - It should be able to continue from a previous answer (Ex: If you type 2+6 the calculator will display 8. If you then multiple by...
I need to make a final grade 12 physics presentation about everything that i have learned,...
I need to make a final grade 12 physics presentation about everything that i have learned, it can be anything the question: Describe what you learned in every unit and whether or not you were able to meet those expectations. (E.g. what are some topic(s) in each unit course that you feel you understand well or skills you excelled at?).
write a program to make scientific calculator in java
Problem StatementWrite a program that uses the java Math library and implement the functionality of a scientific calculator. Your program should have the following components:1. A main menu listing all the functionality of the calculator.2. Your program should use the switch structure to switch between various options of the calculator. Your Program should also have the provision to handle invalidoption selection by the user.3. Your calculator SHOULD HAVE the following functionalities. You can add any other additional features. PLEASE MAKE...
Lab 3.4 Write a program that determines a student’s grade. The student will enter a grade...
Lab 3.4 Write a program that determines a student’s grade. The student will enter a grade and the program will determine if that grade is an A, B, C, D, or E. The student can only enter number 0-100. A = 90-100 B = 80-89 C = 70-79 D= 60-69 E = 59 or less Save the file as Lab3.4 and submit the file. Use https://repl.it/ THIS LANGUAGE IS PYTHON Thank you :)
I need to write a final paper for my managed care course. I chose to do...
I need to write a final paper for my managed care course. I chose to do mine on diabetes and managed care as I am a type 1 diabetic. However, I need some ideas for this paper on what to write regarding diabetes and the relation to managed care.
For an organic chemistry lab final report I need to include 1. Discussion of using liquid-liquid...
For an organic chemistry lab final report I need to include 1. Discussion of using liquid-liquid extraction as a method for separating unknown compounds in a mixture, 2. For what functional groups would this method be most useful, and 3. What are some instances where liquid-liquid extraction wouldn't be useful?
For an organic chemistry lab final report I need to include 1. Discussion of using liquid-liquid...
For an organic chemistry lab final report I need to include 1. Discussion of using liquid-liquid extraction as a method for separating unknown compounds in a mixture, 2. For what functional groups would this method be most useful, and 3. What are some instances where liquid-liquid extraction wouldn't be useful?
I need a java code Write a simple program to prompt the user for a number...
I need a java code Write a simple program to prompt the user for a number between 1 and 12 (inclusive) and print out the corresponding month. For example:   The 12th month is December. Use a java "switch" statement to convert from the number (1-12) to the month. Also use a "do while" loop and conditional checking to validate that the number entered is between 1 and 12 inclusive and if not, prompt the user again until getting the correct...
I need to write a java program (in eclipse) that will read my text file and...
I need to write a java program (in eclipse) that will read my text file and replace specific placeholders with information provided in a second text file. For this assignment I am given a text file and I must replace <N>, <A>, <G>, with the information in the second file. For example the information can be John 22 male, and the template will then be modified and saved into a new file or files (because there will be multiple entries...
In Java I need a Flowchart and Code. Write the following method that tests whether the...
In Java I need a Flowchart and Code. Write the following method that tests whether the array has four consecutive numbers with the same value: public static boolean isConsecutiveFour(int[] values) Write a test program that prompts the user to enter a series of integers and displays it if the series contains four consecutive numbers with the same value. Your program should first prompt the user to enter the input size—i.e., the number of values in the series.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT