Write a program in Java and run it in BlueJ according to the following specifica
ID: 3821436 • Letter: W
Question
Write a program in Java and run it in BlueJ according to the following specifications: The program reads a text file with student records (first name, last name and grade) and prints them in the terminal window. After the name and grade it also prints the type of the grade: excellent (> 89), ok [60,89], and failure (< 60). Then the program prints the number of students, and their average grade and also the number of students and their average in each grade category (excellent, ok, and failure). For example, with the input file students.txt the program must print the following:
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.0
There are 2 excellent students with average grade 92.5
There are 3 ok students with average grade 73.3333
There are 2 failre students with average grade 56.5
Below its what ive done so far, this is the first class
public class Students
{
public static void main (String[] args) throws IOException
{ String first_name, last_name;
int grade;
double average;
Scanner fileInput = new Scanner(new File("students.txt"));
while (fileInput.hasNext())
{
first_name = fileInput.next();
last_name = fileInput.next();
grade = fileInput.nextInt();
Student st = new Student(first_name, last_name, grade);
{
if(average>=89) System.out.print("Excellent");
else if(average>=60)System.out.print("ok");
else if(average<=89)System.out.print("ok");
else if(average<60)System.out.print("failure");
}
System.out.println(st);
}
System.out.println("There are " + Student.getCount() + " students with average grade " + Student.average());
System.out.println("There are " + Student.getCount() + " excellent student with average grade " + Student.average());
System.out.println("There are " + Student.getCount() + " ok with average grade " + Student.average());
System.out.println("There are " + Student.getCount() + " failre with average grade " + Student.average());
}
}
THis is my second class
public class Student
{
private String fname, lname;
private int grade;
private static int total=0, count=0;
public Student(String fname, String lname, int grade)
{
this.fname = fname;
this.lname = lname;
this.grade = grade;
total = total + grade;
count++;
}
public static int getCount()
{
return count;
}
public static double average ()
{
return (double)total/count;
}
public String toString()
{
return fname + " " + lname + " " + grade;
}
}
The program also prints the student with the highest and the student with the lowest grade.
I cant get the rest please help
Explanation / Answer
HI, Please find my implementation.
Please let me know in case of any issue.
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;
int excellent = 0, ok = 0, fail = 0;
Scanner fileInput = new Scanner(new File("students.txt"));
while (fileInput.hasNext())
{
first_name = fileInput.next();
last_name = fileInput.next();
grade = fileInput.nextInt();
Student st = new Student(first_name, last_name, grade);
System.out.print(st);
if(grade>89) {
System.out.println(" Excellent");
excellent++;
}
else if(grade>=60){
System.out.println(" ok");
ok++;
}
else {
System.out.println(" failure");
fail++;
}
}
fileInput.close();
System.out.println("There are " + Student.getCount() + " students with average grade " + Student.average());
System.out.println("There are " + Student.getCount() + " excellent student with average grade " + excellent);
System.out.println("There are " + Student.getCount() + " ok with average grade " + ok);
System.out.println("There are " + Student.getCount() + " failre with average grade " + fail);
}
}
/*
Sample run:
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.0
There are 7 excellent student with average grade 2
There are 7 ok with average grade 3
There are 7 failre with average grade 2
*/
######## students.txt #######
John Smith 90
Barack Obama 95
Al Clark 80
Sue Taylor 55
Ann Miller 75
George Bush 58
John Miller 65
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.