-
Notifications
You must be signed in to change notification settings - Fork 0
/
ShoppingList.java
171 lines (131 loc) · 5.03 KB
/
ShoppingList.java
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
import java.util.Scanner;
class Item{
String name;
String description;
int price;
public void viewFullDescription(){
System.out.println("\nEnter the name of the item: ");
Scanner it = new Scanner(System.in);
name = it.nextLine();
System.out.println("\nEnter the description: ");
description = it.nextLine();
System.out.println("\nEnter the price: ");
price = it.nextInt();
System.out.println("name"+"\t"+"description"+"\t"+"price");
System.out.println(name+"\t"+description+"\t"+price);
}
public void addToShoppingBasket(){
System.out.println("\nYour item is added to shopping basket");
}
public void removeFromShoppingBasket(){
System.out.println("\nYour item is removed from shopping basket");
}
}
class Mp3 extends Item{
String artist;
String duration;
String song;
public void play(){
System.out.println("\nEnter the name of the song: ");
Scanner sc = new Scanner(System.in);
song = sc.nextLine();
System.out.println("\nThe name of the song is: "+song);
System.out.println("\n");
System.out.println("\nEnter the artist who sang this song: ");
artist = sc.nextLine();
System.out.println("The artist who sang this song is: "+artist);
System.out.println("\n");
System.out.println("\nEnter the duration: ");
duration = sc.nextLine();
System.out.println("\nThe duration of this song is: "+duration);
System.out.println("\n");
}
public void download(){
System.out.println("\nEnter the name of the song to be downloaded: ");
Scanner sc = new Scanner(System.in);
song = sc.nextLine();
System.out.println("\nThe song you downloaded is: "+song);
}
void displayMp3(){
System.out.println("\n");
System.out.println(song+"\t"+artist+"\t"+duration);
}
}
class DVD extends Item{
String certificate;
String duration;
String actors;
String movie;
public void ViewTrailer(){
System.out.println("Enter the name of the movie: ");
Scanner sc = new Scanner(System.in);
movie = sc.nextLine();
System.out.println("The name of the movie in which we are viewing the trailer is: "+movie);
System.out.println("Enter the certificate: ");
certificate = sc.nextLine();
System.out.println("The certificate is: "+certificate);
System.out.println("Enter the duration: ");
duration = sc.nextLine();
System.out.println("The duration is: "+duration);
System.out.println("Enter the actors: ");
actors = sc.nextLine();
System.out.println("The actors are: "+actors);
}
void displayDVD(){
System.out.println(movie+"\t"+certificate+"\t"+duration+"\t"+actors);
}
}
class Book extends Item{
String bookname;
String author;
int numberOfPages;
String genre;
public void previewContent(){
System.out.println("Enter the name of the book: ");
Scanner sc = new Scanner(System.in);
Scanner sc1 = new Scanner(System.in);
bookname = sc.nextLine();
System.out.println("The name of the book in which we are previewing the content is: "+bookname);
System.out.println("Enter the author: ");
author = sc.nextLine();
System.out.println("The author who wrote the book is: "+author);
System.out.println("Enter the number of pages: ");
numberOfPages = sc1.nextInt();
System.out.println("The number of pages are: "+numberOfPages);
System.out.println("Enter the genre: ");
genre = sc.nextLine();
System.out.println("The genre is: "+genre);
}
void displayBook(){
System.out.println(bookname+"\t"+author+"\t"+numberOfPages+"\t"+genre);
}
}
public class Iteminheritance {
public static void main(String[] args) {
String song = " ";
String movie = " ";
String bookname = " ";
Item item = new Item();
Mp3 mp3 = new Mp3();
DVD dvd = new DVD();
Book book = new Book();
item.viewFullDescription();
item.addToShoppingBasket();
mp3.play();
System.out.println("song"+"\t"+"artist"+"\t "+"duration");
mp3.displayMp3();
item.removeFromShoppingBasket();
item.viewFullDescription();
item.addToShoppingBasket();
dvd.ViewTrailer();
System.out.println("movie"+"\t"+"certificate"+"\t"+"duration"+"\t"+"actors");
dvd.displayDVD();
item.removeFromShoppingBasket();
item.viewFullDescription();
item.addToShoppingBasket();
book.previewContent();
System.out.println("bookname"+"\t"+"author"+"\t "+"noofPages"+"\t"+"genre");
book.displayBook();
item.removeFromShoppingBasket();
}
}