-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQuote.java
More file actions
58 lines (50 loc) · 1.63 KB
/
Quote.java
File metadata and controls
58 lines (50 loc) · 1.63 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
package tradable;
import book.BookSide;
import price.Price;
public class Quote {
private String user;
private String product;
private QuoteSide buySide;
private QuoteSide sellSide;
public Quote(String symbol, Price buyPrice, int buyVolume, Price sellPrice, int sellVolume, String userName) throws InvalidInput {
setUser(userName);
setProduct(symbol);
buySide = new QuoteSide(userName, symbol, buyPrice, buyVolume, BookSide.BUY);
sellSide = new QuoteSide(userName, symbol, sellPrice, sellVolume, BookSide.SELL);
}
private void setUser(String user) throws InvalidInput {
if(user.length() != 3) {
throw new InvalidInput("Invalid username length");
}
for(char c: user.toCharArray()) {
if(!Character.isLetter(c)) {
throw new InvalidInput("Invalid username character");
}
}
this.user = user;
}
private void setProduct(String product) throws InvalidInput {
if(product.length() < 1 || product.length() > 5) {
throw new InvalidInput("Invalid product length");
}
for(char c: product.toCharArray()) {
if(!Character.isLetter(c) || c == '.') {
throw new InvalidInput("Invalid product character");
}
}
this.product = product;
}
public QuoteSide getQuoteSide(BookSide sideIn){
if(sideIn == BookSide.BUY){
return buySide;
}else{
return sellSide;
}
}
public String getSymbol(){
return product;
}
public String getUser(){
return user;
}
}