Question

In: Computer Science

Im in a java class and having trouble with assigning the seat to a specific number...

Im in a java class and having trouble with assigning the seat to a specific number from the array.. Below are the instructions I was given and then the code that I have already.  

ITSE 2321 – OBJECT-ORIENTED PROGRAMMING JAVA Program 8 – Arrays and ArrayList

A small airline has just purchased a computer for its new automated reservations system. You have been asked to develop the new system. You are to write an application to assign seats on flight of the airline’s only plane (capacity: 10 seats). Your application should display the following alternatives: "Please type 1 for First Class" and "Please type 2 for Economy." If the user types 1, your application should assign a seat in the first-class section (seats 1 – 5). If the user types 2, your application should assign a seat in the economy section (seats 6 – 10). Your application should then display a boarding pass indicating the person’s seat number and whether it’s in the first-class or economy section of the plane. Use a one-dimensional array of primitive type boolean to represent the seating chart of the plane. Initialize all the elements of the array to false to indicate that all the seats are empty. As each is assigned, set the corresponding element of the array to true to indicate that the seat is on longer available. Your application should never assign a seat that has already been assigned. When the economy section is full, your application should ask the person if it’s acceptable to be placed in the first-class section (and vice versa). If yes, make the appropriate seat assignment. If no, display the message "Next flight leaves in 3 hours." End the program when all the ten seats on the plane have been assigned.

No input, processing or output should happen in the main method. All work should be delegated to other non-static methods. Include the recommended minimum documentation for each method. See the program one template for more details.

Run your program, with your own data, and copy and paste the output to a file. Create a folder named, fullname_program8. Copy your source code and the output file to the folder. Zip the folder and upload it to Blackboard.

/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package airlineapp;


import java.util.Scanner;

/**
*
* @author user1
*/
public class AirlineApp {
int num;
int i;
int counter = 0;
int [] seatNum = new int[11];

  
public static void main(String[] args) {
AirlineApp application = new AirlineApp();
application.userInput();
application.seatChart();
  
//create the array
  
  
// TODO code application logic here
}

public void userInput(){
Scanner input = new Scanner(System.in);
System.out.print("Please type 1 for first class and press 2 for economy: ");

//gets the input from the user and saves it as num to perform the rest
//of the aplication
num = input.nextInt();

}

public void seatChart(){
  
for(int counter = 0; counter < seatNum.length; counter++){
if(num != 2 && counter < 6 )
counter = counter + 1;
  
  
}
  
  
  
  
}
  
  
}


  
  
  
  
  
  
  

  
  
  
  

Solutions

Expert Solution

// Java program to simulate an automated reservations system for Airline
import java.util.Scanner;

public class AirlineApp {
  
   private boolean [] seatChart ; // array of seatChart which determines if seat is available or not
  
   // constructor that allocates 10 seats for the airline
   //initially all are available
   public AirlineApp()
   {
       seatChart = new boolean[10];
       for(int i=0;i<seatChart.length;i++)
           seatChart[i] = false;
   }
  
   // method to simulate user input and processing
   public void userInput(){
      
       Scanner input = new Scanner(System.in);
       String choice;
       int index;
       // loop that continues till all the seats are reserved
       while(economyEmptySeat() != -1 || firstClassEmptySeat() != -1)
       {
           // input the type of seat
           System.out.print("\nPlease type 1 for first class and press 2 for economy: ");
          
           //gets the input from the user and saves it as num to perform the rest
           //of the application
           int num = input.nextInt();
           if(num == 2) // if economy class
           {
               index = economyEmptySeat(); // get the index of the next seat free , -1 is economy is full
               if(index == -1) // check if economy is full
               {
                   // inform the user and ask if they would like to be placed in first class
                   System.out.print("Economy class is full. Should I place you in First class (yes/no) ? ");
                   choice = input.next();
                   // if user agrees, allocate a seat in first class and display the boarding pass
                   if(choice.equalsIgnoreCase("yes"))
                   {
                       index = firstClassEmptySeat();
                       seatChart[index] = true;
                       displayBoardPass(index);
                      
                   }else // if user doesn't agree, display the message
                       System.out.println("Next flight leaves in 3 hours");
               }else // if seat is available in economy, allocate a seat and display the boarding pass
               {
                   seatChart[index] = true;
                   displayBoardPass(index);
               }
           }else if(num == 1) // first class
           {
               index = firstClassEmptySeat(); // get the index of the next seat free , -1 is economy is full
               if(index == -1) // check if first class is full
               {
                   // inform the user and ask if they would like to be placed in economy class
                   System.out.print("First class is full. Should I place you in Economy class (yes/no)");
                   choice = input.next();
                  
                   // if user agrees, allocate a seat in economy class and display the boarding pass
                   if(choice.equalsIgnoreCase("yes"))
                   {
                       index = economyEmptySeat();
                       seatChart[index] = true;
                       displayBoardPass(index);
                      
                   }else // if user doesn't agree, display the message
                       System.out.println("Next flight leaves in 3 hours");
               }else // if seat is available in first class, allocate a seat and display the boarding pass
               {
                   seatChart[index] = true;
                   displayBoardPass(index);
               }
           }else // invalid choice
               System.out.println("Invalid choice");
       }
   }

