Class Customer

java.lang.Object
  |
  +--Customer
All Implemented Interfaces:
Enron, Runnable

public class Customer
extends Object
implements Runnable, Enron

CS 537, Fall 2002, Project 3. An energy customer.

Copyright © 2002 by Marvin Solomon. All rights reserved.


Field Summary
private  int[] consumed
          Total consumed thus far
private static DecimalFormat fmt
          A format for printing fractions to two decimal places.
private  int id
          Id of this customer
private  int[] maxPurchase
          Mean amount of each quantity to purchase on each request.
private  int meanSleepTime
          Mean sleep time (in milliseconds) between purchase requests.
private  int numberOfPurchases
          Number of buying requests completed by this Consumer
private  Random rand
          A source of random numbers.
private  int totalServiceTime
          Sum of service times for all requests
private  Trader trader
          The trader to buy from.
 
Fields inherited from interface Enron
cname, COAL, COMMODITIES, cunit, ELEC, GAS, OIL
 
Constructor Summary
Customer(int id, Trader trader)
          Create a new Customer object.
 
Method Summary
private static void pl(Object o)
          Abbreviation for System.out.println.
 void printReport()
          Print information about the history of this customer.
 void run()
          Main loop.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

id

private int id
Id of this customer


trader

private Trader trader
The trader to buy from.


meanSleepTime

private int meanSleepTime
Mean sleep time (in milliseconds) between purchase requests.


maxPurchase

private int[] maxPurchase
Mean amount of each quantity to purchase on each request.


consumed

private int[] consumed
Total consumed thus far


numberOfPurchases

private int numberOfPurchases
Number of buying requests completed by this Consumer


totalServiceTime

private int totalServiceTime
Sum of service times for all requests


rand

private Random rand
A source of random numbers.


fmt

private static DecimalFormat fmt
A format for printing fractions to two decimal places.

Constructor Detail

Customer

public Customer(int id,
                Trader trader)
Create a new Customer object.

Parameters:
id - the unique id of this customer.
trader - the trader to contact to buy stuff.
Method Detail

pl

private static void pl(Object o)
Abbreviation for System.out.println.

Parameters:
o - the object to be printed.

printReport

public void printReport()
Print information about the history of this customer.


run

public void run()
Main loop. Repeatedly generate random buy orders to the trader until the trader tells us to stop. Then print some info and return.

Specified by:
run in interface Runnable