As part of an assignment I am having to produce a LinkedList class called Registry. It is intended to be part of a simple student registration system with an interface.
Unfortately, I have literally hit a wall and have no idea on what to do next with what I am doing here. The Registry class is just intended to manage a linked list of students called studentList.
Below is the current, rather incomplete class I have made so far.
import java.util.*;
public class Registry
{
LinkedList<Student> studentList;
public Registry()
{
}
public void addStudent(Student aStudent)
{
studentList.add(aStudent);
}
public void deleteStudent(int studentID)
{
studentList.remove(studentID);
}
#Override
public String toString()
{
return getClass().getName() +
}
public String format()
{
System.out.format(studentList);
}
}
Now, my main worry is using Student. As part of the assignment, I have had to make another class called Student which create instances of Students, containing forenames, surnames, Student IDs and degree Schemes as strings.
How will I be able to use that sperate class to be added to the LinkedList instanted in Registry? And how can I get the Registry class to fully function?
I will try and provide any additional details on request. I am likely unclear, so if I am, let me know, and I will try and explain as best I can.
EDIT: This is the Student Class as requested:
public class Student
{
private String foreName;
private String surName;
private String studentID;
private String degreeScheme;
public Student()
{
}
public void setForeName(String foreName)
{
this.foreName = foreName;
}
public String getForeName()
{
return foreName;
}
public void setSurName(String surName)
{
this.surName = surName;
}
public String getSurName()
{
return surName;
}
public void setStudentID(String studentID)
{
this.studentID = studentID;
}
public String getStudentID()
{
return studentID;
}
public void setDegreeScheme(String degreeScheme)
{
this.degreeScheme = degreeScheme;
}
public String getDegreeScheme()
{
return degreeScheme;
}
#Override
public String toString()
{
return getClass().getName() + "[foreName = " + foreName + " surName "
+ surName + " studentID " + studentID + " degreeScheme "
+ degreeScheme + "]";
}
public void format()
{
System.out.format("%5s%20s%11s%20s", foreName, surName, studentID, degreeScheme);
}
}
import java.util.Iterator;
import java.util.LinkedList;
public class Tester {
public static void main(String[] args) {
Registry r = new Registry();
r.addStudent(new Student("13", "John", "Doe", "Physics")); // Add a student to the Registry
r.addStudent(new Student("212", "Jane", "Bow", "Chem")); // Add another Student
System.out.println(r); // Print the Student List
r.deleteStudent(212); // Deletes student with ID 212
System.out.println(r);
}
}
class Student {
private String studentID;
private String foreName;
private String surName;
private String degreeScheme;
public Student(String studentId, String foreName, String surName, String degreeScheme) {
this.studentID = studentId;
this.foreName = foreName;
this.surName = surName;
this.degreeScheme = degreeScheme;
}
public void setForeName(String foreName) {
this.foreName = foreName;
}
public String getForeName() {
return foreName;
}
public void setSurName(String surName) {
this.surName = surName;
}
public String getSurName() {
return surName;
}
public void setStudentID(String studentID) {
this.studentID = studentID;
}
public String getStudentID() {
return studentID;
}
public void setDegreeScheme(String degreeScheme) {
this.degreeScheme = degreeScheme;
}
public String getDegreeScheme() {
return degreeScheme;
}
#Override
public String toString() {
return getClass().getName() + "[foreName = " + foreName + " surName " + surName + " studentID "
+ studentID + " degreeScheme " + degreeScheme + "]";
}
public void format() {
System.out.format("%5s%20s%11s%20s", foreName, surName, studentID, degreeScheme);
}
}
class Registry {
LinkedList<Student> studentList;
public Registry() { // Creates studentList
studentList = new LinkedList<>();
}
public void addStudent(Student aStudent) {
studentList.add(aStudent);
}
public void deleteStudent(int studentID) {
int index = searchList(studentID); // Gets index of the student in the Registry
if (index == -1)
throw new IllegalArgumentException("Student not found");
// Since studentList is implemented as LinkedList, .remove removes element at specified position
studentList.remove(index);
}
// Search by studentID , if found, return position in the list
private int searchList(int studentID) {
Iterator<Student> it = studentList.iterator();
int count = -1;
while (it.hasNext()) {
count++;
Student temp;
temp = it.next();
if (Integer.parseInt(temp.getStudentID()) == studentID) {
return count;
}
}
return -1;
}
#Override
//Suggestions to improve the toString are welcome
public String toString() {
for (Student student : studentList) {
student.format();
System.out.println();
}
return "";
}
}
In any data structure there are three functions that almost always require implementation:
Insertion
Searching
Deletion
Let me begin by clarifying what the general Linked List structure consists of.
The linked list works by operating on nodes. Each node contains the actual data you want to store/modify/access.
Registry: This should be responsible for maintaining the structure and providing a way of inserting/searching for/deleting specific nodes in the list.
Student: Stores the data and controls how it is accessed and modified
So far, you have your Registry framework created appropriately. (Although you will want to implement a search method.)
For your student class, you simply create the member variables of the class that you need, as well as the appropriate getters/setters for them.
public class Student {
private String id;
private String forename;
private String surname;
private String degreeScheme;
private Student next; // Maintains a reference to the next node in the list
Student () {
//Default constructor values
}
Student (String id, String forename, String surname, String degreeScheme, Student next) {
this.id = id;
this.forename = forename;
this.surname = surname;
this.degreeScheme = degreeScheme;
this.next = next;
}
public void setID (String id) {
this.id = id;
}
public String getID () {
return id;
}
public void setforename (String forename) {
this.forename = forename;
}
public String getforename () {
return forename;
}
public void setSurname(String surname) {
this.surname = surname;
}
public String getSurname () {
return surname;
}
public void setDegreeScheme(String degreeScheme) {
this.degreeScheme = degreeScheme;
}
public String getDegreeScheme () {
return degreeScheme;
}
public void setNext (Student next) {
this.next = next;
}
public Student getNext () {
return next;
}
} //End Student Class
This should be a good base to get you started. Remember, when creating data structures you'll avoid a lot of headaches by making sure that you have a clear separation of concerns. Make the student class purely responsible for storing and maintaining the data, and let the Registry class be responsible for maintaining the structure itself!
At this point, you can utilize the Student class within your Registry class, just insert the nodes as you want, search for them, delete them as needed.
Related
I have three classes in my program. Ship.java, Cabin.java and Passenger.java. According to the program a single cabin should hold up to 3 passengers only. But I'm stuck on how to do this. I have created an array of cabin objects in my Ship.java class. I can only add one passenger into a cabin with below mentioned addCustomer method
Cabin[] cruiseShip = new Cabin[12];
for (int i = 0; i < cruiseShip.length; i++) {
cruiseShip[i] = new Cabin();
}
public static void addCustomer(Cabin[] cruiseShip, String firstName, String surName, int expenses, int cabinNumber){
if (cruiseShip[cabinNumber].getCabinName().equals("empty")){
cruiseShip[cabinNumber].setFirstName(firstName);
cruiseShip[cabinNumber].setSurName(surName);
cruiseShip[cabinNumber].setExpenses(expenses);
cruiseShip[cabinNumber].setCabinName("not empty");
System.out.println("Cabin number " + cruiseShip[cabinNumber].getCabinNumber() + " is occupied by " + cruiseShip[cabinNumber].getFirstName() + " " + cruiseShip[cabinNumber].getSurName() );
}
}
This is how Cabin.java looks :
public class Cabin extends Passenger {
int cabinNumber;
String cabinName;
public String getCabinName() {
return cabinName;
}
public void setCabinName(String cabinName) {
this.cabinName = cabinName;
}
public int getCabinNumber() {
return cabinNumber;
}
public void setCabinNumber(int cabinNumber) {
this.cabinNumber = cabinNumber;
}
}
This is how Passenger.java looks :
public class Passenger {
String firstName;
String surName;
int expenses;
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public String getSurName() {
return surName;
}
public void setSurName(String surName) {
this.surName = surName;
}
public int getExpenses() {
return expenses;
}
public void setExpenses(int expenses) {
this.expenses = expenses;
}
}
Cabin should contain a data-structure which holds passengers.(association 1-n, from 1_cabin-N_passengers) You could also restrict the no. of passengers regarding to cabin type (up to 2-3-n passengers) and also check not to add n-times the same passenger in the same cabin for a specific time. Same logic with Ship which have Cabins.
class Cabin
{
... etc ... as u did
List<Passenger> listP = new ArrayList<Passenger>();
}
listP.add(new Passenger(...));
class Ship
{
...
List<Cabin> listC = new ArrayList<Cabin>();
}
listC.add(new Cabin(...));
//get a specific cabin from the ship and add a new Passenger
//note maybe it's better to do your custom methods for add,get_Ship, Cabin (based on the requiremts).
//Standard List Methods usually do not fit exactly custom requirements, so need to be enhanced
ship.getlistC().get(i_specificCabin).listP.add(new Passenger(...));
Be carefully not to mix semantics, think how in real world things works (see #Jim Garrison).
Note: Maybe a Map<String/Integer,CustomObject> can fit well for ease of access based on key(id).
Your relationship become as per your code is 1 Cabin have multiple Passager so relationship is OneToMany. The best and easiest way to solve your problem is Composition in java. You are working with Inheritance, It has IS-A relationship but Compostion has HAS-A relationship. Composition is best to worked on relationship.
Here down is code that solved your problem using `Composition Technique:
Passenger.java
public class Passenger {
String firstName;
String surName;
int expenses;
// No argument constructor
public Passenger() {
}
// All argument constructor
public Passenger(String firstName, String surName, int expenses) {
this.firstName = firstName;
this.surName = surName;
this.expenses = expenses;
}
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public String getSurName() {
return surName;
}
public void setSurName(String surName) {
this.surName = surName;
}
public int getExpenses() {
return expenses;
}
public void setExpenses(int expenses) {
this.expenses = expenses;
}
}
Cabin.java
public class Cabin {
int cabinNumber;
String cabinName;
List<Passenger> passenger = new ArrayList<>();
// No argument constructor
public Cabin() {
}
// All argument constructor
public Cabin(int cabinNumber, String cabinName, List<Passenger> passenger) {
this.cabinNumber = cabinNumber;
this.cabinName = cabinName;
this.passenger = passenger;
}
public String getCabinName() {
return cabinName;
}
public void setCabinName(String cabinName) {
this.cabinName = cabinName;
}
public int getCabinNumber() {
return cabinNumber;
}
public void setCabinNumber(int cabinNumber) {
this.cabinNumber = cabinNumber;
}
public List<Passenger> getPassenger() {
return passenger;
}
public void setPassenger(List<Passenger> passenger) {
this.passenger = passenger;
}
}
Here down is Main class which insert record in Passanger and Cabin with relationship.
public static void main (String[] args) {
Cabin cabin = new Cabin();
// Insert and Put all Passanger in ArrayList
List<Passenger> passenger = new ArrayList<>();
passenger.add(new Passenger("Jack", "Crawly", 1000));
passenger.add(new Passenger("Michel", "Jordan", 2000));
passenger.add(new Passenger("Tim", "Leach", 3000));
if(cabin.getCabinName() == null)
{
// Insert Cabin with all Passenger
cabin = new Cabin(1, "Cabin1", passenger);
}
// Get all Passangers with Cabin
List<Passenger> passengers = cabin.getPassenger();
for (Passenger psg : passengers) {
System.out.println("Cabin Number : " + cabin.getCabinNumber());
System.out.println("FirstName : " + psg.getFirstName());
System.out.println("LastName : " + psg.getSurName());
System.out.println();
}
}
So I have a student class.
I have a Jlist and try to add a student object. I set dob value.
Everything runs fine no issue. When I retrive sout "student" it returns all other values, but not Dob.
When I call student.getDob() in fact it returns, means it's assigned.
Don't know why it doesn't retrieve in student as an object. I am thinking maybe there is a bug in netbeans.
Any help?
private void addButtonActionPerformed(java.awt.event.ActionEvent evt) {
// Create an instance of student
Student student = new Student();
student.setFName(firstNameField.getText());
student.setLName(lastNameField.getText());
student.setDob(dateOfBirthField.getText());
student.setGender((String) genderComboBox.getSelectedItem());
System.out.println(student.getDob());
// Add student to the list
ListModel lModel = jList1.getModel();
DefaultListModel dlm = new DefaultListModel<Object>();
int total = lModel.getSize();
for (int x = 0; x < total; x++) {
dlm.addElement(lModel.getElementAt(x));
}
dlm.addElement(student);
jList1.setModel(dlm);
//Clearing the text fields for the next entry
firstNameField.setText("");
lastNameField.setText("");
dateOfBirthField.setText("");
genderComboBox.setSelectedIndex(0);}
}
Student Class:
import java.util.ArrayList;
import java.util.Date;
public class Student {
private String id;
private String fName;
private String lName;
private String gender;
private String dob;
private ArrayList<Address> addresses;
private Instructor instructor;
private ArrayList<Courses> courses;
public Student () {
}
public ArrayList<Address> getAddresses () {
return addresses;
}
public void setAddresses (ArrayList<Address> val) {
this.addresses = val;
}
public ArrayList<Courses> getCourses () {
return courses;
}
public void setCourses (ArrayList<Courses> val) {
this.courses = val;
}
public String getDob () {
return dob;
}
public void setDob (String val) {
this.dob = val;
}
public String getFName () {
return fName;
}
public void setFName (String val) {
this.fName = val;
}
public String getGender () {
return gender;
}
public void setGender (String val) {
this.gender = val;
}
public String getId () {
return id;
}
public void setId (String val) {
this.id = val;
}
public Instructor getInstructor () {
return instructor;
}
public void setInstructor (Instructor val) {
this.instructor = val;
}
public String getLName () {
return lName;
}
public void setLName (String val) {
this.lName = val;
}
#Override
public String toString(){
return getFName()+" "+getLName()+" "+getGender();
}
}
I found it with deep debugging. In the student class Dob was not stringified. Added getDob() at the end.
#Override
public String toString(){
return getFName()+" "+getLName()+" "+getGender()+" "+getDob();
}
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
[UML Diagram][1]
I'm studying for the midterm exam next week and I'm practicing some given examples from my professor; however, I am having some trouble with class return type methods.
I attached UML diagram just in case.
What i'm trying to understand is getPerson method in Job class. I don't think i need a array list in Job class to store all the employee. Because I have an array list already in Company class. Also return type is Employee class that I'm not sure how to get person's info using this class return type.
My problems
public Employee getPerson() {} in Job class
public boolean isVacant() {} in Job class
Also would you mind checking getVacantJobs, getFilledJobs, and getAllJobs methods if those are correctly built?
I used iterator to display all the stored jobs.
---------------------------Employee Class -----------------------------
public class Employee {
private String name;
private int id;
public Employee(int id, String name) {
this.name = name;
this.id =id;
}
public final String getName() {
return name;
}
public final void setName(String name) {
this.name = name;
}
public final int getId() {
return id;
}
public final void setId(int id) {
this.id = id;
}
#Override
public String toString() {
return "Employee [name=" + name + ", id=" + id + "]";
}
}
----------------------------Job Class--------------------------------------
public class Job {
private String description;
private int id;
private double maxSalary;
public Job(int id, double maxSalary, String description) {
this.description = description;
this.id = id;
this.maxSalary = maxSalary;
}
public Job(int id, double maxSalary, String description, Employee e1) {
this.description = description;
this.id = id;
this.maxSalary = maxSalary;
}
#Override
public String toString() {
return "Job [description=" + description + ", id=" + id
+ ", maxSalary=" + maxSalary + "]";
}
public final String getDescription() {
return description;
}
public final void setDescription(String description) {
this.description = description;
}
public final double getMaxSalary() {
return maxSalary;
}
public final void setMaxSalary(double maxSalary) {
this.maxSalary = maxSalary;
}
public final int getId() {
return id;
}
public Employee getPerson() {
retrun
}
public final void setPerson(Employee person) {
this.id = person.getId();
}
}
--------------------------Company Class ---------------------------
import java.util.ArrayList;
import java.util.Iterator;
public class Company {
static ArrayList list = new ArrayList();
Iterator itr = list.iterator();
private String name;
public Company(String name) {
this.name = name;
}
public Company() {
// TODO Auto-generated constructor stub
}
public static void addJob(Job j1) {
list.add(j1);
}
public void removeJob(int id) {
list.remove(id);
}
public ArrayList<Job> getVacantJobs() {
while (itr.hasNext()) {
if ((itr == null)) {
System.out.println(itr);
}
}
return null;
}
public ArrayList<Job> getFilledJobs() {
while (itr.hasNext()) {
if (!(itr == null)) {
System.out.println(itr);
}
}
return null;
}
public ArrayList<Job> getAllJobs() {
while (itr.hasNext()) {
System.out.println(itr.next());
}
return null;
}
}
Add field person to Job class.
public class Job {
// .....
private Employee person;
public Employee getPerson() {
return person;
}
public final void setPerson(Employee person) {
this.person = person;
}
public boolean isVacant() {
return person == null;
}
}
And add jobs field to Company class.
public class Company {
// static ArrayList list = new ArrayList(); // You don't need this
// Iterator itr = list.iterator(); // You don't need this.
// .....
private ArrayList<Job> jobs = new ArrayList<>();
public ArrayList<Job> getVacantJobs() {
ArrayList<Job> result = new ArrayList<>();
for (Job job : jobs)
if (job.isVacant())
result.add(job);
return result;
}
public ArrayList<Job> getFilledJobs() {
ArrayList<Job> result = new ArrayList<>();
for (Job job : jobs)
if (!job.isVacant())
result.add(job);
return result;
}
public ArrayList<Job> getAllJobs() {
ArrayList<Job> result = new ArrayList<>();
for (Job job : jobs)
result.add(job);
return result;
}
}
Hi I have created a toStringmethod in one of my classes which can be seen below.
Student Class:
package Practical5;
public class Student extends Person {
//instance variables
private static int MAX_MODULES = 6;
private StudentMode modeOfStudy;
private boolean studentLoan;
private int numEnrolledModules;
//constructor
public Student(String name, String dob, Address address, StudentMode modeOfStudy, boolean studentLoan) {
super(name, dob, address);
this.modeOfStudy = modeOfStudy;
this.studentLoan = studentLoan;
this.numEnrolledModules = 0;
}
//accessors & mutators
public StudentMode getMode() {
return modeOfStudy;
}
public boolean isStudentLoan() {
return studentLoan;
}
public int getNumEnrolledModules() {
return numEnrolledModules;
}
public void setMode(StudentMode modeOfStudy) {
this.modeOfStudy = modeOfStudy;
}
public void setStudentLoan(boolean studentLoan) {
this.studentLoan = studentLoan;
}
public void setNumEnrolledModules(int numEnrolledModules) {
this.numEnrolledModules = numEnrolledModules;
}
#Override
public void purchaseParkingPass() {
System.out.println(getName() + " just purchased a parking pass with student discount.");
}
#Override
public void addModule(String moduleCode) {
if (getNumEnrolledModules() < MAX_MODULES) {
System.out.println(getName() + " successfully registered for the module: " + moduleCode);
}
else {
System.out.println("You are unable to register for " + moduleCode + " as the maximum number of permitted module enrolments has been reached.");
}
}
public String toString() {
return "Student [ ID: " + getId() + "; Name: " + getName() +
"; DOB: " + getDob() + "; Study Mode: " + getMode() +
"; Number of Enrolled Modules: " + getNumEnrolledModules();
}
}
Person Class:
package Practical5;
public abstract class Person {
//instance variables
private static int LAST_ID = 1000 + 1;
private int id;
private String name;
private String dob;
private Address address;
//constructor
public Person(String name, String dob, Address address) {
super();
LAST_ID ++;
this.id = LAST_ID;
}
//accessors & mutators
public int getId() {
return id;
}
public String getName() {
return name;
}
public String getDob() {
return dob;
}
public Address getAddress() {
return address;
}
public void setName(String name) {
this.name = name;
}
public void setDob(String dob) {
this.dob = dob;
}
public void setAddress(Address address) {
this.address = address;
}
//methods
public abstract void purchaseParkingPass();
public abstract void addModule(String moduleCode);
}
I then created a tester class and created a new ArrayList and added these elements to it.
I then created a for loop in order to loop through each element and call the toString method to print out the details of each element but it is returning null values.
Tester Class:
package Practical5;
import java.util.ArrayList;
import java.util.Scanner;
public class UIS_Tester {
public static void main(String[] args) {
Student student1 = new Student("James Black", "07/09/1995" , new Address("Wheeler's Road",10,"Belfast", "BT12 5EG", "Co.Antrim"),StudentMode.Fulltime, false);
Student student2 = new Student("Adam Smith", "12/11/1979" , new Address("Ivy Hill",67,"Belfast", "BT17 7BN", "Co.Antrim"),StudentMode.Parttime, true);
ArrayList<Person> uniPeople = new ArrayList<Person>();
uniPeople.add(student1);
uniPeople.add(student2);
printMenu(uniPeople);
}
public static void printAllDetails(ArrayList<Person> uniPeople) {
for (int i = 0; i < uniPeople.size(); i++) {
System.out.println(uniPeople.get(i).toString());
}
}
}
Output:
Student [ ID: 1002; Name: null; DOB: null; Study Mode: Fulltime; Number of Enrolled Modules: 0
Student [ ID: 1003; Name: null; DOB: null; Study Mode: Parttime; Number of Enrolled Modules: 0
Can anyone help me with this problem? Thanks
public Person(String name, String dob, Address address) {
super();
LAST_ID ++;
this.id = LAST_ID;
}
The constructor completely ignores its three arguments. It doesn't assign them to the corresponding fields, so these fields keep their default value: null.
You have to store the name value in the constructor. Your version did not use the name value.
public Person(String name, String dob, Address address) {
super();
this.name = name; // <== important line
this.dob = dob; // <== important line
this.address = address; // <== important line
LAST_ID ++;
this.id = LAST_ID;
}
Look at the constructor in person and in student, Should use the parameters in the method header.
super(name,dob,address)
I have 5 classes (they're small). PersonDemo (test class), Person (superclass), and Student, Instructor and Graduate Student (sub classes). All the classes except for PersonDemo are finished.
I need to read in a file (data.txt) and store it to array Person. Then need I need to determine which object to initialize depending on the first value of the array. ( 1 - person, 2 - student, 3 - instructor or 4 - graduate student ) - I'm having trouble with this part.
Can someone point me in the right direction? My classes are below along with what the input file (data.txt) looks like and what the output file should look like.
PersonDemo.Java
public class PersonDemo
{
public static void main ()
{
JFileChooser chooser = new JFileChooser();
Scanner fileScanner = null;
Person [] ins = new Person [10];
try {
if (chooser.showOpenDialog(null) == JFileChooser.APPROVE_OPTION)
{
File selectedFile = chooser.getSelectedFile();
fileScanner = new Scanner(selectedFile);
while(fileScanner.hasNextLine())
{
// Need to load "data.txt" into array
// Then need I need to determine which object to initialize depending on the
// first value of the array in "data.txt"
//( 1 - person, 2 - student, 3 - instructor or 4 - graduate student )
}
fileScanner.close();
}
}
catch (FileNotFoundException e)
{
System.out.println("Could not find file");
}
}
public static void showAll(Person [] ins)
{
// Future code here
}
}
Person.java (superclass)
public class Person
{
private String name;
private int age;
public Person()
{
name="";
age=0;
}
public Person(String name, int age)
{
this.name = name;
this.age = age;
}
public String getName()
{
return name;
}
public void setName(String name)
{
this.name = name;
}
public int getAge()
{
return age;
}
public void setAge(int age)
{
this.age = age;
}
public String toString()
{
return "Name: " + name + "\t" + "Age: " + age;
}
}
Student.java (subclass)
public class Student extends Person
{
private int studentID;
private String major;
public Student()
{
studentID = 0;
major = "";
}
public Student(String name, int age, int studentID, String major)
{
super(name, age);
this.major = major;
this.studentID = studentID;
}
public int getID()
{
return studentID;
}
public void setID(int studentID)
{
this.studentID = studentID;
}
public String getMajor()
{
return major;
}
public void setMajor(String major)
{
this.major = major;
}
public String toString()
{
return super.toString() + "Student ID: " + studentID + "Major: " + major;
}
}
GraduateStudent.java (subclass)
public class GraduateStudent extends Student
{
private String researchArea;
public GraduateStudent()
{
researchArea = "";
}
public GraduateStudent(String name, int age, int studentID, String major, String researchArea)
{
super(name, age, studentID, major);
this.researchArea = researchArea;
}
public String getArea()
{
return researchArea;
}
public void setArea(String researchArea)
{
this.researchArea = researchArea;
}
public String toString()
{
return super.toString() + "Research Area: " + researchArea;
}
}
Instructor.java (subclass)
public class Instructor extends Person
{
private int salary;
public Instructor()
{
salary = 0;
}
public Instructor(String name, int age, int salary)
{
super(name, age);
this.salary = salary;
}
public int getSalary()
{
return salary;
}
public void setSalary(int salary)
{
this.salary = salary;
}
public String toString()
{
return super.toString() + "Salary: " + salary;
}
}