Question: I need help for a CS Project. Here are the Requirments ================================================================================================================ Use the Students.java, Excellent.java, and Ok.java classes from the course website and make

I need help for a CS Project. Here are the Requirments

================================================================================================================

    • Use the Students.java, Excellent.java, and Ok.java classes from the course website and make the following modifications/additions:
      • Create an interface Student and implement it with classes Excellent and Ok to represent the excellent and ok students correspondingly.
      • Create an ArrayList and fill it with objects of classes Excellent and Ok to store all students from the file.
      • Use the ArrayList to print all, excellent and ok students. Use the instanceof operator to distinguish between excellent and ok objects
      • ================================================================================================================
  • Here is the Student.java
  • import java.util.Scanner;
  • import java.io.*;

    public class Students {

    public static void main (String[] args) throws IOException { String first_name, last_name; int grade, count=0; Scanner fileInput = new Scanner(new File("students.txt")); Object st; while (fileInput.hasNext()) { first_name = fileInput.next(); last_name = fileInput.next(); grade = fileInput.nextInt();

    if (grade>89) st = new Excellent(first_name, last_name, grade); else st = new Ok(first_name, last_name, grade);

    if (st instanceof Excellent) ((Excellent)st).info(); else ((Ok)st).info();

    count++; } System.out.println("There are " + count + " students"); } } Here is the Ok,java

  • public class Ok { private String fname, lname; private int grade;

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

    public void info() { System.out.println(fname + " " + lname + "\t" + "Ok"); } }

  • Here is the Excelent.java

  • public class Excellent { private String fname, lname; private int grade;

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

    public void info() { System.out.println(fname + " " + lname + "\t" + "excellent"); } }

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!