I am having trouble were to declare the abstract classes for Widget, Sport and Grommet. They are not being read in the main part of the program could anyone tell me where to declare them so that they will be read.
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package javaapplication1;
/**
*
* @author Torbecire
*/
import java.io.*;
import java.util.StringTokenizer;
/***********************************
*
* A program to maintain a simple inventory
* consisting of three items.
*
* Written by Bob Matthews and <Your name here>
*
***********************************/
public class Project3
{
abstract class Part{
public int getQuantity (int Quantity)
{
return Quantity;
}
public void setQuantity(int Quantity)
{
}
public int increaseQuantity(int Quantity)
{
return Quantity;
}
public int decreaseQuanity(int Quantity)
{
return Quantity;
}
private int printInventory(int Widget, int Spork, int Grommet)
{
System.out.print(toString());
}
/*private String quit()
{
exit;
}*/
public String toString()
{
return (" who" + "ahh");
}
public abstract int Widget();
public abstract int Spork();
public abstract int Grommet();
}
// String constants for the four commands
// that the inventory control system
// understands.
static final String ADD_COMMAND = "add";
static final String REMOVE_COMMAND = "remove";
static final String QUIT_COMMAND = "quit";
static final String PRINT_COMMAND = "print";
// The number of different items in the
// inventory.
public static final int N_INVENTORY_ITEMS = 3;
// Convert a string containing an item name
// into its position in the inventory array.
public static int positionOf (String item)
{
// Convert the string to upper case, and
// then compare it to one of the items.
if (item.toUpperCase().equals("WIDGET"))
return 0;
else if (item.toUpperCase().equals("SPORK"))
return 1;
else if (item.toUpperCase().equals("GROMMET"))
return 2;
else
return -1;
}
// Read the next line from the user and return it as
// as string.
//
// Lines will have the form:
// <command> <item name> <quantity> for add and remove
// <command> for print and quit
public static String readCommandLine (BufferedReader keyboard)
{
String oneLine = "";
try
{
oneLine = keyboard.readLine();
}
catch (IOException e)
{
System.out.println ("Unexpected end of input.");
}
return oneLine;
}
public static void main (String [] args)
{
// The list of inventory items.
Part [] inventory = new Part [N_INVENTORY_ITEMS];
// The three pieces of data we read from
// the user.
String command; // The command
String item; // The number of items to manipulate
int quantity; // The quantity to manipulate
NOT READ HERE NOT READ BELOW
// Setup and initialize the inventory
inventory[0] = new Widget();
inventory[1] = new Spork();
inventory[2] = new Grommet();
ends here
// Setup the input.
BufferedReader keyboard = new BufferedReader
(new InputStreamReader (System.in));
StringTokenizer commandLine =
new StringTokenizer (readCommandLine(keyboard));
// Extract the first command from the command line.
command = commandLine.nextToken();
// Loop until the quit command is given.
while (! command.equals (QUIT_COMMAND))
{
// Add to the inventory
if (command.equals (ADD_COMMAND))
{
// Add items to inventory
item = commandLine.nextToken();
quantity = Integer.parseInt(commandLine.nextToken());
inventory[positionOf(item)]
.increaseQuantity(quantity);
}
// Remove from the inventory
else if (command.equals (REMOVE_COMMAND))
{
/* Insert commands here to remove items
from the inventory (if possible). */
}
// Print the inventory
else if (command.equals (PRINT_COMMAND))
{
/* Insert commands here to print
the inventory of all items.
Use a loop. */
}
// User entered a bad command
else
System.out.println ("Bad command.");
// Read the next line of input and extract
// the next command.
commandLine = new StringTokenizer (readCommandLine(keyboard));
command = commandLine.nextToken();
}
}
}