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

This is the homeword requirement and my solution: Please fix if you understand j

ID: 3663462 • Letter: T

Question

This is the homeword requirement and my solution: Please fix if you understand java. I even posted the response my teacher stated.

Posted on: Tuesday, January 12, 2016 8:00:00 PM EST

This HW is based on programming projects (PPs) # 1 and # 3 from Chapter 5 (p. 371 & p. 372) of your text.

Use the following list of scores for 10 students.

Student ID

Quiz # 1

Quiz # 2

Midterm Exam

Final Exam

A1

8

8.5

84

82

B2

3

7

0

99

C3

10

9.5

92

84

D4

8

8

89

86

E5

9

10

83

91

F6

7.5

8.5

88

69

G7

8.5

0

81

52

H8

6

8.5

79

68

I9

7.5

6

72

91

J10

7

6.5

58

77

1.      Put the above data in a text file with 10 rows of data. Each row has 5 elements as depicted above. Name the file “scores.txt.”

2.    Instantiate a "ClassGrade" object; update the object as the file is being read, line-by-line.

3.      Use the grading policy described in PP # 1 to determine the following: a) the highest score for Quiz # 1, b) the lowest score for Quiz # 2, c) midterm average, and d) final letter grades for all students.

4.      Remember this is an OOP assignment; not a procedural programming HW.

5.    Submit your source code and the input data in email.

pg/ 372

Here is my solution:

// ClassGrade

import java.util.ArrayList;
import java.io.*;
public class ClassGrade {
  
   private static final String[] Stu = null;
   private ArrayList<Student> theClass;
   private ClassGrade readFile;
   private Student stu;
  
   public ClassGrade() {
       this.theClass = new ArrayList<Student>();
       this.setStu(new Student(null, 0, 0, 0, 0));
       }
  
  
   public void readFile() {
       //1. Inside a try/catch block, set up our BufferedReader
       //2. Set up a loop that will read the file until no lines are available
       //3. Inside that loop, read one line, split it into parts, and use the Student constructor to create a new Student
       //4. Add that student to the ArrayList.
              
              
       try {

           BufferedReader br = new BufferedReader(new FileReader("scores.txt"));
           String ourLine;
           while((ourLine = br.readLine()) != null) {
               String[] separatedLine = ourLine.split(" ");
               Student newStudent = new Student(separatedLine[0],Double.parseDouble(separatedLine[1]),Double.parseDouble(separatedLine[2]),Double.parseDouble(separatedLine[3]),Double.parseDouble(separatedLine[4]));
               this.theClass.add(newStudent);
           }
  
           br.close();
       }
  
           catch(IOException e) {
           e.printStackTrace();
           }
   }
  
           public Student highestQuiz1() {
               double currentMax = -1;
               Student bestStudent = this.theClass.get(0);
  
               for(int i = 0 ; i < this.theClass.size() ; i++) {
                   if(this.theClass.get(i).getquiz1() >= currentMax) {
                       currentMax = theClass.get(i).getquiz1();
                       bestStudent = theClass.get(i);
                   }
               }
  
               return bestStudent;
           }
  
           public Student lowestQuiz2() {
               double currentMin = 1000;
               Student worstStudent = this.theClass.get(0);
  
               for(int i = 0 ; i < this.theClass.size() ; i++) {
                   if(theClass.get(i).getquiz1() <= currentMin) {
                       currentMin = theClass.get(i).getquiz2();
                       worstStudent = theClass.get(i);
                   }
               }
  
               return worstStudent;
           }
  
           public double getMidtermAverage() {
               double average = 0;
  
               for(int i = 0 ; i < this.theClass.size() ; i++) {
                   average += this.theClass.get(i).getmidterm();
               }
  
               return average / this.theClass.size();
           }
  
           public void finalLetterGrades() {
               for(int i = 0 ; i < this.theClass.size() ; i++) {
                   String line = this.theClass.get(i).getID() + " : ";
                   double finalGrade = this.theClass.get(i).getfinal()*0.5 + this.theClass.get(i).getmidterm()*0.25 + (this.theClass.get(i).getquiz1()/10 + this.theClass.get(i).getquiz2()/10)*0.25;
                   if(finalGrade<60) line += "F";
                   else if(finalGrade<70) line += "D";
                   else if(finalGrade<80) line += "C";
                   else if(finalGrade<90) line += "B";
                   else line += "A";
  
                   System.out.println(line + " " + finalGrade);
               }
  
           }
           public static void main(String[] args) {
               ClassGrade grades = new ClassGrade();
               grades.setReadFile(new ClassGrade());
               System.out.println("The highest score in Quiz 1 is :"
                       + grades.highestQuiz1().getquiz1() + " out of 10 points,"
                       + " or " + grades.highestQuiz1().getquiz1() / 10 * 100 +"%");
               System.out.println("The lowest score in Quiz 2 is :"
                       + grades.lowestQuiz2().getquiz2() + " out of 10 points, or "
                       + grades.lowestQuiz2().getquiz2() / 10 * 100 +"%");
               System.out.println("The midterm average is: "+grades.getMidtermAverage()+"%");
               System.out.println("The final grades are:");
               grades.finalLetterGrades();
           }
           public ClassGrade getReadFile() {
               return readFile;
           }
           public void setReadFile(ClassGrade readFile) {
               this.readFile = readFile;
}

