You are on page 1of 6

//No 1.

An interface, Instructor, which has two methods: String


getOfficeHours() and Course[ ] getTeachingCourses().

public class Faculty implements Instructor {


private String name;
private String officeHours;
private String[] teachingCourses;

public Faculty(String name, String officeHours, String[] teachingCourses) {


this.name = name;
this.officeHours = officeHours;
this.teachingCourses = teachingCourses;
}

public String getOfficeHours() {


return officeHours;
}
public String[] getTeachingCourses() {
return teachingCourses;
}

public class ResearchAssistant implements Instructor {


private String name;
private String officeHours;
private String[] teachingCourses;

public ResearchAssistant(String name, String officeHours, String[] teachingCourses) {


this.name = name;
this.officeHours = officeHours;
this.teachingCourses = teachingCourses;
}

public String getOfficeHours() {


return officeHours;
}

public String[] getTeachingCourses() {


return teachingCourses;
}

//No 2. A class, Course, with instance variables: courseCode, creditHours,


and title; and appropriate accessor, mutator and toString methods.

public class Course {

private String courseCode;


private int creditHours;
private String title;

public Course(String courseCode, int creditHours, String title) {


this.courseCode = courseCode;
this.creditHours = creditHours;
this.title = title;
}

// Accessor methods (getters)


public String getCourseCode() {
return courseCode;
}

public int getCreditHours() {


return creditHours;
}

public String getTitle() {


return title;
}

// Mutator methods (setters)


public void setCourseCode(String courseCode) {
this.courseCode = courseCode;
}

public void setCreditHours(int creditHours) {


this.creditHours = creditHours;
}

public void setTitle(String title) {


this.title = title;
}

public String toString() {


return "Course Code: " + courseCode +
"\nCredit Hours: " + creditHours +
"\nTitle: " + title;
}

public static void main(String[] args) {


// Creating an instance of the Course class
Course javaCourse = new Course("CS101", 3, "Introduction to Java Programming");

System.out.println("Course Code: " + javaCourse.getCourseCode());


System.out.println("Credit Hours: " + javaCourse.getCreditHours());
System.out.println("Title: " + javaCourse.getTitle());

System.out.println("\nCourse Information:\n" + javaCourse);


}
}
//No 3. A class Faculty that extends MonthlyEmpolyee and implements the
Instructor interface. It has two additional instance variables: String
officeHourse and Course[] teachingCourses.

interface Instructor {
String getOfficeHours();
String[] getTeachingCourses();
}

class MonthlyEmployee {
private String name;
private double salary;

public MonthlyEmployee(String name, double salary) {


this.name = name;
this.salary = salary;
}

public String getName() {


return name;
}

public double getSalary() {


return salary;
}
}

public class Faculty extends MonthlyEmployee implements Instructor {


private String officeHours;
private String[] teachingCourses;

public Faculty(String name, double salary, String officeHours, String[] teachingCourses) {

super(name, salary);

this.officeHours = officeHours;
this.teachingCourses = teachingCourses;
}

public String getOfficeHours() {


return officeHours;
}

public String[] getTeachingCourses() {


return teachingCourses;
}
}
//No 4. classes, Student and GraduateStudents as described in page 3 of the
inheritance session

class Student {
private String name;
private int studentId;

public Student(String name, int studentId) {


this.name = name;
this.studentId = studentId;
}

public String getName() {


return name;
}

public int getStudentId() {

return studentId;

class GraduateStudent extends Student {


private String researchTopic;

public GraduateStudent(String name, int studentId, String researchTopic) {

super(name, studentId);

this.researchTopic = researchTopic;
}

public String getResearchTopic() {


return researchTopic;
}

//No 5. A class, ReaseachAssistant, that extends GraduateStudent and


implements the Instructor interface.

interface Instructor {
String getOfficeHours();
String[] getTeachingCourses();
}

class Student {
private String name;
private int studentId;
public Student(String name, int studentId) {
this.name = name;
this.studentId = studentId;
}

public String getName() {


return name;
}

public int getStudentId() {


return studentId;
}
}

class GraduateStudent extends Student {


private String researchTopic;

public GraduateStudent(String name, int studentId, String researchTopic) {


super(name, studentId);
this.researchTopic = researchTopic;
}

public String getResearchTopic() {


return researchTopic;
}
}

public class ResearchAssistant extends GraduateStudent implements Instructor {


private String officeHours;
private String[] teachingCourses;

public ResearchAssistant(String name, int studentId, String researchTopic, String officeHours, String[]
teachingCourses) {
super(name, studentId, researchTopic);
this.officeHours = officeHours;
this.teachingCourses = teachingCourses;
}
public String getOfficeHours() {
return officeHours;
}

public String[] getTeachingCourses() {


return teachingCourses;
}
}

No 6. A test class, TestInstructors, that has the following methods: void


PrintTeachingDetails(Instructor i): that prints the office hours and
teaching courses for i; and a main method, that creates instances of
Faculty and ReasearchAssistant and prints their teaching details.
class Instructor {
String name;
String officeHours;
String[] teachingCourses;

public Instructor(String name, String officeHours, String[] teachingCourses) {


this.name = name;
this.officeHours = officeHours;
this.teachingCourses = teachingCourses;
}
}

class Faculty extends Instructor {


public Faculty(String name, String officeHours, String[] teachingCourses) {
super(name, officeHours, teachingCourses);
}
}

class ResearchAssistant extends Instructor {


public ResearchAssistant(String name, String officeHours, String[] teachingCourses) {
super(name, officeHours, teachingCourses);
}
}

public class TestInstructors {

public static void printTeachingDetails(Instructor i) {


System.out.println("Teaching details for " + i.name + ":");
System.out.println("Office Hours: " + i.officeHours);
System.out.print("Teaching Courses: ");
for (String course : i.teachingCourses) {
System.out.print(course + " ");
}
System.out.println("\n");
}

public static void main(String[] args) {


// Creating instances of Faculty and ResearchAssistant
Faculty faculty = new Faculty("John Doe", "Monday 2:00 PM - 4:00 PM", new String[]{"Math",
"Physics"});
ResearchAssistant researchAssistant = new ResearchAssistant("Jane Smith", "Wednesday 10:00 AM -
12:00 PM", new String[]{"Computer Science", "Research Methods"});

printTeachingDetails(faculty);
printTeachingDetails(researchAssistant);
}
}

You might also like