Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

NEEDS TO BE WRITTEN IN GROOVY, USING OBJECT ORIENTED PROGRAMMING Problem : Suppo

ID: 3810278 • Letter: N

Question

NEEDS TO BE WRITTEN IN GROOVY, USING OBJECT ORIENTED PROGRAMMING

Problem : Suppose at the end of the semester, there is a file "scores.dat" recording scores each student has earned so far from closed lab assignments (CLA), open lab assignments (OLA), quizzes, exams, and final exam score. You can assume there are no more than 30 students. The final letter grade is decided according to the following table based on the total points they have earned:

Total Points

Final Letter Grade

Total Points

Final Letter Grade

>=90

A

>=70, but <73

C-

>=87, but <90

B+

>=67, but <70

D+

>=83, but <87

B

>=63, but <67

D

>=80, but <83

B-

>=60, but <63

D-

>=77, but <80

C+

<60

F

>=73, but <77

C

In this assignment, you are asked to write a program to calculate student final letter grades as well as the average and highest scores of CLA, OLA, quizzes, exams, and final exam scores. The final result should be printed to the screen (standard output).

Requirements:

At the beginning of the program, your program should give the user a prompt for the name of the data file which contains the records of student grades.

Define a class Student, which includes student id, scores for CLA, OLA, quizzes, exams, final scores, total points, and letter grade. All member data must be private. The class must provide a function to calculate the final letter grade.

Store all Student objects in an associative array (other similar data structures like map, hash map are also fine) so that we can lookup student final letter grade by C#.

Your program should allow users to perform two queries. For each query, the user inputs C#, and your program should print all information (including his/her final letter grade) of the student with the given C#. After two queries, your program print information of all students on the screen.

If the language doesn’t support object-oriented programming or associative array, then use appropriate data structures.

If the language doesn’t support file input, you can store them in your program.

Make sure that your program has the proper documentation (program heading, variable explanation, description/input/output for each user defined function, explanation for logically related statements, etc), and style for good program readability and modifiability. Refer to the back page for more details on program requirements your program should follow.

this is the file:

C# CLA OLA Quiz Exam FinalExam
c1234501 10 20    10 30 30
c1234502 9 10 5 20 20
c1234503 10 17 8 27 27
c1234504 8 14 10 29 15
c1234505 7 18 3 24 27
c1234506 8 16 9 13 14
c1234507 6 11 5 27 26
c1234508 8 15 9 17 28
c1234509 5 19 8 28 29
c1234510 9 14 6 19 19
c1234511 2 6 4 17 19
c1234512 7 18 7 22 25
c1234513 4 10 9     11 19
c1234514 8 18 8 24 19
c1234515 7 13 7 20 20
c1234516 10 19 9 19 19
c1234517 8 10 9 19 24
c1234518 6 11 7 23 25
c1234519 4 8 4 19 20
c1234520 9 15 9 22 24
c1234521 10 13 10 20 30
c1234522 10 12 10 25 25

Total Points

Final Letter Grade

Total Points

Final Letter Grade

>=90

A

>=70, but <73

C-

>=87, but <90

B+

>=67, but <70

D+

>=83, but <87

B

>=63, but <67

D

>=80, but <83

B-

>=60, but <63

D-

>=77, but <80

C+

<60

F

>=73, but <77

C

Explanation / Answer

import java.io.FileNotFoundException;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Scanner;

