-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPharmacy.java
More file actions
86 lines (72 loc) · 2.39 KB
/
Copy pathPharmacy.java
File metadata and controls
86 lines (72 loc) · 2.39 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
public class Pharmacy {
// Atributos
private ServiceTree catalog;
private PriorityList clientList;
// Constructor
public Pharmacy() {
catalog = new ServiceTree();
clientList = new PriorityList(100);
}
public PriorityList getClientList() {
return clientList;
}
// Agregar treatment
public Service addTreatment(String name, double price) {
Treatment treatment = new Treatment(generateId(), name, price);
catalog.insert(treatment);
return treatment;
}
// Agregar medicine
public Service addMedicine(String name, double price, String indication, int cuantity) {
Medicine medicine = new Medicine(generateId(), name, price, indication, cuantity);
catalog.insert(medicine);
return medicine;
}
// Buscar service por ID
public Service searchService(int id) {
return catalog.search(id);
}
// Mostrar catalog de treatments
public void showTreatmentCatalog() {
System.out.println("\n---- Treatment Catalog ----");
catalog.inOrder();
}
// Mostrar catalog de medicine
public void printMedicineCatalog() {
System.out.println("\n---- Medicine Catalog ----");
catalog.inOrder();
}
// Registrar cliente y agregarlo a la cola
public Client registerClient(String name, String cedula, boolean preferential, java.util.List<int[]> solicitedServices) {
Client client = new Client(name, cedula, preferential);
CartList cart = new CartList();
for (int[] par : solicitedServices) {
int id = par[0];
int cuantity = par[1];
Service s = searchService(id);
if (s != null) {
cart.insert(s, cuantity);
}
}
client.setCart(cart);
clientList.enroll(client);
return client;
}
// Atender al siguiente client
public void attendNextClient() {
Client c = clientList.attendNext();
if (c == null) {
System.out.println("There is no client in the list.");
return;
}
System.out.println("\nAttending: " + c.getFullName());
if (c.getCart() != null) {
c.getCart().printCart();
}
System.out.println("Thanks for your purchase.\n");
}
private static int countId = 1;
private int generateId() {
return countId++;
}
}