CIS 35A: Introduction to Java Programming

Home | Green Sheet | Lectures | Assignments | FAQ | Grades | Students

Lab #7 (Exercise 8-1)

Create and work with interfaces

Due Date: Monday of Week 3
10 points

In this lab, you'll create and implement the DepartmentConstants interface presented in this chapter. You'll also create and implement an interface named Displayable that's similar to the Printable interface.

    Create the interfaces

  1. Add an interface named DepartmentConstants that contains the three constants. Compile the interface.
  2. Add an interface named Displayable. This interface should contain a single method named getDisplayText that returns a String. Compile this interface.
  3. Implement the interfaces

  4. Edit the Product class so it implements the Displayable interface. The getDisplayText method in this class should format a string that can be used to display the product information. When you're done, compile this class.
  5. Edit the Employee class so it implements the DepartmentConstants and Displayable interfaces. The getDisplayText method in this class should work like the one in the Product class, and it should use the constants in the DepartmentConstants interface to include the department name in the return value. When you're done, compile this class.
  6. Use the classes that implement the interfaces

  7. Display the DisplayableTestApp class.
  8. Add code to this class that creates an Employee object, assigns it to a Displayable variable, and displays the information in the Employee object at the console. To get the information for an employee, you'll need to use the getDisplayText method of the Displayable interface.

  9. Compile and run the application to make sure that it displays the employee information.

  10. Repeat steps 6 and 7 for a Product object.
Include in your program the following comments:
  • Name of program
  • Team's name with all the names of the members (e.g. Team A: John Doe, Jane Smith, etc.)
  • Current Date
  • Computer system and compiler you are using
  • Brief description of the program

Compile and run the Java program.

When you are ready, upload the java program by clicking the link below:

Upload Lab

I cannot grade if I don't get the file and receive your email.