Post date: Oct 10, 2017 10:19:25 AM
/!\ Quiz 1 will be on Thursday
Chapter 13: Interface and Inner Classes
13.1 Interfaces
13.2 Simple Uses of Inner Classes
In-Class Exercises:
Ex 1:
Write each of the following:
an interface, Instructor, which has two methods: String getOfficeHours() and Course[] getTeachingCourses().
a class, Course, with instance variables: courseCode, creditHours, and title; and appropriate accessor, mutator and toString() methods.
a class Faculty that implements the Instructor interface. It has two additional instance variables: String officeHours and Course[] teachingCourses.
classes, Student (with String name, int id and double gpa as instance variables; with accessors and mutators and the method toString()) and GraduateStudent that inherits from Student with an instance variable String thesisTitle and a method defendThesis() as well as toString().
a class, ReaseachAssistant, that extends GraduateStudent and implements the Instructor interface
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 ResearchAssistant and prints their teaching details.
Ex 2: (based on Programming Project #2 from the book (p786))
Listed next is the skeleton for a class named InventoryItem . Each inventory item
has a name and a unique ID number:
class InventoryItem {
private String name;
private int uniqueItemID;
}
Flesh out the class with appropriate accessors, constructors, and mutatators.
The uniqueItemID ’s are assigned by your store and can be set from outside the InventoryItem class—your code does not have to ensure that they are unique.
Next, modify the class so that it implements the Comparable interface. The compareTo() method should compare the uniqueItemID ’s; e.g., the InventoryItem with item ID 5 is less than the InventoryItem with ID 10.
Test your class by creating an array of sample InventoryItem ’s and sort them using a sorting method that takes as input an array of type Comparable.