Question: HELP IN JAVA: You are given a person class. You are to write an instructor class derived from the Person class. Each Instructor has a
HELP IN JAVA:
You are given a person class. You are to write an instructor class derived from the Person class. Each Instructor has a name and an ArrayList of courses s/he teaches. This ArrayList is empty when the instructor is constructed. Create four instructors in main. On each line in your input file there are two strings. The first is the instructors name and the second is a course. As you input this data add the course to the arraylist for that instructor. If the input 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 to the Instructor class. If s is an instructor then s.add"CIS101" adds CIS101 to the arraylist for s1.
You also need a WriteOutput method in instructor. This will write 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; protected int age;
public Person() { name = ""; age = 0; }
public Person(String n, int a) { name = n; age = a; }
/** * @return the name */ public String getName() { return name; }
/** * @param name the name to set */ public void setName(String name) { this.name = name; }
/** * @return the age */ public int getAge() { return age; }
/** * @param age the age to set */ public void setAge(int age) { this.age = age; }
public String toString() { return ("Name: " + name + " Age: " + age); }
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
