-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCustomerService.java
More file actions
65 lines (58 loc) · 2.27 KB
/
CustomerService.java
File metadata and controls
65 lines (58 loc) · 2.27 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
package services;
import models.*;
import java.util.*;
import APP.Main;
public class CustomerService {
public static List<Booking> bookings = Main.bookings;
public static List<Show> shows = Main.shows;
public static List<Movie> movies = Main.movies;
// ✅ Book tickets
public static void bookTicket(User user, int showId, int seats) {
Show show = null;
for (Show s : shows) {
if (s.id == showId) {
show = s;
break;
}
}
if (show == null) {
System.out.println("Show ID not found!");
return;
}
if (seats <= 0 || seats > show.availableSeats) {
System.out.println("Invalid number of seats. Available: " + show.availableSeats);
return;
}
show.availableSeats -= seats;
double pricePerSeat = 10.0; // example
Booking booking = new Booking(Main.bookingIdCounter++, user.id, showId, seats, seats * pricePerSeat, java.time.LocalDate.now().toString());
bookings.add(booking);
System.out.println("Booking successful! Total price: $" + (seats * pricePerSeat));
}
// ✅ VIEW BOOKING HISTORY
public static void viewBookingHistory(User user) {
boolean found = false;
System.out.println("\n--- Booking History ---");
for (Booking b : bookings) {
if (b.userId == user.id) {
Show s = null;
Movie m = null;
for (Show sh : shows) {
if (sh.id == b.showId) s = sh;
}
if (s != null) {
for (Movie mv : movies) {
if (mv.id == s.movieId) m = mv;
}
}
System.out.println("Booking ID: " + b.id +
", Movie: " + (m != null ? m.title : "Unknown") +
", Date: " + (s != null ? s.date : "Unknown") +
", Seats: " + b.seats +
", Total: $" + b.totalPrice);
found = true;
}
}
if (!found) System.out.println("No bookings found.");
}
}