-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQ5 Stock.java
More file actions
56 lines (50 loc) · 1.2 KB
/
Q5 Stock.java
File metadata and controls
56 lines (50 loc) · 1.2 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
class Stock
{
String item;
int qt;
double rate;
double amt;
public Stock(String item, int qt, double rate)
{
this.item = item;
this.qt = qt;
this.rate = rate;
this.amt = qt * rate;
}
public void display()
{
System.out.println("Item Name: " + item);
System.out.println("Quantity in Stock: " + qt);
System.out.println("Unit Price: " + rate);
System.out.println("Net Value in Stock: " + amt);
}
}
class Purchase extends Stock
{
int pqty;
double prate;
public Purchase(String item, int qt, double rate, int pqty, double prate)
{
super(item, qt, rate);
this.pqty = pqty;
this.prate = prate;
}
public void update()
{
qt += pqty;
if (prate != rate)
{
rate = prate;
}
amt = qt * rate;
}
@Override
public void display()
{
super.display();
System.out.println("Purchased Quantity: " + pqty);
System.out.println("Purchase Rate: " + prate);
System.out.println("Updated Quantity in Stock: " + qt);
System.out.println("Updated Net Value in Stock: " + amt);
}
}