Repository navigation
Expand file tree
/
Copy pathTransaction.java
More file actions
91 lines (75 loc) · 2.07 KB
/
Copy pathTransaction.java
File metadata and controls
91 lines (75 loc) · 2.07 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
public class Transaction {
private String type;
private String stockSymbol;
private int quantity;
private double price;
private double totalAmount;
private double profitLoss;
private LocalDateTime dateTime;
public Transaction(
String type,
String stockSymbol,
int quantity,
double price,
double profitLoss) {
this.type = type;
this.stockSymbol = stockSymbol;
this.quantity = quantity;
this.price = price;
this.totalAmount = quantity * price;
this.profitLoss = profitLoss;
this.dateTime = LocalDateTime.now();
}
public Transaction(
String type,
String stockSymbol,
int quantity,
double price,
double profitLoss,
LocalDateTime dateTime) {
this.type = type;
this.stockSymbol = stockSymbol;
this.quantity = quantity;
this.price = price;
this.totalAmount = quantity * price;
this.profitLoss = profitLoss;
this.dateTime = dateTime;
}
public String getType() {
return type;
}
public String getStockSymbol() {
return stockSymbol;
}
public int getQuantity() {
return quantity;
}
public double getPrice() {
return price;
}
public double getTotalAmount() {
return totalAmount;
}
public double getProfitLoss() {
return profitLoss;
}
public LocalDateTime getDateTime() {
return dateTime;
}
public void displayTransaction() {
DateTimeFormatter formatter =
DateTimeFormatter.ofPattern("dd-MM-yyyy HH:mm:ss");
System.out.printf(
"%-6s %-8s %-8d $%-10.2f $%-12.2f $%-12.2f %s%n",
type,
stockSymbol,
quantity,
price,
totalAmount,
profitLoss,
dateTime.format(formatter)
);
}
}