Some reformatting.
This commit is contained in:
parent
bdc4f794f5
commit
ae82904244
@ -1,25 +1,29 @@
|
|||||||
package StockExchange;
|
package StockExchange;
|
||||||
|
|
||||||
public class Account {
|
public class Account {
|
||||||
public long shares=0; // number of shares
|
|
||||||
public double money=0; // amount of money
|
/**
|
||||||
|
* Number of shares in this account
|
||||||
|
*/
|
||||||
|
public long shares = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Ammount of money in this account
|
||||||
|
*/
|
||||||
|
public double money = 0;
|
||||||
|
|
||||||
public String name = "";
|
public String name = "";
|
||||||
|
|
||||||
public boolean orderpending = false;
|
public boolean orderpending = false;
|
||||||
|
|
||||||
private double bound_money;
|
private double bound_money;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public void print_current() {
|
public void print_current() {
|
||||||
System.out.printf("%s shares: %d credit: %.2f\n",
|
System.out.printf("%s shares: %d credit: %.2f\n",
|
||||||
name, shares, money
|
name, shares, money
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public SellOrder Sell(long size, double limit, Exchange ex) {
|
public SellOrder Sell(long size, double limit, Exchange ex) {
|
||||||
SellOrder o = new SellOrder();
|
SellOrder o = new SellOrder();
|
||||||
o.account = this;
|
o.account = this;
|
||||||
@ -33,8 +37,9 @@ public class Account {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public BuyOrder Buy(long size, double limit, Exchange ex) {
|
public BuyOrder Buy(long size, double limit, Exchange ex) {
|
||||||
if (size * limit > money)
|
if (size * limit > money) {
|
||||||
return null;
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
BuyOrder o = new BuyOrder();
|
BuyOrder o = new BuyOrder();
|
||||||
o.limit = limit;
|
o.limit = limit;
|
||||||
@ -46,13 +51,11 @@ public class Account {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Buy( Account a,long size, double price)
|
public void Buy(Account a, long size, double price) {
|
||||||
{
|
|
||||||
shares += size;
|
shares += size;
|
||||||
money -= price * size;
|
money -= price * size;
|
||||||
a.shares -= size;
|
a.shares -= size;
|
||||||
a.money += price * size;
|
a.money += price * size;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user