-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathClient.java
66 lines (56 loc) · 2.37 KB
/
Client.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
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package gl.project;
/**
*
* @author gh
*/
public class Client extends Utilisateur {
private final Panier panier;
// Constructor
public Client(int idUtilisateur, String nom, String email, String telephone, String password) {
super(idUtilisateur, nom, email, telephone, password);
this.panier = new Panier(); // Each client has one panier
}
// Methods
public void register(String nom, String email, String telephone, String password) {
this.nom = nom;
this.email = email;
this.telephone = telephone;
this.password = password;
System.out.println("Client registered with details: Name=" + nom + ", Email=" + email + ", Phone=" + telephone);
}
public void login(String identifier, String password) {
if ((identifier.equals(this.email) || identifier.equals(this.telephone)) && password.equals(this.password)) {
System.out.println("Client logged in successfully: " + nom);
} else {
System.out.println("Login failed: Incorrect email/phone or password.");
}
}
public Panier getPanier() {
return panier;
}
public void ajouterAuPanier(Produit produit, int quantite) {
panier.getCartItems().add(produit);
panier.getQuantities().add(quantite);
panier.setTotalPrice(panier.getTotalPrice() + produit.getPrice() * quantite);
System.out.println("Added to cart: " + produit.getName() + " (Quantity: " + quantite + ")");
}
void supprimerDuPanier(Produit produit , int quantite) {
int index = panier.getCartItems().indexOf(produit);
if (index >= 0) {
panier.setTotalPrice(panier.getTotalPrice() - produit.getPrice() * panier.getQuantities().get(index));
panier.getCartItems().remove(index);
panier.getQuantities().remove(index);
System.out.println("Removed from cart: " + produit.getName());
} else {
System.out.println("Product not found in cart.");
}
}
public void sendMessage( String message) {
System.out.println("Message from " + getNom() + ": " + message);
}
}