   // method that returns the next available seat in economy class, -1 if full
   public int economyEmptySeat()
   {
       for(int i=0;i<5;i++)
           if(!seatChart[i])
               return i;
       return -1;
   }
  
   // method that returns the next available seat in first class, -1 if full
   public int firstClassEmptySeat()
   {
       for(int i=5;i<seatChart.length;i++)
           if(!seatChart[i])
               return i;
       return -1;
   }
  
   // method to display the boarding pass
   public void displayBoardPass(int index)
   {
       System.out.println("BOARDING PASS: ");
       System.out.println("Seat Number : "+(index+1));
       if(index >=0 && index < 5)
           System.out.println("Economy");
       else
           System.out.println("First class");
   }
  
  
   public static void main(String[] args) {
       // create an object of AirlineApp
       AirlineApp application = new AirlineApp();
       application.userInput(); //simulate the operation
   }

}
//end of program

Output:


Related Solutions

hey im having trouble with this Use Excel to find the Standard Normal Probability for the...
hey im having trouble with this Use Excel to find the Standard Normal Probability for the following questions. Don't forget to sketch the normal distribution and shade the required area. a) What is the area under the standard normal curve to the left of z = 0.89? (4dp) Answer b) What is the area under the standard normal curve between z = -0.89 and z = 1.63? (4dp) Answer c) What is the z-value that gives the right hand tail...
Im having trouble turning my words and calculations into tables and graphs for my research methods...
Im having trouble turning my words and calculations into tables and graphs for my research methods paper. I need 2 tables and 1 graph. Table 1 - should show that out of 17,425 respondents 43% resported being in business for 3+ years. 33% reported being in business for 1-2 years and 24% respondents being on business for 0-1 years Table 2 - should show marketing method preference. 43% respondent with both online and relationship marketing methods. the 33% group respondent...
Hello, Im having trouble understanding the graphing/chart section of this lesson. Is there anyone who can...
Hello, Im having trouble understanding the graphing/chart section of this lesson. Is there anyone who can help me understand? Goods A B C D E F Capital 5 4 3 2 1 0 Consumer 0 5 9 12 14 15 (presentation as a table rather than as a graph) 1. Using the above PPTable, if the economy is producing at alternative D, the opportunity cost of producing one more unit of capital is A. 1 unit of consumer goods. B....
I have to write a random password generator in Python 3 and im having some trouble...
I have to write a random password generator in Python 3 and im having some trouble writing the code and i dont really know where to start. The prompt goes as such: The problem in this assignment is to write a Python program that uses functions to build (several options of) passwords for the user. More specifically, your program will do the following: 1. Prompt the user for the length of the password to be generated. Call this length lenP....
Im having trouble making nursing diagnosis for PTSd , anyone can give idea. My pt is...
Im having trouble making nursing diagnosis for PTSd , anyone can give idea. My pt is 26 yo had car accident since then shes distressed by the accident, social interaction changed, unable to handle work , she experienced flashback and have phobia against car. She experienced self destructive behavior and experienced sleep dosturbances
answer in basic JAVA im in and INTRO JAVA CLASS Problem 2: Point of Sale System...
answer in basic JAVA im in and INTRO JAVA CLASS Problem 2: Point of Sale System The McDowell Restaurant chain has asked you to write a menu program for their new Fast-food service machines. Your program already prints the following menu like this: ********************************************************************** McDowell’s Restaurant ********************************************************************** Make your selection from the menu below: 1. Regular Hamburger $1.50 2. Regular Cheeseburger $1.75 3. Fish Sandwich $2.50 4. Half-pounder with cheese $2.75 5. French Fries $0.99 6. Large Soft Drink $1.25...
Having some trouble with this Java Lab (Array.java) Objective: This lab is designed to create an...
Having some trouble with this Java Lab (Array.java) Objective: This lab is designed to create an array of variable length and insert unique numbers into it. The tasks in this lab include: Create and Initialize an integer array Create an add method to insert a unique number into the list Use the break command to exit a loop Create a toString method to display the elements of the array Task 1: Create a class called Array, which contains an integer...
Hello! I am having trouble starting this program in Java. the objective is as follows: "...
Hello! I am having trouble starting this program in Java. the objective is as follows: " I will include a text file with this assignment. It is a text version of this assignment. Write a program that will read the file line by line, and break each line into an array of words using the tokenize method in the String class. Count how many words are in the file and print out that number. " my question is, how do...
​​​​​​This is an assignment that I'm having trouble figuring out in python: Modify Node class so...
​​​​​​This is an assignment that I'm having trouble figuring out in python: Modify Node class so it has a field called frequency and initialize it as one. Add a search function. If a number is in the list, return its frequency. Modify Insert function. Remove push, append, and insertAfter as one function called insert(self, data). If you insert a data that is already in the list, simply increase this node’s frequency. If the number is not in the list, add...
Hello, I’m having some trouble making changes to the Cellphone and the associated tester class; Any...
Hello, I’m having some trouble making changes to the Cellphone and the associated tester class; Any help is appreciated ! Cellphone class; -Implement both get and set methods for all 3 attributes or fields of the class - Fields/Attributes are all initialized using the setter methods and there’s no need to initialize them using the contractor. 2) Tester Class; -Create the objects using the default constructor. This is the constructor with no parameter -Call the set methods of all 3...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT