update multiple classes

This commit is contained in:
2026-06-27 21:12:42 +03:30
parent 3573dc1f58
commit dd6e81bcd5
13 changed files with 224 additions and 144 deletions
@@ -6,11 +6,11 @@ import java.sql.SQLException;
public class DatabaseConnection {
private static final String URL = "jdbc:postgresql://localhost:5432/restaurant_db"; // DB Server
private static final String URL = "jdbc:postgresql://localhost:5432/postgres"; // DB Server
private static final String USER = "postgres"; // Your Username
private static final String PASSWORD = "password"; // Your Password
private static final String PASSWORD = "1234"; // Your Password
private DatabaseConnection() {
+3 -4
View File
@@ -17,10 +17,9 @@ public class MenuService {
for ( MenuItem menuItem : items) {
System.out.println(menuItem.getId() + ". " + menuItem.getName() +
" " + menuItem.getPrice() + " | " + menuItem.getCategory());
System.out.println(menuItem.getDescription());
" " + menuItem.getPrice() + "$ \n" +
menuItem.getCategory() + " | " + menuItem.getDescription());
System.out.println();
}
}
}
+3 -2
View File
@@ -85,7 +85,7 @@ public class OrderService {
double totalPrice = 0;
System.out.println("\n===== RECEIPT =====");
System.out.println("\n============ RECEIPT ============");
for (OrderDetail detail : details) {
@@ -97,7 +97,8 @@ public class OrderService {
System.out.println( item.getName() + " | Quantity: " + detail.getQuantity() +
" | Price: " + detail.getPrice() + "$ | Total: " + subtotal + "$");
}
System.out.println("\nFinal Total: $" + totalPrice);
System.out.println("==============================");
System.out.println("Final Total: $" + totalPrice);
}
public void showOrderHistory(int userId) {
+88 -4
View File
@@ -1,12 +1,21 @@
package dev.ui;
import dev.model.User;
import dev.service.AuthService;
import dev.service.MenuService;
import dev.service.OrderService;
import java.util.Scanner;
public class ConsoleMenu {
private final Scanner scanner =
private final Scanner in =
new Scanner(System.in);
private final AuthService authService = new AuthService();
private final MenuService menuService = new MenuService();
private final OrderService orderService = new OrderService();
public void start() {
while (true) {
@@ -17,16 +26,17 @@ public class ConsoleMenu {
System.out.println("2. Register");
System.out.println("3. Exit");
int choice = scanner.nextInt();
int choice = in.nextInt();
in.nextLine();
switch (choice) {
case 1:
// TODO
login();
break;
case 2:
// TODO
register();
break;
case 3:
@@ -41,4 +51,78 @@ public class ConsoleMenu {
}
public void login() {
System.out.println("Enter your username: ");
String username = in.nextLine();
System.out.println("Enter your password: ");
String password = in.nextLine();
User user = authService.login(username, password);
if(user != null) {
System.out.println("Welcome back, " + username);
showOptions(user);
}
else System.out.println("Wrong username or password.");
}
public void register() {
System.out.println("Enter your username: ");
String username = in.nextLine();
System.out.println("Enter password: ");
String password = in.nextLine();
System.out.println("Enter your email: ");
String email = in.nextLine();
if (authService.register(username, password, email)) {
System.out.println("Welcome!");
}
else System.out.println("Registration failed");
}
public void showOptions(User user) {
System.out.println("""
=======================================
\uD83C\uDF7D MAIN MENU \uD83C\uDF7D
=======================================""");
while (true) {
System.out.println("1. View Menu\n" +
"2. Place a New Order\n" +
"3. View Order History \n" +
"4. Logout");
int choice = in.nextInt();
switch (choice) {
case 1:
menuService.showMenu();
break;
case 2:
orderService.placeOrder(user.getId());
break;
case 3:
orderService.showOrderHistory(user.getId());
break;
case 4:
return;
}
}
}
}