Class Project2

Object
  extended byProject2
All Implemented Interfaces:
IBM

public class Project2
extends Object
implements IBM

The Project 2 main class.


Field Summary
 
Fields inherited from interface IBM
GOLD, metalName, METALS, PLATINUM, URANIUM
 
Constructor Summary
Project2()
           
 
Method Summary
static void debug(Object message)
          If the debugging flag is on, prints a message, preceded by the name of the current thread.
static void main(String[] args)
          Main program for project 2.
static String orderToString(int[] order)
          Turns an order into a printable string.
static int randInt(int max)
          Utility to generate a random integer in the range 0 <= x < max.
static int randInt(int min, int max)
          Utility to generate a random integer in the range min <= x <= max.
static void setVerbose(boolean on)
          Turns debugging output on or off.
static Broker specialist(int metal)
          Returns the specialist for a given metal.
static void terminateProgram()
          Gathers allocation information from the Refiner, Consumers, and Brokers and prints it.
 
Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Project2

public Project2()
Method Detail

setVerbose

public static void setVerbose(boolean on)
Turns debugging output on or off.

Parameters:
on - if true, turn debugging on; otherwise turn it off.

specialist

public static Broker specialist(int metal)
Returns the specialist for a given metal.

Parameters:
metal - the metal code.
Returns:
the Broker that specializes in this metal.

debug

public static void debug(Object message)
If the debugging flag is on, prints a message, preceded by the name of the current thread. If it is off, does nothing.

Parameters:
message - the message to print.

orderToString

public static String orderToString(int[] order)
Turns an order into a printable string.

Parameters:
order - an indication of the amount of each metal desired.
Returns:
a string such as "[1 ounce gold, 2 ounces platinum, 0 ounces urantim]"

randInt

public static int randInt(int max)
Utility to generate a random integer in the range 0 <= x < max.

Parameters:
max - integer one greater than the largest possible result.
Returns:
a non-negative integer strictly less than max.

randInt

public static int randInt(int min,
                          int max)
Utility to generate a random integer in the range min <= x <= max.

Parameters:
min - the smallest possible result.
max - the largest possible result.
Returns:
an integer between min and max, inclusive.

main

public static void main(String[] args)
Main program for project 2.

Parameters:
args - the command-line arguments.

terminateProgram

public static void terminateProgram()
Gathers allocation information from the Refiner, Consumers, and Brokers and prints it. Then interrupts all the Consumer threads.