-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathShow.java
64 lines (59 loc) · 1.85 KB
/
Show.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
import java.util.Date;
public class Show {
private static int idCounter=0;
private int id;
private Date showTime;
private Movie movie;
private Theatre theater;
private int availableSeats;
public Show(Date showTime, Movie movie, Theatre theater) {
idCounter += 1;
this.id = idCounter;
this.showTime = showTime;
this.movie = movie;
this.theater = theater;
this.availableSeats = theater.getCapacity();
theater.getShows().add(this);
}
public Movie getMovie() {
return movie;
}
public void setTheater(Theatre theater) {
this.theater = theater;
}
public void setAvailableSeats(int availableSeats) {
this.availableSeats = availableSeats;
}
public int getAvailableSeats() {
return availableSeats;
}
public void updateShow(){
}
public synchronized Ticket bookTicket(RegisteredUser user, int seats){
if(availableSeats >= seats && seats >0){
Ticket ticket = new Ticket();
availableSeats -= seats;
ticket.setOwner(user.getName());
ticket.setBookedShow(this);
ticket.setBookingTime(new Date());
ticket.setNumberOfSeats(seats);
System.out.println("Successfully booked");
user.bookingHistory.add(ticket);
return ticket;
}
else{
System.out.println("Seats not Available");
return null;
}
}
@Override
public String toString() {
return "Show{" +
"id=" + id +
", showTime=" + showTime +
", movie=" + movie.getName() +
", theater=" + theater.getName() +
", availableSeats=" + availableSeats +
'}';
}
}