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 this in java A6 – Shipping Calculator Assignment Introduction In this part, you will...
I need this in java A6 – Shipping Calculator Assignment Introduction In this part, you will solve a problem described in English. Although you may discuss ideas with your classmates, etc., everyone must write and submit their own version of the program. Do NOT use anyone else’s code, as this will result in a zero for you and the other person! Shipping Calculator Speedy Shipping Company will ship your package based on the weight and how far you are sending...
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?).
Question: How do I write a program in C# that calculates a student's final grade for...
Question: How do I write a program in C# that calculates a student's final grade for a test with 20 multiple questions using arrays and helper methods? Instructions: (0-incorrect answer, 1-correct answer) If the student answered the question right, add .5 points to the running total. If the student didn’t answer correctly subtract .5 points from the running total. The running total is initialized with 5 points (so the student receives 5 points extra credit). To define the final grade...
Please use Java language in an easy way with comments! Thanks! Create a calculator that uses...
Please use Java language in an easy way with comments! Thanks! Create a calculator that uses an array of buttons for numbers from 0-9, the . for decimals, and for operators +, -, * ,/ and = as well as a JTextfield that displays the current value or the result. Use ActionListeners and LayoutManagers appropriately. The example below shows how to determine which button has been clicked. ActionListener actionListener = new ActionListener() { public void actionPerformed(ActionEvent actionEvent) { System.out.println(actionEvent.getActionCommand()); }...
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...
I need it in java. Write a program that will print if n numbers that the...
I need it in java. Write a program that will print if n numbers that the user will input are or not within a range of numbers. For that, your program needs to ask first for an integer number called N that will represent the number of times that will ask for other integer numbers. Right after, it should ask for two numbers that will represent the Min and Max for a range. Lastly. it will iterate N number times...
These are reactions I did in my lab. I need to write the molecular, total ionic,...
These are reactions I did in my lab. I need to write the molecular, total ionic, and net ionic reactions for them. Even after watching Khan Academy and using my book, I was still unsure, so I asked the professor and he said every single one was wrong and told me to figure it out. I know this is long, but I would really appreciate it. I need the molecular, total ionic, and net ionic equations for all of them....
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 :)
JAVA PROGRAMMING Hi! I need to create a calculator using do/while loop that calls a menu...
JAVA PROGRAMMING Hi! I need to create a calculator using do/while loop that calls a menu switch where the user choice the calculation type. In the switch each case calls a method to each type of calculation (addition/subtraction/division/multiply/ change set of numbers in the array) those methods sends back the result to be displayed in another method. This application needs to hold the user input's numbers as an array. Thanks for your time. It is a great help!
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT