Code Lab
Code Lab
*;
import java.util.*;
class Database {
// Class Product
class Product {
int id;
String name;
double price;
int stockQuantity;
this.id = id;
this.name = name;
this.price = price;
this.stockQuantity = stockQuantity;
}
public void displayInfo() {
System.out.println(id + ". " + name + " - " + price + " VND (Stock: " + stockQuantity + ")");
// Class Customer
class Customer {
int customerId;
String password;
String name;
String role;
String email;
public Customer(int customerId, String name, String password, String role, String email) {
this.customerId = customerId;
this.name = name;
this.password = password;
this.role = role;
this.email = email;
// Class EcommerceSystem
class EcommerceSystem {
int id = rs.getInt("id");
p.displayInfo();
} catch (SQLException e) {
e.printStackTrace();
stmt.setString(1, name);
ResultSet rs = stmt.executeQuery();
if (rs.next()) {
} catch (SQLException e) {
e.printStackTrace();
return null;
}
public Customer login(String email, String password) {
stmt.setString(1, email);
stmt.setString(2, password);
ResultSet rs = stmt.executeQuery();
if (rs.next()) {
} catch (SQLException e) {
e.printStackTrace();
return null;
// Main Class
if (loggedInCustomer == null) {
return;
while (true) {
System.out.println("3. Exit");
scanner.nextLine();
switch (choice) {
case 1:
system.listProducts();
break;
case 2:
if (product != null) {
product.displayInfo();
} else {
break;
case 3:
return;