Question: i need to fix my program, this is what i need to do Use the Student.java and Students.java classes from the course website to represent

i need to fix my program, this is what i need to do

Use the Student.java and Students.java classes from the course website to represent and process student records and modify them accordingly:

The encapsulation principle must be strictly enforced.

****The main method in class Students should only read the text file, and print student records (student names, grade and grade type) and statistics (number of students and averages) using methods of class Student.

All counting, totaling, computing averagas, checking grade intervals, and assigning grade types to students should be implemented in class Student. Hints: use static variables in class Student and add methods to compute and return (or print) averages. Modify the toString() method to return the grade type too.

When you write your program

use proper names for the variables suggesting their purpose.

format your code accordingly using indentation and spacing.

use multiple line comment in the beginning of the code and write your name, e-mail address, class, and section.

for each line of code add a short comment to explain its meaning.

Extra credit (2 points): The program also prints the student with the highest and the student with the lowest grade.

This is what i have

import java.io.*; import java.util.*; public class Students { public static void main (String[] args) throws IOException { String first_name, last_name; int grade; double avg = 0; String comment = " "; double eGrade,oGrade,fGrade; int eCount,oCount,fCount,s,highest,lowest;//counts the number of excellent, ok , failure, average, highest, lowest highest = 0; lowest = 101; String hname,lname; hname=lname = " "; eGrade = oGrade= fGrade=eCount=oCount=fCount=s=0; Scanner fileInput = new Scanner(new File("students.txt"));//specify the location of the code while (fileInput.hasNext()) { first_name = fileInput.next(); last_name = fileInput.next(); grade = fileInput.nextInt();

Student st = new Student(first_name, last_name, grade); grade = st.getGrade(); if(grade > highest)//finds the student with the highest grade { highest = grade; hname = first_name+" "+last_name; } if(grade < lowest)//find the student with the lowest grade { lowest = grade; lname = first_name+" "+last_name; }

if(grade>=89)//prints the student is excellent if grade is higher than 89 { comment = "Excellent"; eCount++; eGrade = eGrade +grade; } else if(grade>=60 && grade <=89)//prints the students is okey it the grade is between 60 and 89 { comment = "ok"; oCount++; oGrade = oGrade +grade; } else if(grade<60)//prints the student is failing if the grade is less than 60 { comment = "failure"; fCount++; fGrade = fGrade +grade; }

System.out.println(st + " " + comment);//finds the average s++; avg = avg+grade; } System.out.printf(" There are %d students with average grade %.2f",s,(avg/s));//prints out the average grade of all students together System.out.printf(" There are %d excellent student with average grade %.2f ", eCount,(eGrade/eCount));//prints out the student with the excellent grade System.out.printf(" There are %d ok with average grade %.2f", oCount,(oGrade/oCount));//prints out the students with the okey grade System.out.printf(" There are %d failure with average grade %.2f " ,fCount,(fGrade/fCount));//prints the number of students failing System.out.println(" "+hname+" score highest grade ="+highest);//prints out student highest grade System.out.println(" "+lname +" score lowest grade ="+lowest);//prints out student with lowest grade

} }

second part

public class Student { private String fname, lname; private int grade;

public Student(String fname, String lname, int grade) { this.fname = fname; this.lname = lname; this.grade = grade;

}

public int getGrade() { return grade; }

public String toString() { return fname + " " + lname + "\t" + grade;

} }

and this is what i get

John Smith 90 Excellent Barack Obama 95 Excellent Al Clark 80 ok Sue Taylor 55 failure Ann Miller 75 ok George Bush 58 failure John Miller 65 ok

There are 7 students with average grade 74.00 There are 2 excellent student with average grade 92.50 There are 3 ok with average grade 73.33 There are 2 failure with average grade 56.50 Barack Obama score highest grade =95

Sue Taylor score lowest grade =55

so i get what am suppose to get right but the proffessor wants me to separate it and i dont know how

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!