210 likes | 282 Views
Distributed Systems Lab. Simple Exchange Application. Part1. Project Description. It is extremely simplified application will be realized with the aid of various middleware technologies.
E N D
Distributed Systems Lab Simple Exchange Application
Project Description • It is extremely simplified application will be realized with the aid of various middleware technologies. • It allows the retrieval of information on market prices and exchange rate developments, as well as managing the stock deposit. • The application will also allows the user to play a game during observing the prices of the stock market. • such Sudoku, Zuma or else. Distributed Systems Lab
Application Database • It will be MySQL database stores the companies prices in the market and users login and balance details. • The database tables will be: • CO_Name • CO_ID (primary key): ID of the limited company and it is an integer. • CO_NAME: String, name of the company. • CO_Data: • ID (primary key): it is an integer. • C_ID: ID of the company, which is integer also. • DAY: we will assume that has taken place every working day trade and day as an integer number (1 .. 31). • SHARE_VALUE: Current share price that day and it is a double number (0.01 to 9999.99 EUR). Distributed Systems Lab
Application Database Cont. • USER • U_ID (primary key): ID of the limited company and it is an integer. • U_NAME: String, name of the company. • U_PSWD: • USER_TRANS: // user transaction history • ID (primary key): it is an integer. • C_ID: ID of the company, which is integer also. • U_ID: • DAY: we will assume that has taken place every working day trade and day as an integer number (1 .. 31). • TRANS_TYPE: • AMOUNT: int amount Distributed Systems Lab
Implementation • Application will be implemented as following: • ConnectDB Class • exchangeClient Class • GameClass • Note: • Interface or abstract class. Which one should you use on the project. Distributed Systems Lab
ConnectDB Class • / / Constructor, loads the DB driverpublic ConnectDB () • MySql DB url: jdbc:mysql://host_name:port/dbname • MySql Driver: com.mysql.jdbc.Driver • Class.forName("com.mysql.jdbc.Driver").newInstance(); //load the driver • Connection dcon = DriverManager.getConnection(DB url, “username", “password");//start a connection • / / Opens a connection to the databasepublic booleanOpenDB () • if(!dcon.isClosed()) // check if the connection is open • / / Closes an existing connection to the databasepublic booleanCloseDB () • dcon.close(); Distributed Systems Lab
ConnectDB Class Cont. • / / Takes the SQL string from the open DB and return ResultSet. on error SQLException is thrown public ResultSet executeDB (String SQL) //define statement object to execute sql query Statement stat = dcon.createStatement(); //results of sql query returns in a ResultSet object ResultSet rs = stat.executeQuery("select * from table where “); if (!rs.next()) { //if no results found rs.close(); stat.close(); dcon.close(); } else { // action code } • / / Returns the error message of the last executed SQL command. if the command was successful, "OK" would be returned public String getStatus () Distributed Systems Lab
exchangeClient Class • public String CreateUser(String name, String pwrd) • It returns string on success like “your account is created successfully ” , or if there is any problem during the creation such as the duplication of the user name, empty field it returns message of that problem. • public String Login (String name, String pwrd) • If there is any problem during the login process such as the name is not exist in the DB it returns message of it . Otherwise it returns welcoming message. Distributed Systems Lab
exchangeClient Class Cont. • public String [] GetAllCompanies () • Returns a list of all Company names in an array of strings. • public double GetValue (int x, String Company) • It returns the price of the share of the Company on day X (1 .. 31). When entering an invalid date and / or Company-name is not exist will return "-1.0". Distributed Systems Lab
exchangeClient Class Cont. • public double BigWinnerGain (int X, int Y) • Investigated the stock during the period between the 2 days X (1 .. 30) and Y (X. .. 31) the largest percentage gain • With Y > X and K (X) = price at the date X has generated. The output is the percentage value of the price. Distributed Systems Lab
exchangeClient Class Cont. • public String BigWinnerCompany (int X, int Y)As the previous method, but the name of the concerned Company is returned. Distributed Systems Lab
exchangeClient Class Cont. • public double Variance (String Company)Calculates the sensitivity of the price of a given Company-Name over the entire month. First, calculate the arithmetic mean with all the prices of the share xi of n days. • The standard deviation can then be calculated from the following equation. Distributed Systems Lab
exchangeClient Class Cont. • public int Tendency (int X1)Sums the overall performance by all the companies on a given day X1 (1 .. 30) . The same happens for the following day X2 = X1 +1. The trend is as Integer value returned from the following equations: 0 - strongly positive (SumX2> SumX1 + 250) 1 - positive (SumX2 > SumX1 + 80) AND (SumX2 ≤ SumX1 +250) 2 - neutral (SumX2 > SumX1- 80) AND (SumX2 ≤ SumX1 +80) 3 - negative (SumX2 > SumX1-250) AND (SumX2 ≤ SumX1-80) 4 - strongly negative (SumX2 < SumX1-250) Distributed Systems Lab
exchangeClient Class Cont. • public boolean Buy (String Company, int amount) * Buy a quantity of shares of a corporation at the current rate on 31 Day. Upon successful transaction, it returns true, otherwise false. • public void Sell (String Company, int amount) *Selling a set M of shares of a corporation at the current rate on 31 Day. Upon successful transaction, it returns true, otherwise false. Distributed Systems Lab
exchangeClient Class Cont. • public int StockAmount (String CO) *Returns the number of the shares of the Company CO, which one has in its custody. • public double StockValue (String CO) *Returns the value of the shares of the Company CO, which one has in its custody. By the price of 31 Day is used. Distributed Systems Lab
Notes • These guides to help you implementing your project. • You can add or edit if you think it convenient to your project in which you will mention it in your report. Distributed Systems Lab
Resources • http://www.roseindia.net/jdbc/jdbc.shtml • http://www.stardeveloper.com/articles/display.html?article=2003090401&page=1 Distributed Systems Lab