////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //PIMS: Personal Invstment Management System //Class : CurrentValueSystem //Use:Downloads the current prices from the net and gives the price //of the asked share ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// import java.lang.*; import java.io.*; import java.util.*; import java.net.*; import java.awt.*; public class CurrentValueSystem{ private dataRepository DR; private NetLoader NL; private ProxyLoader PL; private int numShares = 0; private String shares[][]; private boolean read = false; public CurrentValueSystem(dataRepository DR, boolean downloadOption)throws Exception{ this.DR = DR; //Initialize the NetLoader NL = new NetLoader(DR, downloadOption);//initialize the net loader //Initialize the NetLoader PL = new ProxyLoader(DR); //initially read the prices of shares from the prices file. shares =DR.readSharePriceFromFile(); //Counting the number of shares. while(shares[numShares][0] != null)numShares++; } public CurrentValueSystem(dataRepository DR )throws Exception{ this.DR = DR; //Initialize the NetLoader PL = new ProxyLoader(DR); //initially read the prices of shares from the prices file. shares =DR.readSharePriceFromFile(); //Counting the number of shares. while(shares[numShares][0] != null)numShares++; } //This method invokes the NetLoader which updates the share prices, //by downloading the current price from the remote database. public void UpdateCurrentPrice()throws Exception{ Thread th = new Thread(NL); th.start(); read = true; } //This method invokes the NetLoader which updates the share prices, //by downloading the current price from the remote database. public void UpdateCurrentPrice(boolean b)throws Exception{ Thread th = new Thread(PL); th.start(); read = true; } //This method returns the list of all shares with their current price public String[][] readSharePrices(){ return(shares); } //This method returns the price fo a specified share. public double priceOfShare(String code)throws Exception{ int i; if(read){ //Now read the updated share price values. shares = DR.readSharePriceFromFile(); //Count the number of shares. while(shares[numShares][0] != null)numShares++; read = false; } for(i=0;i