Listing 8. The BigBuyer class using Observable:
public class BigBuyer implements Observer
{
private String symbol;
private float close;
private float high;
private float low;
private long volume;
public BigBuyer(Observable observable)
{
observable.addObserver(this);
}
public void update(Observable observable,Object args)
{
if(observable instanceof StockData)
{
StockData stockData = (StockData)observable;
this.symbol = stockData.getSymbol();
this.close = stockData.getClose();
this.high = stockData.getHigh();
this.low = stockData.getLow();
this.volume = stockData.getVolume();
display();
}
}
public void display()
{
DecimalFormatSymbols dfs = new DecimalFormatSymbols();
DecimalFormat volumeFormat = new DecimalFormat("###,###,###,###",dfs);
DecimalFormat priceFormat = new DecimalFormat("###.00",dfs);
System.out.println("Big Buyer reports... ");
System.out.println("\tThe lastest stock quote for " + symbol + " is:");
System.out.println("\t$" + priceFormat.format(close) + " per share (close).");
System.out.println("\t$" + priceFormat.format(high) + " per share (high).");
System.out.println("\t$" + priceFormat.format(low) + " per share (low).");
System.out.println("\t" + volumeFormat.format(volume) + " shares traded.");
System.out.println();
}
}
New on the Java Boutique:
New Review:
Time Management Made Easy with the Quartz Enterprise Job Scheduler
Why not just use the Java timer API? This open source scheduling
API boasts simplicity, ease-of-integration, a well-rounded feature
set, and it's free!
New Applet:
Reverse Complement
Reverse Complement is a simple applet that converts DNA or RNA
sequences into three useful formats.
Elsewhere on internet.com:
WebDeveloper Java
Lots of Java information on webdeveloper.com
WDVL Java
Thorough Java resource at the Web Developer's Virtual Library.
ScriptSearch Java
Hundreds of free Java code files to download.
jGuru: Your View of the Java Universe
Customizable portal with online training, FAQs, regular news updates, and tutorials.
|