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: how do i fix the error?

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

    Exclamation how do i fix the error?

    This is my code for a school assignment, and I don't understand where I am making a mistake. The code has some extra lines for things that have not yet been implemented but They shouldn't cause any problems or errors. I am really stuck, and any ideas as to what i am doing wrong are very much appreciated. Even if I have to rewrite a majority of what I have already written I am ok with trying out any suggestions.

    (USEING ECLIPSE TO WRITE THE CODE)

    Menu class:

    import java.util.Scanner;

    public class Menu {

    static double bal = 0;

    public double Bal() {
    //bal = bal + ticketCost;
    return bal;
    }
    /////////////////////////////////////////////////////////////////////////////////
    public static void main(String[] args) {
    Plane callPlane = new Plane();
    Ticket callTicket = new Ticket();

    Scanner input = new Scanner(System.in);
    Scanner input2 = new Scanner(System.in);
    Scanner input3 = new Scanner(System.in);
    //Scanner input4 = new Scanner(System.in);

    System.out.println("Air Canada\n");
    //Menu tabs
    System.out.println("Please chose which option you would like.\n");
    System.out.println("Purchase a Ticket");
    System.out.println("Ticket Pricing");
    System.out.println("Availability");
    System.out.println("Checkout");
    System.out.println("Get a refund\n");
    ///////////
    String menuChoice = input.nextLine();
    menuChoice = menuChoice.toLowerCase();

    if (menuChoice.equals("purchase a ticket")) {
    input.close();
    System.out.println("Would you like to purchase a Business Class seat or an Economy Class seat?");
    String choice2 = input2.nextLine();
    choice2 = choice2.toLowerCase();

    int x = 0;

    if (choice2.equals("business class")) {
    input2.close();
    System.out.println("How many seats would you like to purchase?");
    int choice3 = input3.nextInt();
    input3.close();
    do {
    callPlane.businessClass();
    x += 1;
    }while(x != choice3);
    }else {
    System.out.println("How many seats would you like to purchase?");
    int choice3 = input3.nextInt();
    input3.close();
    do {
    callPlane.economyClass();
    x += 1;
    }while(x != choice3);
    }
    ////////////
    }else if (menuChoice.equals("ticket pricing")) {
    input.close();
    System.out.println("Would you like to purchase a Business Class seat or an Economy Class seat?");
    String choice2 = input2.nextLine();
    choice2 = choice2.toLowerCase();
    if (choice2.equals("business class")) {
    input2.close();
    callTicket.busPrice();
    }else {
    callTicket.ecoPrice();
    }
    }else if (menuChoice.equals("availability")) {
    input.close();

    }else if (menuChoice.equals("checkout")) {
    input.close();

    }else if (menuChoice.equals("get a refund")) {
    input.close();
    if (bal <= 0) {
    System.out.println("You have no purchased tickets to refund");
    }
    }
    }
    /////////////////////////////////////////////////////////////////////////////////
    }



    Plane Class:

    import java.util.ArrayList;
    import java.util.Scanner;
    /////////////////////////////////////////////////////////////////////////////////
    public class Plane {
    Ticket callTicket = new Ticket();
    /////////////////////////////////////////////////////////////////////////////////
    public void businessClass() {

    Scanner input = new Scanner(System.in);
    boolean seat[][] = new boolean[2][3];

    for (int row = 0; row < seat.length; row++) {

    for (int col = 0; col < seat[row].length; col++) {

    if (!seat[0][col]) {
    seat[0][col] = true;
    System.out.println("You have place number 0" + col + " in the Business Class");
    break;
    }
    }
    if (seat[0][2]) {
    if (seat[1][2]) {
    System.out.println("The plane is full, welcome again");
    System.exit(0);

    } else {

    System.out.println("Business Class is full, do you want to book in the Economy Class? (yes or no)");
    String choice = input.nextLine();
    choice = choice.toLowerCase();
    if (choice.equals("yes")) {
    economyClass();
    } else {
    System.out.println("Thank you and welcome again");
    System.exit(0);

    }
    }
    }
    }
    }
    /////////////////////////////////////////////////////////////////////////////////
    public void economyClass() {

    Scanner input = new Scanner(System.in);
    boolean seat[][] = new boolean[2][3];

    for (int row = 0; row < seat.length; row++) {

    for (int col = 0; col < seat[row].length; col++) {

    if (!seat[0][col]) {
    seat[0][col] = true;
    System.out.println("You have place number 0" + col + " in the Economy Class");
    break;
    }
    }
    if (seat[0][2]) {
    if (seat[1][2]) {
    System.out.println("The plane is full, welcome again");
    System.exit(0);

    } else {

    System.out.println("Economy Class is full, do you want to book in the Business Class? (yes or no)");
    String choice = input.nextLine();
    choice = choice.toLowerCase();
    if (choice.equals("yes")) {
    businessClass();
    } else {
    System.out.println("Thank you and welcome again");
    System.exit(0);

    }
    }
    }
    }
    }
    /////////////////////////////////////////////////////////////////////////////////
    }


    Ticket class:

    import java.util.Scanner;

    public class Ticket {
    Plane callPlane = new Plane();
    /////////////////////////////////////////////////////////////////////////////////
    public void busPrice() {
    Scanner input = new Scanner(System.in);
    System.out.println("Enter the number of Business Class seats you would like to purchase");
    int numSeats = input.nextInt();
    double price = (numSeats * 200) * 1.13;
    System.out.println("The price of " + numSeats + "Business Class seats is: " + price);
    }
    /////////////////////////////////////////////////////////////////////////////////
    public void ecoPrice() {
    Scanner input = new Scanner(System.in);
    System.out.println("Enter the number of Economy Class seats you would like to purchase");
    int numSeats = input.nextInt();
    double price = (numSeats * 115) * 1.13;
    System.out.println("The price of " + numSeats + "Economy Class seats is: " + price);
    }
    /////////////////////////////////////////////////////////////////////////////////
    }


    error message:

    Screen Shot 2019-01-15 at 7.11.30 PM.jpg

  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: how do i fix the error?

    Please copy the text of the error messages and paste it here. The image is hard to read and it is not possible to copy text from an image to include in a response.

    Please edit your post and wrap your code with code tags:

    [code]
    **YOUR CODE GOES HERE**
    [/code]

    to get highlighting and preserve formatting.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Member
    Join Date
    Sep 2018
    Location
    Virginia
    Posts
    284
    My Mood
    Cool
    Thanks
    0
    Thanked 38 Times in 36 Posts

    Default Re: how do i fix the error?

    But I did notice the first few lines of your code. Do not declare more than one Scanner instance for taking input from the console. All you need is one for any input required. And when you are done, DO NOT close it.

    Regards,
    Jim

Similar Threads

  1. Help me to fix the error in my programming.
    By devarajand in forum What's Wrong With My Code?
    Replies: 2
    Last Post: February 1st, 2018, 08:26 AM
  2. [SOLVED] A very peculiar error I just cant fix
    By Cornix in forum AWT / Java Swing
    Replies: 0
    Last Post: August 28th, 2014, 01:42 PM
  3. [SOLVED] Im new to Java and have an error i cannot fix please help
    By blockmaster2001 in forum What's Wrong With My Code?
    Replies: 4
    Last Post: July 6th, 2014, 06:39 PM
  4. I keep getting an error message but I don't know how to fix this!
    By mpagudelo in forum What's Wrong With My Code?
    Replies: 2
    Last Post: September 12th, 2013, 01:56 AM
  5. Cant fix this error... Help!
    By Hypermegazord in forum What's Wrong With My Code?
    Replies: 1
    Last Post: November 1st, 2012, 01:06 PM

Tags for this Thread