Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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;

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 courses;

public Instructor() { super(); } public Instructor(String name,ArrayList courses) { super(name); this.courses = courses; } public ArrayList getCourses() { return courses; } public void setCourse(ArrayList 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.java and the main.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Put Your Data To Work 52 Tips And Techniques For Effectively Managing Your Database

Authors: Wes Trochlil

1st Edition

0880343079, 978-0880343077

More Books

Students also viewed these Databases questions