-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathA Video Rental Inventory System The goal of this project is to design and implement a simple inventory control system for a small video rental store. Define least two classes: a class Video to model a video and a class VideoStore to model the actual store.
161 lines (146 loc) · 4.87 KB
/
A Video Rental Inventory System The goal of this project is to design and implement a simple inventory control system for a small video rental store. Define least two classes: a class Video to model a video and a class VideoStore to model the actual store.
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
package inheritance;
import java.util.ArrayList;
import java.util.Scanner;
class video {
private String videoName;
private boolean checkout;
private int rating;
public video(String name) {
videoName = name;
}
public String getName() {
return videoName;
}
public void doCheckout() {
checkout = true;
}
public void doReturn() {
checkout = false;
}
public void receiveRating(int rating) {
this.rating = rating;
}
public int getRating() {
return rating;
}
public boolean getCheckout() {
return checkout;
}
}
class VideoStore {
private ArrayList<video> store = new ArrayList<video>();
public void addVideo(String name) {
video vid = new video(name);
store.add(vid);
}
public void doCheckout(String name) {
if (store == null || store.size() == 0) {
System.out.println("Store is empty");
return;
}
for (video vid : store) {
if (vid.getName().equals(name)) {
vid.doCheckout();
}
}
}
public void doReturn(String name) {
if (store == null || store.size() == 0) {
System.out.println("Store is empty");
return;
}
for (video vid : store) {
if (vid.getName().equals(name)) {
vid.doReturn();
}
}
}
public void receiveRating(String name, int rating) {
if (store == null || store.size() == 0) {
System.out.println("Store is empty");
return;
}
for (video vid : store) {
if (vid.getName().equals(name)) {
vid.receiveRating(rating);
}
}
}
public void listInventory() {
if (store == null || store.size() == 0) {
System.out.println("Store is empty");
return;
}
for (int i = 0; i < 80; i++)
System.out.print("-");
System.out.println();
System.out.println("Name | Rating |Checkout ");
for (int i = 0; i < 80; i++)
System.out.print("-");
System.out.println();
for (video vid : store) {
String name = vid.getName();
int rating = vid.getRating();
boolean chekout = vid.getCheckout();
System.out.print(name + " ");
System.out.print(rating + " ");
System.out.println(chekout);
}
for (int i = 0; i < 80; i++)
System.out.print("-");
}
}
public class store {
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
VideoStore store = new VideoStore();
int choice = 0;
do {
System.out.println("\n1. Add Videos: \n" +
"2. Check Out Video: \n" +
"3. Return Video: \n" +
"4. Receive Rating: \n" +
"5. List Inventory: \n" +
"6. Exit: \n" +
"Enter your choice (1..6): ");
choice = sc.hasNextInt() ? sc.nextInt() : 6;
sc.nextLine();
String name;
switch (choice) {
case 1:
System.out.println("Enter the name of the video you want to Add: ");
name = sc.nextLine();
store.addVideo(name);
System.out.println("Video " + name + " added out successfully.");
break;
case 2:
System.out.println("Enter the name of the video you want to Checkout: ");
name = sc.nextLine();
store.doCheckout(name);
System.out.println("Video " + name + " checked out successfully.");
break;
case 3:
System.out.println("Enter the name of the video you want to Return: ");
name = sc.nextLine();
store.doReturn(name);
System.out.println("Video " + name + " returned successfully.");
break;
case 4:
System.out.println("Enter the name of the video you want to Rate: ");
name = sc.nextLine();
System.out.println("Enter the rating for this video: ");
int rating = sc.nextInt();
store.receiveRating(name, rating);
System.out.println("Rating " + rating + " has been mapped to the Video " + name + ".");
break;
case 5:
store.listInventory();
break;
default:
System.out.println("Exiting...!! Thanks for using the application.");
break;
}
} while (choice != 6);
sc.close();
}
}