Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and beginning April 20th, 2021 (Eastern Time) the Yahoo Answers website will be in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.

Question about Java programming?

My assignment was to create a program of a ticket booking system using java.

The program should print out a summary of the tickets booked. If the user booked more than 1 tickets, it is correct to use "counter"?

4 Answers

Relevance
  • 1 decade ago
    Favorite Answer

    import javax.swing.JOptionPane;

    public class TicketSystem{

    private static final int MAX_TICKETS = 50;

    private int MAX_MOVIES = 5;

    private String MOVIE[];

    private int SOLD[];

    public TicketSystem(){

    MOVIE = new String[MAX_MOVIES];

    SOLD = new int[MAX_MOVIES];

    }

    public TicketSystem(int max_movies){

    setMAX_MOVIES(max_movies);

    MOVIE = new String[MAX_MOVIES];

    SOLD = new int[MAX_MOVIES];

    }

    public void setMAX_MOVIES(int max_movie){

    MAX_MOVIES = (max_movie>=0)?max_movie:MAX_MOVIES;

    }

    public int getMAX_MOVIES(){

    return MAX_MOVIES;

    }

    public int getMAX_TICKETS(){

    return MAX_TICKETS;

    }

    public boolean setMovie(String[] movie){

    if(movie.length>this.MAX_MOVIES){

    JOptionPane.showMessageDialog( null, "Array Length Exceeding No. of Movies!!!",

    "ERROR" ,JOptionPane.ERROR_MESSAGE);

    return false;

    }

    else if(movie.length<this.MAX_MOVIES){

    JOptionPane.showMessageDialog( null, "Array Length Deceed No. of Movies!!!",

    "ERROR", JOptionPane.ERROR_MESSAGE);

    return false;

    }

    else{

    for(int index=0; index<MAX_MOVIES; index++)

    MOVIE[index] = movie[index];

    }

    return true;

    }

    public boolean getMovie(String[] movie){

    if(movie.length>this.MAX_MOVIES){

    JOptionPane.showMessageDialog( null, "Array Length Exceeding No. of Movies!!!",

    "ERROR", JOptionPane.ERROR_MESSAGE);

    return false;

    }

    else if(movie.length<this.MAX_MOVIES){

    JOptionPane.showMessageDialog( null, "Array Length Deceed No. of Movies!!!",

    "ERROR", JOptionPane.ERROR_MESSAGE);

    return false;

    }

    else{

    for(int index=0; index<MAX_MOVIES; index++)

    movie[index] = MOVIE[index];

    }

    return true;

    }

    private void setSold(int movie, int tickets){

    SOLD[movie]+=tickets;

    }

    private int getSold(int movie){

    return SOLD[movie];

    }

    public boolean reserve(int movie, int tickets){

    // validate value of movie & tickets

    // if valide:

    // update SOLD[moive]

    // return true

    // else:

    // show error message

    // return flase

    if( movie<0 || movie>=MAX_MOVIES ){

    JOptionPane.showMessageDialog( null, "Movie is not Available",

    "ERROR", JOptionPane.ERROR_MESSAGE);

    return false;

    }

    else if( tickets<=0 ){

    JOptionPane.showMessageDialog( null, "No. of Tickets is not Valid",

    "ERROR", JOptionPane.ERROR_MESSAGE);

    return false;

    }

    else{

    int remained = MAX_TICKETS-getSold(movie);

    if(tickets>MAX_TICKETS || tickets>remained){

    JOptionPane.showMessageDialog( null, "Available tickets can't cover your want\n"

    + "We still have <" + remained + "> seat available",

    "WARNING", JOptionPane.WARNING_MESSAGE);

    return false;

    }

    else{

    JOptionPane.showMessageDialog( null, tickets + " tickets reserved for "

    + MOVIE[movie],

    "Reserved OK", JOptionPane.INFORMATION_MESSAGE);

    setSold(movie, tickets);

    }

    }

    return true;

    }

    public boolean dereserve(int movie, int tickets){

    // validate value of movie & tickets

    // if valide:

    // update SOLD[moive]

    // return true

    // else:

    // show error message

    // return flase

    return true;

    }

    }

  • 1 decade ago

    I'm not quite sure what you're asking. Are you trying to keep track of the total number of tickets booked by a customer?

    If so, you can use a variable called "counter" if you want. You may want to name it something a little more intuitive like "numOfTickets" or "ticketQuantity" or something.

    Sorry, I'm not so sure I'm getting what you're after.

  • 5 years ago

    Why roll your own when there is in all likelihood a calendar widget you can reuse? By the way, the Java API itself provides many useful classes and interfaces: Date, Calendar, GregorianCalendar, DateFormat, and SimpleDateFormat.

  • 1 decade ago

    MJordan1, you forgot to include the main() method.

Still have questions? Get your answers by asking now.