Add OOP/Java/Assignments/FISAC/Q8.java
This commit is contained in:
parent
01ea7fccc2
commit
35507d524c
57
OOP/Java/Assignments/FISAC/Q8.java
Normal file
57
OOP/Java/Assignments/FISAC/Q8.java
Normal file
@ -0,0 +1,57 @@
|
||||
import java.util.*;
|
||||
|
||||
class Movie {
|
||||
String movieName, seatType;
|
||||
int seatsAvailable;
|
||||
|
||||
Movie(String movieName, String seatType, int seatsAvailable) {
|
||||
this.movieName = movieName;
|
||||
this.seatType = seatType;
|
||||
this.seatsAvailable = seatsAvailable;
|
||||
}
|
||||
}
|
||||
|
||||
class BharathCinemasMultiplex {
|
||||
ArrayList<Movie> movies = new ArrayList<>();
|
||||
ArrayList<String> users = new ArrayList<>();
|
||||
|
||||
void addMovie(Movie movie) {
|
||||
movies.add(movie);
|
||||
}
|
||||
|
||||
void listMovies() {
|
||||
for (Movie m : movies)
|
||||
System.out.println(m.movieName + " (" + m.seatType + ") - Seats: " + m.seatsAvailable);
|
||||
}
|
||||
|
||||
void bookTicket(String userName, String movieName, String seatType, int noOfTickets) {
|
||||
for (Movie m : movies) {
|
||||
if (m.movieName.equals(movieName) && m.seatType.equals(seatType)) {
|
||||
if (m.seatsAvailable >= noOfTickets) {
|
||||
m.seatsAvailable -= noOfTickets;
|
||||
users.add(userName + " - " + movieName + " (" + seatType + ") - Tickets: " + noOfTickets);
|
||||
System.out.println("Booking successful!");
|
||||
} else {
|
||||
System.out.println("Not enough tickets available.");
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
System.out.println("Movie not found.");
|
||||
}
|
||||
|
||||
void listUsers() {
|
||||
for (String user : users)
|
||||
System.out.println(user);
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
BharathCinemasMultiplex bcm = new BharathCinemasMultiplex();
|
||||
bcm.addMovie(new Movie("Movie1", "Regular", 50));
|
||||
bcm.addMovie(new Movie("Movie2", "Premium", 30));
|
||||
bcm.listMovies();
|
||||
bcm.bookTicket("User1", "Movie1", "Regular", 2);
|
||||
bcm.bookTicket("User2", "Movie2", "Premium", 5);
|
||||
bcm.listUsers();
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user