Menu

(Solved) : Given Person Class Write Instructor Class Derived Person Class Instructor Name Arraylist C Q29052778 . . .

You are given a person class. You are to write an instructorclass derived from the Person class. Each Instructor has a name andan ArrayList of courses s/he teaches. This ArrayList is empty whenthe instructor is constructed. Create four instructors in main. Oneach line in your input file there are two strings. The first isthe instructors name and the second is a course. As you input thisdata add the course to the arraylist for that instructor. If theinput line is

Henderson CIS101

then add CIS101 to the ArrayList for Henderson

In order to do this you need to add a method called addCourse tothe Instructor class. If s is an instructor then s.add”CIS101″ addsCIS101 to the arraylist for s1.

You also need a WriteOutput method in instructor. This willwrite the name then the courses in the ArrayList.

instructors.txt:

Henderson CIS101

James ENG101

Juice SCI201

Henderson CIS102

James PHIL150

Henderson CIS103

Person.java:

public class Person {

protected String name;

public Person() {
name = “”;
}

public Person(String n) {
name = n;
}

/**
* @return the name
*/
public String getName() {
return name;
}

/**
* @param name the name to set
*/
public void setName(String name) {
this.name = name;
}

public void writeOutput() {
System.out.println(“Name: “+ name);
}

}

Instructor.java:

public class Instructor extends Person
{
private ArrayList<Object> courses;

public Instructor()
{
super();
}
public Instructor(String name,ArrayList<Object>courses)
{
super(name);
this.courses = courses;
}
public ArrayList<Object> getCourses() {
return courses;
}
public void setCourse(ArrayList<Object> courses) {
this.courses = courses;
}
public void addCourse(String s){
  
}
public void writeOutput(){
super.writeOutput();
System.out.println(” Courses: “+courses);
}
}

Please help me finish the addCourse method for Instructor.javaand the main.

Expert Answer


Answer to Given Person Class Write Instructor Class Derived Person Class Instructor Name Arraylist C Q29052778 . . .

OR