Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: Coach Booking System - Add Booking Run-Time Error

  1. #1
    Junior Member
    Join Date
    Jan 2018
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Coach Booking System - Add Booking Run-Time Error

    Hi, I'm currently developing a booking system for an assignment at university but I keep getting an exception error, when i attempt to add a new booking in the program and cannot for the life of me figure out whats causing it any help would be appreciated. Source Code and screenshot included below:

    Main Class
    package quantockcoaches;
    import java.util.*;
    /**
     *
     * @author Jordan Southey
     */
    public class QuantockCoaches 
    {
        public static void main(String[] args){
            int MenuOption, TripID, ChoosenTripID, NewNoOfAdults, NewNoOfChildren;
            String NewFirstName, NewSurname, NewTelNumber, NewAddress1, NewAddress2, 
                    NewCity, NewCounty, NewPostcode;
     
            ArrayList <TripCatalogue> Trips = new ArrayList();
     
            Trips.add(new TripCatalogue("QC01", "Bridgwater to Wells", 25.00));
            Trips.add(new TripCatalogue("QC02", "Bridgwater to Bristol", 25.00));
            Trips.add(new TripCatalogue("QC03", "Bridgwater to London", 25.00));
            Trips.add(new TripCatalogue("QC04", "Bridgwater to Manchester", 25.00));
            Trips.add(new TripCatalogue("QC05", "Bridgwater to Leeds", 25.00));
            Trips.add(new TripCatalogue("QC06", "Bridgwater to Liverpool", 25.00));
            Trips.add(new TripCatalogue("QC07", "Bridgwater to Edinburgh", 25.00));
            Trips.add(new TripCatalogue("QC08", "Bridgwater to Glasow", 25.00));
            Trips.add(new TripCatalogue("QC09", "Bridgwater to Heathrow", 25.00));
            Trips.add(new TripCatalogue("QC010", "Bridgwater to Plymouth", 25.00));
            Trips.add(new TripCatalogue("QC011", "Bridgwater to Landsend", 25.00));
            Trips.add(new TripCatalogue("QC012", "Bridgwater to Padstow", 25.00));
     
            Scanner Scanner;
            Scanner InputScanner;
            Scanner BillingAndTicketingScanner;
            Scanner ViewScanner;
            Scanner TripCatalogueScanner;
     
            for(;;){ 
                do{
                    System.out.println("Quantock Coaches Booking System V1.0");
                    System.out.println("What type of operation do you wish to perform?");
                    System.out.println("1: Check Coach Seats.");
                    System.out.println("2: Create New Booking.");
                    System.out.println("3: View / Delete Bookings.");
                    System.out.println("4: Exit Program.");
     
                    Scanner = new Scanner(System.in);
                    MenuOption = Scanner.nextInt();
                }while (MenuOption < 1 || MenuOption > 4);
     
                if (MenuOption == 0)
                    break;
     
                switch (MenuOption){
                    case 1: 
                    {
                        TripCatalogueScanner = new Scanner(System.in);
                        System.out.println("Please select the trip by entering the ID numbers E.G. 12");
                        for (int i = 0; i < Trips.size();i++)
                          System.out.println(Trips.get(i).toString());
                        ChoosenTripID = TripCatalogueScanner.nextInt();
     
                        System.out.println("Selected Trip: " + ChoosenTripID);
                        System.out.println("Total seating space is 32");
                        System.out.println("Free seats remaining: " + Trips.get(ChoosenTripID-1).AvalibleSeats() + "\n");
     
                        break;
                    }
     
                    case 2:
                    {
                        InputScanner = new Scanner(System.in);
                        System.out.println("Please select the trip by entering the ID numbers E.G. 12");
                        for (int i = 0; i < Trips.size();i++)
                          System.out.println(Trips.get(i).toString());
                        ChoosenTripID = InputScanner.nextInt();
     
                        System.out.println("Please enter the customer's first name: ");
                        InputScanner.nextLine();
                        NewFirstName = InputScanner.nextLine();
                        System.out.println("Please enter the customer's surname: ");
                        NewSurname = InputScanner.nextLine();
                        System.out.println("Please enter the customer's telephone number: ");
                        NewTelNumber = InputScanner.nextLine();
                        System.out.println("Please enter the customer's first address line: ");
                        NewAddress1 = InputScanner.nextLine();
                        System.out.println("Please enter the customer's second address line: ");
                        NewAddress2 = InputScanner.nextLine();
                        System.out.println("Please enter the customer's town or city: ");
                        NewCity = InputScanner.nextLine();
                        System.out.println("Please enter the customer's county: ");
                        NewCounty = InputScanner.nextLine();
                        System.out.println("Please enter the customer's postcode: ");
                        NewPostcode = InputScanner.nextLine();
                        System.out.println("Please enter the number of adult party members: ");
                        NewNoOfAdults = InputScanner.nextInt();
                        System.out.println("Please enter the number of child party members: ");
                        NewNoOfChildren = InputScanner.nextInt();
                        System.out.println("Thank you for booking with Quantock Coaches.");
     
                        Trips.get(ChoosenTripID-1).AddBooking(NewFirstName, NewSurname, NewTelNumber, NewAddress1, 
                                NewAddress2, NewCity, NewCounty, NewPostcode, NewNoOfAdults, NewNoOfChildren);
                        break;
                    }
     
                    case 3:
                    {
                        int CustomerID = 0, ChoosenBooking = 0;
     
                        ViewScanner = new Scanner(System.in);
                        System.out.println("Please select the trip by entering the ID numbers E.G. 12");
                        for (int i = 0; i < Trips.size();i++)
                          System.out.println(Trips.get(i).toString());
                        ChoosenTripID = ViewScanner.nextInt();
     
                        System.out.println("The choosen trip is: " + ChoosenTripID);
                        System.out.println(Trips.get(ChoosenTripID-1).ViewBooking());
                        System.out.println("Please select the ID number of the record you wish to remove.");
                        CustomerID = ViewScanner.nextInt();
                        System.out.println("Are you sure this is the booking you wish to delete? "
                                + "Enter 1 for yes or 2 for no.");
                        ChoosenBooking = ViewScanner.nextInt();
     
                        switch (ChoosenBooking){
                            case 1:
                            {
                                Trips = null;
                            }
                            case 2:
                            {
                                System.out.println("Returning to main menu... Please wait.");
                            }
                            break;
                        }  
                    }
     
                    case 4:
                    {
                        System.exit(0);
                    }
     
                }
            }             
        }
     
    }

    Billing and Ticketing Class
    package quantockcoaches;
     
    /**
     *
     * @author Jordan Southey
     */
    public class BillingAndTicketing
    {
            String TripID, TripDes, FirstName, Surname, TelNumber;
        int NoOfAdults, NoOfChildren;
        double TotalFare;
     
        public BillingAndTicketing(String TripID, String TripDes, String FirstName, String Surname, 
               String TelNumber, int NoOfAdults, int NoOfChildren, double TotalFare)
        {
            this.TripID = TripID;
            this.TripDes = TripDes;
            this.FirstName = FirstName;
            this.Surname = Surname;
            this.TelNumber = TelNumber;
            this.NoOfAdults = NoOfAdults;
            this.NoOfChildren = NoOfChildren;
            this.TotalFare = TotalFare;
        }
     
        BillingAndTicketing(String FirstName, String Surname, String TelNumber, String Address1, String Address2, String City, String County, String Postcode, int NoOfAdults, int NoOfChildren) {
            throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
        }
     
        @Override
     
        public String toString()
        {
            return "Trip ID: " + TripID + " TripDes" + TripDes + "/n" + "FirstName: " + FirstName
                    + " Surname: " + Surname + " Telephone No: " + TelNumber + "/n" + "Adults: "
                    + NoOfAdults + " Children: " + NoOfChildren + "/n" + "Total Fare: " + TotalFare + "\n";
        }
    }

    Customer Class
    package quantockcoaches;
     
    /**
     *
     * @author Jordan Southey
     */
    public class Customer 
    {
        String FirstName, Surname, TelNumber, Address1, Address2, City, County, Postcode;
        int NoOfAdults, NoOfChildren;   
     
        @Override
     
        public String toString()
        {
            return FirstName + "\n" + Surname + "\n" + TelNumber + "\n" + Address1 + "\n" + Address2
                + "\n" + City + "\n" + County + "\n" + Postcode + "\n" + Integer.toString(NoOfAdults) +
                    Integer.toString(NoOfChildren) + "\n";
        }
    }

    TripCatalogue Class
    package quantockcoaches;
    import java.util.ArrayList;
    /**
     *
     * @author Jordan Southey
     */
    public class TripCatalogue 
    {
      ArrayList <BillingAndTicketing> Coach = new ArrayList();
     
      String TripID, TripDes;
      int NoOfSeats = 32, AvalibleSeats = 32;
      double TripFare;
     
      public TripCatalogue (String ID, String Des, double TFare)
      {
          TripID = ID;
          TripDes = Des;
          TripFare = TFare;
     
      }
     
      public void AddBooking(String FirstName, String Surname, String TelNumber, String Address1,
              String Address2, String City, String County, String Postcode,int NoOfAdults, int NoOfChildren)
      {
          Coach.add(new BillingAndTicketing(FirstName, Surname, TelNumber, Address1, Address2, City, County, Postcode, NoOfAdults, NoOfChildren));
          AvalibleSeats -= (NoOfChildren + NoOfAdults);
      }
     
      public String ViewBooking()
      {
          String value = "";
          for(int i = 0; i < Coach.size(); i++)
              value += Coach.get(i).toString();
          return value;
      }
     
      public int AvalibleSeats()
      {
              return AvalibleSeats;
      }
     
      @Override
     
      public String toString()
      {
          return "TripID: " + TripID + " Trip Destination: " + TripDes + "\n" + " Number of Seats: " + NoOfSeats 
                  + " Free Seats: " + AvalibleSeats + " Total Fare: " + TripFare + "\n";
      }
    }
    Error Message
    Untitled.jpg
    Exception in thread "main" java.lang.UnsupportedOperationException: Not supported yet.
    at quantockcoaches.BillingAndTicketing.<init>(Billing AndTicketing.java:27)
    at quantockcoaches.TripCatalogue.AddBooking(TripCatal ogue.java:26)
    at quantockcoaches.QuantockCoaches.main(QuantockCoach es.java:98)
    C:\Users\Jorda\AppData\Local\NetBeans\Cache\8.2\ex ecutor-snippets\run.xml:53: Java returned: 1
    BUILD FAILED (total time: 39 seconds)

  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Coach Booking System - Add Booking Run-Time Error

    Exception in thread "main" java.lang.UnsupportedOperationException: Not supported yet.
    at quantockcoaches.BillingAndTicketing.<init>(Billing AndTicketing.java:27)
    That exception is explicitly thrown by the code at line 27 in BillingAndTicketing.
    If you don't want that exception to be thrown then
    either do not call that constructor
    or remove the throw statement and replace it with some useful code.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Jan 2018
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Coach Booking System - Add Booking Run-Time Error

    Quote Originally Posted by Norm View Post
    That exception is explicitly thrown by the code at line 27 in BillingAndTicketing.
    If you don't want that exception to be thrown then
    either do not call that constructor
    or remove the throw statement and replace it with some useful code.
    Thank you very much for your response, I swapped the code snippet from the first constructor into the one with the throw statement and it worked perfectly with a bit of tweeking for appearances

Similar Threads

  1. Replies: 2
    Last Post: September 24th, 2014, 03:28 PM
  2. Need help with Hotel booking math.
    By JoelleIsAce in forum What's Wrong With My Code?
    Replies: 4
    Last Post: December 12th, 2013, 05:46 PM
  3. Design Pattern for Online booking
    By tcstcs in forum Java Theory & Questions
    Replies: 0
    Last Post: January 14th, 2013, 05:21 AM
  4. Hotel Booking form ??
    By dynamix24 in forum JavaServer Pages: JSP & JSTL
    Replies: 1
    Last Post: March 22nd, 2012, 09:35 AM