i need to fix my program, this is what i need to do Use the Student.java and Stu
ID: 3825581 • Letter: I
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 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 + " " + 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
Explanation / Answer
Dear Student,
NOTE: You have implemented both the classes in a single program. Your professor means that there should be a main method and the two classes must be in as a seprate package.
Read these lines again. in the question.
---------------------------------------------------------------------------------------------------------------------------------------
First Part:
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.
----------------------------------------------------------------------------------------------------------------------------------------
Second Part:
All counting, totaling, computing averagas, checking grade intervals, and assigning grade types to students should be implemented in class Student.
----------------------------------------------------------------------------------------------------------------------------------------
So if you are using eclipse or Netbeans IDE. Please try to implement both the student.java and Students.java classes seperately. I have no access to these classes so can not solve the problem for you.
I think now you have got what is the seperation means.
-----------------------------------------------------------------------------------------------------------------------------------------
Kindly Check and Verify Thanks...!!!
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.