CIS 35A: Introduction to Java Programming

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

Lab #6 (Exercise 7-2)

Create a Product application that uses inheritance

Due Date: Thursday of Week 2
10 points

In this lab, you'll create a Product application like the one presented in this chapter that uses inheritance. However, you will add an additional kind of product: compact discs. To make this application easier to develop, we'll give you most of the starting classes.

    Create a new subclass named CompactDisc

  1. Copy and paste the codes below:
  2. Product class

    Book class

    Software class

    ProductDB class

    ProductApp class

  3. Add a class named CompactDisc that inherits the Product class. This new class should work like the Book and Software classes, but it should include public get and set methods for a private instance variable named artist. In addition, it should include a toString method that overrides the toString method in the Product class. This method should append the artist name to the end of the string.

  4. Compile the CompactDisc class to make sure that it doesn't contain any syntax errors.
  5. Modify the ProductDB class so it returns a CompactDisc object

  6. Modify the ProductDB class so it creates at least one CompactDisc object. For example, this object might contain the following information:
  7. Cose:        sgtp
    Description: Sgt. Pepper's Lonely Hearts Club Band
    Price:       $15.00
    Artist:      The Beatles
    
  8. Compile this class and run the application to make sure it works.
  9. Add a protected variable

  10. Open the Product class and change the access modifier for the count varaible from public to protected.

  11. Compile this class, and then run the application one more time to make sure that the count is maintained properly.
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.

Take a screen capture by hitting simultaneously the keys Alt and Print Screen (Prt Sc) of the output results (console) and paste it in MS Paint. Save it as a gif file.

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

Upload Lab

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