In Java Create an abstract superclass Person and two subclas
In Java:
Create an abstract superclass “Person” and two subclasses “Student” and “Instructor”. The person class should include information such as id, first name, last name, etc. A student class should contain more information such as the number of years in college and email address, and an instructor class should contain information such as office number and phone number, etc. You should also include methods to get/set values of the variables of the objects.
Create a database class that includes an array of references to all Students and an array of references to all Instructors, methods to add students and instructors, methods to retrieve student/instructor reference using person’s id, methods to remove student/instructor using either the object reference of person’s id, methods for printing all students or instructors, methods for taking input from command line. Reading and writing students and instructors from and to a file will be convenient for you to have it for testing purpose.
Create an application, the main program that creates a “People” object and makes calls to those methods you implemented. The main program is the user interface to this database software and you should expose the full functionality of the database to users via easy-to-use interface in command line
Solution
class Person
{
String FirstName;
String LastName;
Person(String fName, String lName)
{
FirstName = fName;
LastName = lName;
}
void Display()
{
System.out.println(\"First Name : \" + FirstName);
System.out.println(\"Last Name : \" + LastName);
}
}
class Student extends Person
{
int id;
String standard;
String instructor;
Student(String fName, String lName, int nId, String stnd, String instr)
{
super(fName,lName);
id = nId;
standard = stnd;
instructor = instr;
}
void Display()
{
super.Display();
System.out.println(\"ID : \" + id);
System.out.println(\"Standard : \" + standard);
System.out.println(\"Instructor : \" + instructor);
}
}
class Instructor extends Person
{
String mainSubject;
int salary;
String type;
Instructor(String fName, String lName, String sub, int slry, String sType)
{
super(fName,lName);
mainSubject = sub;
salary = slry;
type = sType;
}
void Display()
{
super.Display();
System.out.println(\"Main Subject : \" + mainSubject);
System.out.println(\"Salary : \" + salary);
System.out.println(\"Type : \" + type);
}
}
class InheritanceDemo
{
public static void main(String args[])
{
Person pObj = new Person(\"Rayan\",\"Miller\");
Student sObj = new Student(\"Jacob\",\"Smith\",1,\"1 - B\",\"Roma\");
Instructor tObj = new Instructor(\"Daniel\",\"Martin\",\"English\",\"6000\",\"Primary Instructor\");
System.out.println(\"Person :\");
pObj.Display();
System.out.println(\"\");
System.out.println(\"Student :\");
sObj.Display();
System.out.println(\"\");
System.out.println(\"Instructor :\");
tObj.Display();
}
}


