forked from slgobinath/Java-Helps-Java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSingleSales.java
More file actions
43 lines (35 loc) · 844 Bytes
/
SingleSales.java
File metadata and controls
43 lines (35 loc) · 844 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
public class SingleSales {
public static void main(String[] args) {
doStuff(new Pen(10.00));
doStuff(new Book(250.00, 5.00));
}
public static void doStuff(Sellable item) {
double income = item.sell();
System.out.println("Income: $" + income);
}
}
interface Sellable {
double sell();
}
class Book implements Sellable {
private double price;
private double discount;
public Book(double price, double discount) {
this.price = price;
this.discount = discount;
}
@Override
public double sell() {
return price - (price * discount / 100.00);
}
}
class Pen implements Sellable {
private double price;
public Pen(double price) {
this.price = price;
}
@Override
public double sell() {
return price;
}
}