Some of you are having trouble with this assignment. Here are 11 (fairly easy) steps that should help you get a good start if you're having a lot of trouble.
You don't have to follow these steps, they are just suggestions. But if you're lost, they're a great place to start.
Here, I'll start those last two bits for you:
case 'q':
// Quit
break;
case 'c':
// Create new clothing.
createItem( in, inventory );
break;
// Add your other commands here.
Notice the 'in' parameter -- you need to pass in the BufferedReader so you
can continue to read from it in Driver.createItem().
Simplicity is key! For example, feel free to store the size as a String, so you can store both "13" and "medium", depending on the subclass.
Also create various methods for listing the types of clothing that your inventory can handle; this will be useful when prompting the user for what type of clothing to create, and so on. In fact, here's a pair of methods that will do just that. You can put these in your inventory class:
// A list of the types of clothes that I sell.
private String[] clothes = {
"csc324.clothes.TShirt",
"csc324.clothes.CasualShirt",
"csc324.clothes.DressShirt",
"csc324.clothes.Sweater",
"csc324.clothes.DressPant",
"csc324.clothes.Jeans",
"csc324.clothes.Shorts"
};
// Return the types of clothes I sell.
public String[] getClothingTypes() {
return clothes;
}
// Find out what type of clothes to create.
System.out.println(" Select from the following list:" );
String[] clothingTypes = inventory.getClothingTypes();
// Print each type of clothing to the screen.
for( int i=0; i < clothingTypes.length; i++ ) {
System.out.println( " " + i + " " + clothingTypes[i] );
}
Clothes c; // A reference to the item of clothing being created.
try {
// Read the type of clothing that the user wants to create.
String line = in.readLine();
int whichClothingType = Integer.parseInt( line );
// This is a nifty way to get an instance of what the user wants;
// you can read all about it in the Java APIs, linked from the
// main page.
c = (Clothes) ( Class.forName(
clothingTypes[whichClothingType] ).newInstance() );
} catch( Exception e ) {
e.printStackTrace();
}