-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStock.java
More file actions
51 lines (35 loc) · 918 Bytes
/
Copy pathStock.java
File metadata and controls
51 lines (35 loc) · 918 Bytes
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
/*
* @author Joel Delgado jode9188
* Prog2 - VT2020
* Assignment 1 - Part 2
* @version: 2.1
*/
import java.text.DecimalFormat;
public class Stock extends Valuable {
private int quantity;
private double rate;
public Stock(String name, int quantity, double rate) {
super(name);
this.quantity = quantity;
this.rate = rate;
}
public int getQuantity() {
return quantity;
}
public double getRate() {
return rate;
}
public void setRate(double rate) {
this.rate = rate;
}
@Override
public double getValue() {
return quantity * rate;
}
@Override
public String toString() {
DecimalFormat df = new DecimalFormat("0.00");
return String.format("%-15s quantity: %4d \tshare price: %8s \tvalue: %11s \t+VAT: %11s",
getName(), getQuantity(), df.format(getRate()), df.format(getValue()), df.format(getValuePlusVAT()));
}
}