           public static String[] getStu() {
               return Stu;
           }

           public void setStu(Student stu) {
               this.stu = stu;
           }
}
  

// Student class

public class Student {

private String studentID;
private Student stu[] = new Student[10];
private double quiz1,quiz2,midterm,finalGrade;
  
public Student(String ID, double Q1, double Q2, double mid, double fin){
this.studentID = ID;
this.quiz1 = Q1;
this.quiz2 = Q2;
this.midterm = mid;
this.finalGrade = fin;
this.setquiz1(quiz1);
}
  
   public String getID() {
return this.studentID;
}
  
public double getquiz1(){
return this.quiz1;
}
  
public double getquiz2() {
return this.quiz2;
}
  
  
public double getmidterm() {
return this.midterm;
}

public double getfinal() {
return this.finalGrade;
}
  
public void setStudentID(String ID) {
this.studentID = ID;
}

public void setquiz1(double quiz1) {
this.quiz1 = quiz1;
}
  
public void setquiz2(double quiz2){
this.quiz2 = quiz2;
}
  
public void setmidterm(double midterm){
this.midterm = midterm;
}
  
public void setfinal(double finalGrade){
this.finalGrade = finalGrade;
}

   public Student[] getStu() {
       return stu;
   }

   public void setStu(Student stu[]) {
       this.stu = stu;
   }

}

//text file

A1 8 8.5 84 82
B2 3 7 0 99
C3 10 9.5 92 84
D4 8 8 89 86
E5 9 10 83 91
F6 7.5 8.5 88 69
G7 8.5 0 81 52
H8 6 8.5 79 68
I9 7.5 6 72 91
J10 7 6.5 58 77

My Teacher's comments on how to fix this program:

Use java programming and run the program: Exception in thread "main" java.lang.IndexOutOfBoundsException: Index: 0, Size: 0 at java.util.ArrayList.rangeCheck(Unknown Source) at java.util.ArrayList.get(Unknown Source) at ClassGrade.highestQuiz1(ClassGrade.java:43) at ClassGrade.main(ClassGrade.java:97) Study the file below. Once you understand, rewrite & resubmit.

import java.util.Scanner; import java.io.File; import java.io.FileNotFoundException; public class driver { public static void main(String[] args) { // String fileName = "scores.txt"; Scanner inputStream = null; try { inputStream = new Scanner(new File(fileName)); } catch(FileNotFoundException e) { System.out.println("Error opening the file " + fileName); System.exit(0); } //declarations ClassGrade myClass = new ClassGrade(); String currentStudent = ""; double q1, q2, mid, fin, totalMid = 0; char grade = ' '; int n = 0; // while (inputStream.hasNextLine()) { currentStudent = inputStream.next(); q1 = inputStream.nextDouble(); q2 = inputStream.nextDouble(); mid = inputStream.nextDouble(); fin = inputStream.nextDouble(); // totalMid = totalMid + mid; n++; grade = ClassGrade.finalGrade(q1,q2,mid,fin); // myClass.setStudentGrade(currentStudent, grade, n); if (q1>myClass.getHighestQuiz1()) myClass.setHighestQuiz1(q1); if (q2

Student ID

Quiz # 1

Quiz # 2

Midterm Exam

Final Exam

A1

8

8.5

84

82

B2

3

7

0

99

C3

10

9.5

92

84

D4

8

8

89

86

E5

9

10

83

91

F6

7.5

8.5

88

69

G7

8.5

0

81

52

H8

6

8.5

79

68

I9

7.5

6

72

91

J10

7

6.5

58

77

Explanation / Answer

import java.util.*;
import java.io.*;
public class StudentGradeSystem {

public static void main(String arguments[]) throws IOException {
String stdNam;
double stdScor, stdTotalScore, q1HighGrade, q2LowGrade, sum;
double average;
double MidTermaverage = -1;
System.out.println("These r the student scores from the text-file.");
System.out.println(" Implotant : All student scores are out of 100%. ");
Scanner fileInput = new Scanner(new File("stdScores.txt"));
while (fileInput.hasNext()) {
stdNam = fileInput.next();
System.out.print(stdNam);
stdScore = 0;
stdTotalScore = 0;
q1HighGrade=0;
q2LowGrade=0;
sum = 0;
for (int i = 0; i < 4; i++) {
stdScore = fileInput.nextDouble();
if (stdScore <= 10){
stdScore=stdScore*10;
}
System.out.print(" " + stdScore);
q1HighGrade=
stdTotalScore = stdTotalScore + stdScore;
sum++;
}
average = stdTotalScore / sum;
System.out.print(" Total Grade Average: " + average + " Grade: ");
gradeDisplay(average);
fileInput.close();
}
public static void gradeDisplay( double average ) {
if ( average >= 90 ) {
System.out.println( " A " );
} else if ( average >= 80 ) {
System.out.println( " B " );
} else if ( average >= 70 ) {
System.out.println( " C " );
} else if ( average >= 60 ) {
System.out.println( " D " );
} else{
System.out.println( " F " );
}
}
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote