Created
August 19, 2015 09:20
-
-
Save yaswanthrajyadiki/026212f6f6736dcfaf09 to your computer and use it in GitHub Desktop.
BookYourShow application can be extended by anyone
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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