Skip to content

Instantly share code, notes, and snippets.

@yaswanthrajyadiki
Created August 19, 2015 09:20
Show Gist options
  • Save yaswanthrajyadiki/026212f6f6736dcfaf09 to your computer and use it in GitHub Desktop.
Save yaswanthrajyadiki/026212f6f6736dcfaf09 to your computer and use it in GitHub Desktop.
BookYourShow application can be extended by anyone
import java.util.ArrayList;
import java.util.ListIterator;
class BookYourShow {
private ArrayList<Show> show;
private String userName;
private String userMobileNumber;
private String movieName;
private String movieShowDate;
private String movieShowTime;
private int numberOfSeats;
BookYourShow() {
show = new ArrayList<Show>();
}
public void addAShow(Show s) {
show.add(s);
}
public void removeAShow(String movieName) {
ListIterator<Show> iterator = show.listIterator();
while(iterator.hasNext()) {
Show ss = iterator.next();
if (movieName==ss.getMovieName()) {
show.remove(ss);
break;
}
}
}
public void getAShow(String movieName) {
ListIterator<Show> iterator2 = show.listIterator();
while(iterator2.hasNext()) {
Show ss2 = iterator2.next();
if (movieName==ss2.getMovieName()) {
System.out.println(ss2);
}
}
}
public void bookAShow(Patron patron,
String movieName, String date,
String time, int noOfSeats) {
ListIterator<Show> iterator1 = show.listIterator();
while(iterator1.hasNext()) {
Show ss1 = iterator1.next();
if (movieName.equals(ss1.getMovieName()) && date.equals(ss1.getMovieShowDate())
&& time.equals(ss1.getMovieShowTime()) && ss1.getNumberOfSeats() >= noOfSeats) {
this.userName = patron.getUserName();
this.userMobileNumber = patron.getUserMobileNumber();
this.movieName = movieName;
this.movieShowDate = date;
this.movieShowTime = time;
this.numberOfSeats = noOfSeats;
ss1.updateSeats(-noOfSeats);
}
}
}
public String printTicket() {
String printTickets = "Name: " + this.userName + "\n";
printTickets = printTickets + "Mobile number: " + this.userMobileNumber + "\n";
printTickets = printTickets + "Movie name: " + this.movieName + "\n";
printTickets = printTickets + "Date: " +this.movieShowDate + "\n";
printTickets = printTickets + "Time: " +this.movieShowTime + "\n";
printTickets = printTickets + "Number of seats: " +this.numberOfSeats;
return printTickets;
}
}
class Menu {
public static void main(String[] args) {
Show show[] = new Show[10];
show[0] = new Show("Srimanthudu",
"17-08-2015", "11:00 AM", 50);
show[1] = new Show("MI5",
"17-08-2015", "02:30 PM", 50);
show[2] = new Show("Upendra2",
"18-08-2015", "11:00 AM", 50);
show[3] = new Show("Srimanthudu",
"19-08-2015", "11:00 AM", 50);
BookYourShow bys = new BookYourShow();
bys.addAShow(show[0]);
bys.addAShow(show[1]);
bys.addAShow(show[2]);
bys.addAShow(show[3]);
bys.removeAShow("Upendra2");
bys.getAShow("Srimanthudu");
Patron p = new Patron("Raj", "9493395040");
bys.bookAShow(p, "Srimanthudu", "17-08-2015", "11:00 AM", 6);
System.out.println(bys.printTicket());
}
}
class Patron {
private String userName;
private String mobileNumber;
Patron(String userName,
String mobileNumber) {
this.userName = userName;
this.mobileNumber = mobileNumber;
}
public String toString() {
String s = userName + "\n";
s = s + mobileNumber;
return s;
}
public String getUserName() {
return this.userName;
}
public String getUserMobileNumber() {
return this.mobileNumber;
}
}
class Show {
String nameOfMovie;
String movieShowDate;
String movieShowTime;
int seatNumber;
Show(String nameOfMovie,
String movieShowDate,
String movieShowTime,
int seatNumber) {
this.nameOfMovie = nameOfMovie;
this.movieShowDate = movieShowDate;
this.movieShowTime = movieShowTime;
this.seatNumber = seatNumber;
}
public String toString() {
String s = nameOfMovie + "\n";
s = s + movieShowDate + "\n";
s = s + movieShowTime + "\n";
s = s + seatNumber;
return s;
}
public String getMovieName() {
return this.nameOfMovie;
}
public String getMovieShowDate() {
return this.movieShowDate;
}
public String getMovieShowTime() {
return this.movieShowTime;
}
public int getNumberOfSeats() {
return this.seatNumber;
}
public void updateSeats(int noOfSeats) {
seatNumber = seatNumber + noOfSeats;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment