-
Notifications
You must be signed in to change notification settings - Fork 0
/
Store.java
67 lines (64 loc) · 2.08 KB
/
Store.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
package hust.soict.dsai.aims.store;
import hust.soict.dsai.aims.disc.DigitalVideoDisc;
public class Store {
public static final int MAX = 100000;
private DigitalVideoDisc[] itemsInStore = new DigitalVideoDisc[MAX];
private int qtyInStore = 0;
public void addDVD(DigitalVideoDisc disc)
{
if (qtyInStore == MAX)
{
System.out.println("The store is out of space");
}
else {
itemsInStore[qtyInStore] = disc;
qtyInStore+=1;
System.out.println("The disc has been added");
}
return;
}
public void removeDVD(DigitalVideoDisc disc)
{
int found = 0;
int index;
if (qtyInStore == 0)
{
System.out.println("No discs in store");
return;
}
for (int i = 0; i < qtyInStore; i++)
{
if (itemsInStore[i] == disc)
{
index = i;
DigitalVideoDisc tmp[] = new DigitalVideoDisc[qtyInStore-1];
for (int j = 0; j < index; j++)
{
tmp[j] = itemsInStore[j];
}
for (int j = index; j < qtyInStore-1; j++)
{
tmp[j] = itemsInStore[j+1];
}
itemsInStore = tmp;
qtyInStore-=1;
found = 1;
System.out.println("The disc has been removed");
break;
}
}
if (found == 0)
System.out.println("The disc is not found");
}
public void printStore()
{
System.out.println("***********************STORE***********************");
System.out.println("In Store Items:");
for (int i = 0; i < qtyInStore; i++)
{
System.out.println(itemsInStore[i].getId() + ". DVD - " + itemsInStore[i].getTitle() + " - "
+ itemsInStore[i].getCategory() + " - " + itemsInStore[i].getDirector() + " - "
+ itemsInStore[i].getLength() + ": " + itemsInStore[i].getCost() + "$");
}
}
}