-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathClient.java
More file actions
64 lines (60 loc) · 2.42 KB
/
Client.java
File metadata and controls
64 lines (60 loc) · 2.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/**
* Client Side of a Share Market System made in Java RMI
*
* @author Yoan Ribeiro
*
*/
import java.rmi.Naming;
import java.rmi.RMISecurityManager;
import java.io.BufferedReader;
import java.io.InputStreamReader;
public class Client
{
public static void main( String[] args )
{
if (System.getSecurityManager() == null)
System.setSecurityManager(new RMISecurityManager());
BufferedReader stdIn = new BufferedReader(new InputStreamReader(System.in));
String userIn = new String();
try
{
Broker market = (Broker)Naming.lookup("rmi://localhost/broker");
while(userIn != null)
{
Share s = new Share();
System.out.print("Order? BUY/SELL\n> ");
userIn = stdIn.readLine();
if(userIn.equals("BUY"))
{
System.out.print("\nSymbol?\n> ");
userIn = stdIn.readLine();
Stock stock = (Stock)market.lookup(userIn);
Notif cb = new NotifImpl( "BOUGHT", userIn );
System.out.print("\nQuantity?\n> ");
userIn = stdIn.readLine();
s.quantity = (Integer.parseInt(userIn));
System.out.print("\nLimit Price?\n> ");
userIn = stdIn.readLine();
s.limit_price = Float.parseFloat(userIn);
stock.buy(s.quantity, s.limit_price, cb);
}
else
if(userIn.equals("SELL"))
{
System.out.print("\nSymbol?\n> ");
userIn = stdIn.readLine();
Stock stock = market.lookup(userIn);
Notif cb = new NotifImpl( "SOLD", userIn );
System.out.print("\nQuantity?\n> ");
userIn = stdIn.readLine();
s.quantity = (Integer.parseInt(userIn));
System.out.print("\nLimit Price?\n> ");
userIn = stdIn.readLine();
s.limit_price = Float.parseFloat(userIn);
stock.sell(s.quantity, s.limit_price, cb);
}
}
}
catch(Exception e) { e.printStackTrace(); }
}
}