CS 231: Lab #4

The goal of this lab period is to get you started on the current assignment and give you an introduction to Interfaces.

Documentation for Java 1.5 is located at: Java 1.5 SE API.

Documentation for Java 1.6 is located at: Java 1.6 SE API

Tasks

  1. Think about the concept of an inventory. What are the things an inventory needs to do?
    • Stock - put things into the inventory
    • Consume - take things out of the inventory
    • Query - discover what is in the inventory

    An interface allows us to specify a set of methods a class must implement in order to qualify as a member of that type.

  2. Create a Stuff class that has a string descriptor (name) and a quantity (amount), and give it some accessor methods.
  3. Create an inventory interface: just the three method descriptors: Stock, Consume, and Query. What should their input and output forms be?
  4. Create a class Backpack that implements the inventory interface. It should be able to hold up to five things (Stuff). You can use the skeleton file to get started.

Once you are comfortable with the above tasks, go on to the assignment.