CSCE 145 Lab Test 2

Section 6

This lab is to be done with NO COMMUNICATION with others. You MAY use your book, notes, class slides on Blackboard, APIs (Java and Robots), past labs, and past homework; basically any materials directly related to the class. Outside materials or help from others is not allowed. You must dropbox the .java files by the end of this lab period (see bottom of page).

Overview

You will create a simple program that keeps track of the shoes in your closet.

Program

You need to create 2 classes, Shoe and Closet. Shoe has 2 instance variables: (String) brand, and (String) color. Closet holds exactly 3 Shoe objects as instance variables. The Closet class has a method called public void showCloset( ) that prints out the contents of the closet. EACH CLASS should have accessors and mutators for all instance variables and 2 constructors: one a default (no parameters) and the other accepts parameters for all variables.

Create a driver that interacts with a user via the console. The program should ask the user for the 3 Shoes, put them into a  new Closet object, then print the entire contents of the closet. You can assume the user will enter the information in exactly the same format (brand, a comma, color) as shown in the example below.

In order to use a 'comma' as the delimiter when reading in the Shoe information from the console, use the following piece of code to instantiate the Scanner object.
Scanner console = new Scanner(System.in).useDelimiter(",");
In the past we have used the Scanner class with the default 'space' delimiter. Using a 'comma' as the delimiter will result in console.next( ) returning the next sequence of characters until a 'comma' is encountered. This said, you might have to do multiple console.next( ) calls to get all the console input.

Example Output

Please describe the 1st shoe:

Nike, black

Please describe the 2nd shoe:

Converse, blue

Please describe the 3rd shoe:

Sketchers, orange

The shoes in the closet are:

Nike, black

Converse, blue

Sketchers, orange

 

DROPBOX YOUR .java FILES BEFORE 6:05pm (end of lab)! Don't wait until the last minute!