public class Driver {
   static Scanner scanner = new Scanner(System.in);
   public static void main(String[] args) {
       ;
       Map<String, Student> map = readInput("scores.dat");
       while(true){
           int choice =getChoice();
           if(choice==1){
               System.out.println("Enter Student ID(C#):");
               String id = scanner.next();
               Student stu = getStudent(map, id);
               if(stu != null)
                   System.out.println(stu);
               else
                   System.out.println("Not found!");
           }
           if(choice ==2){
               printAllStudents(map);
           }
           if(choice == 3)
               break;
       }
   }
   public static void printAllStudents(Map<String, Student> map){
       for (Entry<String, Student> entry : map.entrySet())
       {
       System.out.println(entry.getValue());
       }
   }
   public static Student getStudent(Map<String, Student> map, String id){
       Student stu = null;
       stu = map.get(id);
       return stu;
   }
   public static int getChoice(){
       int choice = -1;
       while(true){
           System.out.println("[1] Get One Student Information");
           System.out.println("[2] Get All Students Information");
           System.out.println("[3] Exit");
           System.out.println("Enter Your Choice :");
           choice = scanner.nextInt();
           if(choice>0 && choice <4){
               break;
           }
           else{
               System.out.println("Invalid Input");
               continue;
           }
       }
       return choice;
   }
   public static Map<String, Student> readInput(String file){
       Map<String, Student> map = new HashMap<>();
       try{
           Scanner sc = new Scanner(new java.io.File(file));
           while(sc.hasNext()){
               Student stu = new Student(sc.next(), sc.nextInt(), sc.nextInt(), sc.nextInt(), sc.nextInt(), sc.nextInt());
               map.put(stu.getId(), stu);
           }
           sc.close();
       }catch(FileNotFoundException e){
           e.printStackTrace();
       }
       return map;
   }

}

public class Student {
  
   private String id;
   private int CLAScore;
   private int OLAScore;
   private int quizScore;
   private int examScore;
   private int finalExamScore;
   private int totalPoint;
   private String grade;
  
   public Student(String id,int claScore, int olaScore, int quizScore, int examScore,int finalExamSore){
       this.setId(id);
       this.setCLAScore(claScore);
       this.setOLAScore(olaScore);
       this.setQuizScore(quizScore);
       this.setExamScore(examScore);
       this.setFinalExamScore(finalExamSore);
       this.setTotalPoint(calculateTotalPoint());
       this.setGrade(calculateGrade());
   }
  
   public String toString(){
       String str ="";
       str += "Student ID : "+getId()+" ";
       str += " CLA :"+getCLAScore()+" ";
       str += " OLA :"+getOLAScore()+" ";
       str += " Quiz Score :"+getQuizScore()+" ";
       str += " Exam Score :"+getExamScore()+" ";
       str += " Final Exam :"+getFinalExamScore()+" ";
       str += " Total Point :"+getTotalPoint()+" ";
       str += " Grade : "+getGrade()+" ";
       return str;
   }
   private int calculateTotalPoint(){
       return getCLAScore()+
               getOLAScore()+
               getQuizScore()+
               getExamScore()+
               getFinalExamScore();
   }
   private String calculateGrade(){
       String g = "F";
       int total = getTotalPoint();
       if(total>=90)
           g = "A";
       else if(total>=87 && total < 90)
           g = "B+";
       else if(total>=83 && total < 87)
           g = "B";
       else if(total>=80 && total < 83)
           g = "B-";
       else if(total>=77 && total < 80)
           g = "C+";
       else if(total>=73 && total < 77)
           g = "C";
       else if(total>=70 && total < 73)
           g = "C-";
       else if(total>=67 && total < 70)
           g = "D+";
       else if(total>=63 && total < 67)
           g = "D";
       else if(total>=60 && total < 63)
           g = "D-";
       else
           g = "F";
      
       return g;
   }
   public int getCLAScore() {
       return CLAScore;
   }

   public void setCLAScore(int cLAScore) {
       CLAScore = cLAScore;
   }

   public int getOLAScore() {
       return OLAScore;
   }

   public void setOLAScore(int oLAScore) {
       OLAScore = oLAScore;
   }

   public int getQuizScore() {
       return quizScore;
   }

   public void setQuizScore(int quizScore) {
       this.quizScore = quizScore;
   }

   public int getExamScore() {
       return examScore;
   }

   public void setExamScore(int examScore) {
       this.examScore = examScore;
   }

   public int getFinalExamScore() {
       return finalExamScore;
   }

   public void setFinalExamScore(int finalExamScore) {
       this.finalExamScore = finalExamScore;
   }

   public int getTotalPoint() {
       return totalPoint;
   }

   public void setTotalPoint(int totalPoint) {
       this.totalPoint = totalPoint;
   }

   public String getGrade() {
       return grade;
   }

   public void setGrade(String grade) {
       this.grade = grade;
   }

   public String getId() {
       return id;
   }

   public void setId(String id) {
       this.id = id;
   }
}