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

java five files School.java, Students.java, Elementary.java, Middle.java, and Hi

ID: 3770797 • Letter: J

Question

java

five files

School.java, Students.java, Elementary.java, Middle.java, and HighSchool.java. The School.java file will be the only file to contain a main()

The Student class, which is stored in Student.java, will act as your parent class from which the different types of students will be derived from. This class must have the following members:

Fields for the following attributes

Name

ID Number

“Getter”/”Setter” methods for each attribute

public String getName()

public void setName(String n)

public String getID ()

public void setID (int id)

A method that will return a String of all of the attributes for this object

public String toString()

An appropriate constructor

The constructor must initialize both fields of the Student object with the constructor’s parameters

public Student(String n, int id)

The HighSchool Class

The HighSchool class, which is stored in HighSchool.java, will be a child class of the Student Class. This class must have the following members:

A field for the following attribute

Name Of School

A “getter” and “setter” method for this attribute

public String getSchoolNames()

public void setSchoolNames(String schoolName)

A method that will return a String of all of the attributes for this object

public String toString()

An appropriate constructor

The constructor must initialize both fields of the Student object with the constructor’s parameters

public HighSchool (String n, int id, String schoolName)

The Middle Class

The Middle Class, which is stored inMiddle.java, will also be a child class of the Student Class. This class must have the following members:

A field for the following attribute

Major

A “getter” and “setter” method for this attribute

public String getGrade()

public void setGrade(String Grade)

A method that will return a String of all of the attributes for this object

public String toString()

An appropriate constructor

The constructor must initialize both fields of the Student object with the constructor’s parameters

public Middle(String n, int id, String major)

The Elementary Class

The Elementary Class, which is stored in Elementary.java, will be the final child class of the Student Class. This class must have the following members:

Fields for the following attributes

Grade

Teacher

“Getter”/“Setter” methods for each attribute

public String getGrade()

public void setGrade(String Grade)

public String getTeacher()

public void setTeacher(String Teacher)

A method that will return a String of all of the attributes for this object

public String toString()

An appropriate constructor

The constructor must initialize both fields of the Student object with the constructor’s parameters

public Elementary(String n, int id, String Grade, String Teacher)

The program will read a file example 11111.txt

You will write the output to a text file (ID_student.txt) with the same format shown in the Sample Runs section

Sample file 11111.txt

Sample Essay File (saved as 11111.txt)

Elementary

Jane Doe

11111

John Smith

Sample file output 11111_graded.txt

Elementary Student Jane Doe

Student ID 11111

Teacher: John Smith

Explanation / Answer

Complete Program:

// File: Student.java
public class Student
{
private String name;
private int id;

public Student()
{
  name = "";
  id = 0;
}

public Student(String sname, int sid)
{
  name = sname;
  id = sid;
}

public String getName()
{
  return name;
}

public void setName(String sname)
{
  name = sname;
}

public int getID()
{
  return id;
}

public void setID(int sid)
{
  id = sid;
}

public String toString()
{
  return "Student: " + name + " " + "Student ID: " + id;
}
}


// File: HighSchool.java
public class HighSchool extends Student
{
private String schoolName;

public HighSchool()
{
  super();
  schoolName = "";
}

public HighSchool(String sname, int sid, String hschoolName)
{
  super(sname, sid);
  schoolName = hschoolName;
}


public String getSchoolNames()
{
  return schoolName;
}

public void setSchoolNames(String hschoolName)
{
  schoolName = hschoolName;
}

public String toString()
{
  return "HighSchool " + super.toString() + " Name of School: " + schoolName;
}
}

// File: Middle.java
public class Middle extends Student
{
private String major;

public Middle()
{
  super();
  major = "";
}

public Middle(String sname, int sid, String mmajor)
{
  super(sname, sid);
  major = mmajor;
}

public String getMajor()
{
  return major;
}

public void setMajor(String mmajor)
{
  major = mmajor;
}

public String toString()
{
  return "Middle " + super.toString() + " Major: " + major;
}
}


// File: Elementary.java
public class Elementary extends Student
{
private String grade;
private String teacher;

public Elementary()
{
  super();
  grade = "";
  teacher = "";
}

public Elementary(String sname, int sid, String egrade, String eteacher)
{
  super(sname, sid);
  grade = egrade;
  teacher = eteacher;
}

public String getGrade()
{
  return grade;
}

public void setGrade(String egrade)
{
  grade = egrade;
}

public String getTeacher()
{
  return teacher;
}

public void setTeacher(String eeacher)
{
  teacher = eteacher;
}

public String toString()
{
  return "Elementary " + super.toString() + " Teacher: " + teacher + " Grade: " + grade;
}
}

// File: School.java
import java.io.*;
import java.util.*;
public class School
{
public static void main(String[] args) throws FileNotFoundException
{
  Scanner infile = new Scanner(new File("11111.txt"));
  PrintWriter outfile = new PrintWriter(new File("11111_graded.txt"));
    
  while(infile.hasNextLine())
  {
   String school = infile.nextLine();
   String sname = infile.nextLine();
   int sid = Integer.parseInt(infile.nextLine());   
   
   if(school.equalsIgnoreCase("Elementary"))
   {
    String egrade = infile.nextLine();
    String eteacher = infile.nextLine();
    
    Elementary elementary = new Elementary(sname, sid, egrade, eteacher);
    
    outfile.println("Elementary Student: " + elementary.getName());
    outfile.println("Student ID: " + elementary.getID());
    outfile.println("Teacher: " + elementary.getTeacher());
    outfile.println("Grade: " + elementary.getGrade());    
   }
   else if(school.equalsIgnoreCase("Middle"))
   {
    String mmajor = infile.nextLine();
    
    Middle middle = new Middle(sname, sid, mmajor);
    
    outfile.println("Middle Student: " + middle.getName());
    outfile.println("Student ID: " + middle.getID());
    outfile.println("Major: " + middle.getMajor());  
   }
   else if(school.equalsIgnoreCase("HighSchool"))
   {
    String hschoolName = infile.nextLine();
    
    HighSchool highSchool = new HighSchool(sname, sid, hschoolName);
    
    outfile.println("Middle Student: " + highSchool.getName());
    outfile.println("Student ID: " + highSchool.getID());
    outfile.println("Name of School: " + highSchool.getSchoolNames());  
   }
   else
    System.out.println("Invalid class name");
  }
  
  infile.close();
  outfile.close();
}
}