-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBookShop
More file actions
115 lines (98 loc) · 2.28 KB
/
BookShop
File metadata and controls
115 lines (98 loc) · 2.28 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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
//A program to show inheritance in the form of a BookShop
class Publication
{
String title;
double price;
//Constructor of Publication with parameters
public Publication(String title, double price)
{
this.title=title;
this.price=price;
}
public void display()
{
System.out.println("The Title of the Book: " + title);
System.out.println("The price of the Book: " + price);
}
}
//Making Child class Book of parent class Publication which is also implementing interface Sales
class Book extends Publication implements Sales
{
int count;
static double sales;
//Constructor of Book with parameters
public Book(String title,double price,int count)
{
super(title,price);
this.count=count;
}
//Display function
public void display()
{
super.display();
System.out.println("Number of pages are: "+count);
}
//Function for Sales
public void InputSales()
{
sales += price;
}
//Function for displaying Sales
public void DisplaySales()
{
System.out.println("The sales of Books currently are: " + sales);
}
}
//Making Child class Tape of parent class Publication which is also implementing interface Sales
class Tape extends Publication implements Sales
{
double time;
static double sales;
//Constructor of Tape with parameters
public Tape(String title, double price, double time)
{
super(title,price);
this.time= time;
}
//Display function
public void display()
{
super.display();
System.out.println("Playing time is " + time + " hrs");
}
//Function for Sales
public void InputSales()
{
sales += price;
}
//Function for displaying Sales
public void DisplaySales()
{
System.out.println("The sales of Tapes currently are: " + sales);
}
}
//Made an Interface
interface Sales
{
public void InputSales();
public void DisplaySales();
}
public class BookShop
{
public static void main(String args[])
{
Book book1 = new Book("It's not your Story",150,220);
Book book2 = new Book("The Fault in our Stars",300,450);
Tape tape1 = new Tape("The Story of my life",500,4);
Tape tape2 = new Tape("It's You",280,3.5);
//Made Objects and called functions from them
book1.InputSales();
book1.DisplaySales();
book2.InputSales();
book2.DisplaySales();
tape1.InputSales();
tape1.DisplaySales();
tape2.InputSales();
tape2.DisplaySales();
}
}