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

i just need comments on all of this please public class Student { private String

ID: 3838166 • Letter: I

Question

i just need comments on all of this please

public class Student {

private String fname;
private String lname;
private int grade;

private static int total = 0, count = 0;
private static int totalExcellent = 0, totalOk = 0, totalFailure = 0;
private static int countExcellent = 0, countOk = 0, countFailure = 0;

private static Student higher;
private static Student lower;

public Student( String fname, String lname, int grade )
{
this.fname = fname;
this.lname = lname;
this.grade = grade;
if( higher == null || lower == null )
{
higher = this;
lower = this;
}
else
{
if( this.grade > higher.grade )
higher = this;
if( this.grade < lower.grade )
lower = this;
}

total = total + grade;
count++;

if( grade < 60 )//prints failure for students with grades less than 60
{
totalFailure += grade;
countFailure++;
}
else if( grade <= 89 )//prints okey for students with grades 89 less
{
totalOk += grade;
countOk++;
}
else//prints out excellent for students with higher grades
{
totalExcellent += grade;
countExcellent++;
}

}

public static int getExcellentCount()
{
return countExcellent;
}

public static double getExcellentaverage()
{
return (double) totalExcellent / countExcellent;
}

public static int getOkCount()
{
return countOk;
}

public static double getOkaverage()
{
return (double) totalOk / countOk;
}

public static int getFailureCount()
{
return countFailure;
}

public static double getFailureaverage()
{
return (double) totalFailure / countFailure;
}

public static int getCount()
{
return count;
}

public static double average()//generates loop
{
return (double) total / count;
}

public String toString()
{
return fname + " " + lname + " " + grade + " " + getType(grade);
}

public static Student getHigher()
{
return higher;
}

public static Student getLower()
{
return lower;
}

private String getType( int grade )
{
if( grade < 60 )
return "failure";
if( grade <= 89 )
return "ok";
return "excellent";
}
}

------

import java.io.File;
import java.io.IOException;
import java.util.Scanner;
public class Students
{

public static void main( String[] args ) throws IOException
{
String first_name, last_name;
int grade, total = 0, count = 0;
double average;
Scanner fileInput = new Scanner(new File("students.txt"));//specify the location of the code
while( fileInput.hasNext() )
{
first_name = fileInput.next();//gets the first name
last_name = fileInput.next();//gets the last name
grade = fileInput.nextInt();//gets the grades
Student st = new Student(first_name, last_name, grade);
System.out.println(st);
}

Explanation / Answer


public class Student {
private String fname;
private String lname;
private int grade;
private static int total = 0, count = 0;
private static int totalExcellent = 0, totalOk = 0, totalFailure = 0;
private static int countExcellent = 0, countOk = 0, countFailure = 0;
private static Student higher;
private static Student lower;
//Constructor to create Student object with first name, last name and grade
public Student( String fname, String lname, int grade )
{
this.fname = fname;
this.lname = lname;
this.grade = grade;
if( higher == null || lower == null )
{
higher = this;
lower = this;
}
else
{
       //Calculating higher and lower grades
if( this.grade > higher.grade )
higher = this;
if( this.grade < lower.grade )
lower = this;
}
   //Calculating total grades
total = total + grade;
count++;
   //Calculating failure Grades and total failure students
if( grade < 60 )//prints failure for students with grades less than 60
{
totalFailure += grade;
countFailure++;
}
   //Calculatig total ok grades and ok students
else if( grade <= 89 )//prints okey for students with grades 89 less
{
totalOk += grade;
countOk++;
}
   //Calculating total excellent grades and excellent students
else//prints out excellent for students with higher grades
{
totalExcellent += grade;
countExcellent++;
}
}
//Returning count of excellent students
public static int getExcellentCount()
{
return countExcellent;
}
//Returning average of the excellent students
public static double getExcellentaverage()
{
return (double) totalExcellent / countExcellent;
}
//Returning count of ok students
public static int getOkCount()
{
return countOk;
}
//Returning average of the ok students
public static double getOkaverage()
{
return (double) totalOk / countOk;
}
//Returning count of failure students
public static int getFailureCount()
{
return countFailure;
}
//Returning average of the failure students
public static double getFailureaverage()
{
return (double) totalFailure / countFailure;
}
//Returns the total count of all the students
public static int getCount()
{
return count;
}
//Returns the average of all the students
public static double average()//generates loop
{
return (double) total / count;
}
//String to print the student object
public String toString()
{
return fname + " " + lname + " " + grade + " " + getType(grade);
}
//Returns the highest grade student
public static Student getHigher()
{
return higher;
}
//returns the lower grade student
public static Student getLower()
{
return lower;
}
//Returns the type of this student
private String getType( int grade )
{
if( grade < 60 )
return "failure";
if( grade <= 89 )
return "ok";
return "excellent";
}
}
------
import java.io.File;
import java.io.IOException;
import java.util.Scanner;
public class Students
{
public static void main( String[] args ) throws IOException
{
String first_name, last_name;
int grade, total = 0, count = 0;
double average;
   //Reading the file from string
Scanner fileInput = new Scanner(new File("students.txt"));//specify the location of the code
while( fileInput.hasNext() )
{
first_name = fileInput.next();//gets the first name
last_name = fileInput.next();//gets the last name
grade = fileInput.nextInt();//gets the grades
       //Initializing a student object
Student st = new Student(first_name, last_name, grade);
System.out.println(st);
}