Hi I need help with a java program that I need to create a Airline Reservation System I already finish it but it doesnt work can someone please help me I would be delighted it doesnt show the available seats when running the program and I need it to run until someone says no for booking a seat and if they want to cancel a seat it should ask the user to cancel a seat or continue booking also it should prompt them to go back to the main menu and choose a ticket type and a row number and column here is my program
import java.io.*;
import java.util.*;
public class AirReservations {
static Scanner scan = new Scanner(System.in);
public static void main(String[] args) {
// TODO Auto-generated method
stub
{
//creats new
array, at this point all of the values are set to null
char[][] seats =
new char[13][6];
MenuSystem
myMenu = new MenuSystem();
myMenu.presentMenu("main",0);
myMenu.presentSeatingChoice("sc-menu",0);
myMenu.presentClassChoice("cc-menu",0);
myMenu.presentRowChoiceMenu("rc-menu",0);
myMenu.presentColumnChoiceMenu("col-menu",0);
SeatingSystem
mySystem = new SeatingSystem();
mySystem.displaySeatingchart(seats);
mySystem.seatAvailable(seats, "seatCode");
mySystem.seatAssign(seats, "seatCode");
mySystem.seatUnAssign(seats, "seatCode");
//this method
will populate the array with "*" instead of nulls,
//denoting an
empty seat
pupulateGrid(seats);
//prompt
user, 0 to quit 1 to reserve
System.out.println("Enter 0 to quit or 1 to reserve a ticket");
//choice is
the result of the above prompt
int choice =
scan.nextInt();
//if choice
is 0 then the user does not run this loop and they are done
//booking id
choice is 1 the loop below will run.
while(choice !=
0)
{
//the rowMessage() asks the user for a row
choice i.e. A, B, C, D, E
//converts it to an int. We do this so we can
use the numerical
//value to index the array.
int row = rowMessage();
//the colMessage() asks the user for a numerical
row choice
//and returns and stores it into column
int col = colMessage();
//HERE IS WHERE WE CHECK IF THE ROW AND COL
ENTERD IS VALID
if(row<6&&col<13)
{
// HERE IS WHERE WE CHECK IF
THE seat is taken, if it is print seat taken
if (seats[row][col] ==
'X')
System.out.println("seat taken");
//if the seat is empty mark
it occupied using 'x'
if (seats[row][col] ==
'*')
seats[row][col] = 'x';
}//END IF FOR VALID CHECK HERE
System.out.print("Enter 0 to quit or 1 to
reserve a ticket");
choice = scan.nextInt();
}
printGrid(seats);
}
}
public static int
rowMessage()
{
System.out.println(" Enter your row as letter ");
String rowLetter
= scan.next();
if(
rowLetter.equals("A"))
return 0;
if(
rowLetter.equals("B"))
return 1;
if(
rowLetter.equals("C"))
return 2;
if(
rowLetter.equals("D"))
return 3;
if(
rowLetter.equals("E"))
return 4;
if(
rowLetter.equals("F"))
return 5;
return 6;
}
public static int
colMessage()
{
System.out.println(" Enter your column as letter ");
int col =
scan.nextInt();
return
col;
}
public static void
printGrid(char[][] multiPassed)
{
for (int i = 0;
i < 13; i++)
{
for (int j = 0; j < 6; j++)
{
System.out.print(multiPassed[i][j]);
}
System.out.println("");
}
}
public static void
pupulateGrid(char[][] multiPassed)
{
for (int i = 0;
i < 13; i++)
{
for (int j = 0; j < 6; j++)
{
multiPassed[i][j] = '*';
}
}
}
}
import java.util.Scanner;
public class MenuSystem {
//This will print the menuId which what the user want
to do for the first
//MainMenu
public static int presentMenu(String menuId,int
main)
{ Scanner scan = new Scanner(System.in);
if(menuId.equals("main"))//This
will equal the main menu of the Airline Reservation System
{
System.out.println("1. Book a reservation ");
System.out.println("2. Cancel a reservation ");
System.out.println("3. Print Current Seating Chart
");
System.out.println("Press 0 to Exit System\n" );
System.out.println("Please choose an option to
proceed|| Pres '0' to exit to main menu ");
menuId = scan.nextLine();
int Menu=main;
}
return main;//This will return the main menu
}
//This will let the user to pick a choice either a
ticket type or return
//to the main menu
public static int presentSeatingChoice(String menuId,
int scChoicemenu)
{
Scanner scan = new Scanner(System.in);
if (menuId.equals("sc-menu"))//This method will be
be determined what the
//user
will want to do.
{
System.out.println("Seating Choice Menu");
System.out.println("1) Choose Ticket Type (First
Class, Business Class, Economy Class)");
System.out.println("2) Exit to Main Menu");
System.out.println("Pick a choice to proceed to the
next section or type a to '2' to go back to the MainMenu");
scChoicemenu = scan.nextInt();
}
int sChoice = scChoicemenu;
return sChoice;//This will return the Seating Choice
Menu
}
//This method will return the class choice menu
public static int presentClassChoice(String menuId,
int ccChoicemenu)
{
Scanner scan = new Scanner(System.in);
if (menuId.equals("cc-menu"))// This will also
equal to the menuId for
// the
class choice menu to appear
{
System.out.println("Class Choice Menu");
System.out.println("1. Firstclass");
System.out.println("2. Businessclass");
System.out.println("3. Economyclass");
System.out.println("0. Exit to the MainMenu");
System.out.println("Please choose a Class choice or
type '0'to return to return to the main menu");
ccChoicemenu = scan.nextInt();
}
int cChoice = ccChoicemenu;
return cChoice;// This will return the Class Choice
Menu
}
//This method will let the user to
choose what row they like to seat in
public static int presentRowChoiceMenu(String menuId,
int rwChoicemenu)
{
Scanner scan = new Scanner(System.in);
if(menuId.equals("rc-menu"));//Row Choice Menu inside
a if statement that
//Will
equals to the choices below
System.out.println("Row Choice Menu");
System.out.println("1)(For first class type numbers type '1-2'");
System.out.println("2)(For Business class type '3-7'");
System.out.println("3)(For Economy class type
'8-13' ");
System.out.println("Choose a option to proceed to the
column choice");
rwChoicemenu= scan.nextInt();
int rwChoice= rwChoicemenu;
return rwChoice;
}
//This method is where the column choices will take
place to let the user
//Decide what column they like to place in
public static int presentColumnChoiceMenu(String
menuId, int cwChoice)
{
Scanner scan = new Scanner(System.in);
System.out.println("Seat Choice Menu");
if(menuId.equals("col-menu"));//Column Choice Menu
will also be equal to the
//choices below
{
System.out.println("Pick a letter which you want to
reserve in 'A=1' , 'B=2', 'C=3', 'D=4', 'E=5', 'F=6' ");
System.out.println("Choose a option to proceed || Pres
'0' to exit to main menu ");
cwChoice = scan.nextInt();
}
int cChoice=cwChoice;
return cwChoice;
}
}
public class SeatingSystem {
public static final int ROWS = 13;
public static final int COLS = 6;
public static final void seat(char[][] seatingChart)
{
for(int i=0; i for(int j=0;j
seatingChart[i][j] = '*';
}
}
}//this is where the seatingSystem will determine if
the seat is Available or not
public static boolean seatAvailable(char [][]
seatingChart, String seatCode)
{
int row = 1, index = 1, col = 1;
while(seatCode.charAt(index) >= '0' &&
seatCode.charAt(index) <= '9') {
row = row*10 + (int)seatCode.charAt(index) - 48;
index++;
}
col = (int)index - (int)'A';
if(seatingChart[row][col] == '*')
return true;
else return false;
}
// This method will be an integer and a char
statement with a nested
//if else statment to assign the seat
public static int seatAssign(char [][] seatingChart,
String seatCode)
{
int row = 0, index = 0, col = 0;
while(seatCode.charAt(index) >= '0' &&
seatCode.charAt(index) <= '9') {
row = row*10 + (int)seatCode.charAt(index) - 48;
index++;
}
col = (int)index - (int)'A';
if(seatingChart[row][col] == '*') {
seatingChart[row][col] = 'X';
return 1;
}
return 0;
}
public static int seatUnAssign(char[][] seatingChart,
String seatCode)
{
int row = 0, index = 0, col = 0;
while(seatCode.charAt(index) >= '0' &&
seatCode.charAt(index) <= '9') {
row = row*10 + (int)seatCode.charAt(index) - 48;
index++;
}
col = (int)index - (int)'A';
if(seatingChart[row][col] == 'X') {
seatingChart[row][col] = '*';
return 1;
}
return 0;
}
// this method will display and print the seating
chart
public static void
displaySeatingchart(char[][]seatingChart)
{
System.out.print("\t");
for(int j=0; j System.out.print(
(char)((int)'A' + j) + "\t");
}
System.out.println();
for(int i=0; i System.out.print("Row" +
String.valueOf(i+1) + "\t");
for(int j=0; j
System.out.print(seatingChart[i][j] + "\t");
}
System.out.println();
}
}
}
//Air Reservations :
package com.test.java;
import java.util.Scanner;
public class AirReservations {
static Scanner scan = new Scanner(System.in);
public static void main(String[] args) {
// TODO Auto-generated method
stub
{
// creats new
array, at this point all of the values are set to null
char[][] seats =
new char[13][6];
choiceSelection(seats);
// this method
will populate the array with "*" instead of nulls,
// denoting an
empty seat
pupulateGrid(seats);
// prompt user,
0 to quit 1 to reserve
choiceMenu(seats);
printGrid(seats);
}
}
private static void choiceSelection(char[][] seats)
{
int choice =
menuSystemCall();
System.out.println("Choice
Choosen--->"+choice);
switch (choice) {
case 0:
System.exit(0);
break;
case 1:
seatingSystemCall(seats, choice);
break;
case 2:
choice =
menuSystemCall();
seatingSystemCall(seats, choice);
break;
case 3:
seatingSystemCall(seats, choice);
break;
default:
choice =
menuSystemCall();
break;
}
}
private static void choiceMenu(char[][] seats)
{
System.out.println("Enter 0 to quit
or 1 to reserve a ticket");
// choice is the result of the
above prompt
int choice = scan.nextInt();
// if choice is 0 then the user
does not run this loop and they are done
// booking id choice is 1 the loop
below will run.
while (choice != 0) {
// the
rowMessage() asks the user for a row choice i.e. A, B, C, D,
// E
// converts it
to an int. We do this so we can use the numerical
// value to
index the array.
int row =
rowMessage();
// the
colMessage() asks the user for a numerical row choice
// and returns
and stores it into column
int col =
colMessage();
// HERE IS WHERE
WE CHECK IF THE ROW AND COL ENTERD IS VALID
if (row < 13
&& col < 6) {
// System.out.println("Seat
Status--->"+seats[row][col]);
// HERE IS WHERE WE CHECK IF THE seat is taken,
if it is print
// seat taken
if (seats[row][col] == 'X')
System.out.println("seat
taken by others already");
// if the seat is empty mark it occupied using
'x'
if (seats[row][col] == '*')
System.out.println("seat
reserved for you");
seats[row][col] = 'x';
}// END IF FOR
VALID CHECK HERE
System.out.print("Enter 0 to quit or 1 to reserve a ticket");
choice =
scan.nextInt();
}
}
private static void seatingSystemCall(char[][]
seats, int ch) {
SeatingSystem mySystem = new
SeatingSystem();
if (ch == 3 || ch == 1)
mySystem.displaySeatingchart(seats);
mySystem.seatAvailable(seats,
"seatCode");
mySystem.seatAssign(seats,
"seatCode");
if (ch == 2)
mySystem.seatUnAssign(seats, "seatCode");
}
private static int menuSystemCall() {
MenuSystem myMenu = new
MenuSystem();
int choice =
myMenu.presentMenu("main");
System.out.println("Choice
menuSystemCall--->"+choice);
if(choice == 0 ||
choice==2||choice==3){
return
choice;
}
myMenu.presentSeatingChoice("sc-menu", 0);
myMenu.presentClassChoice("cc-menu", 0);
myMenu.presentRowChoiceMenu("rc-menu", 0);
myMenu.presentColumnChoiceMenu("col-menu", 0);
return choice;
}
public static int rowMessage() {
System.out.println(" Enter your row
as letter ");
String rowLetter =
scan.next();
if (rowLetter.equals("A"))
return 0;
if (rowLetter.equals("B"))
return 1;
if (rowLetter.equals("C"))
return 2;
if (rowLetter.equals("D"))
return 3;
if (rowLetter.equals("E"))
return 4;
if (rowLetter.equals("F"))
return 5;
if (rowLetter.equals("H"))
return 6;
if (rowLetter.equals("I"))
return 7;
if (rowLetter.equals("J"))
return 8;
if (rowLetter.equals("K"))
return 9;
if (rowLetter.equals("L"))
return 10;
if (rowLetter.equals("M"))
return 11;
if (rowLetter.equals("N"))
return 12;
return 12;
}
public static int colMessage() {
System.out.println(" Enter your
column number ");
int col = scan.nextInt();
return col;
}
public static void printGrid(char[][] multiPassed)
{
for (int i = 0; i < 13; i++)
{
for (int j = 0;
j < 6; j++) {
System.out.print(multiPassed[i][j]);
}
System.out.println("");
}
}
public static void pupulateGrid(char[][]
multiPassed) {
for (int i = 0; i < 13; i++)
{
for (int j = 0;
j < 6; j++) {
multiPassed[i][j] = '*';
}
}
}
}
//Menu system:
package com.test.java;
import java.util.Scanner;
public class MenuSystem {
//This will print the menuId which what the user want
to do for the first
//MainMenu
public static int presentMenu(String menuId)
{ Scanner scan = new Scanner(System.in);
if(menuId.equals("main"))//This will equal the main menu of the
Airline Reservation System
{
System.out.println("1. Book a reservation ");
System.out.println("2. Cancel a reservation ");
System.out.println("3. Print Current Seating Chart ");
System.out.println("Press 0 to Exit System\n" );
System.out.println("Please choose an option to proceed|| Pres '0'
to exit to main menu ");
menuId = scan.nextLine();
}
return Integer.parseInt(menuId);//This will return the main
menu
}
//This will let the user to pick a choice either a ticket type or
return
//to the main menu
public static int presentSeatingChoice(String menuId, int
scChoicemenu)
{
Scanner scan = new Scanner(System.in);
if (menuId.equals("sc-menu"))//This method will be be determined
what the
//user will want to do.
{
System.out.println("Seating Choice Menu");
System.out.println("1) Choose Ticket Type (First Class, Business Class, Economy Class)");
System.out.println("2) Exit to Main Menu");
System.out.println("Pick a choice to proceed to the next section or
type a to '2' to go back to the MainMenu");
scChoicemenu = scan.nextInt();
}
int sChoice = scChoicemenu;
return sChoice;//This will return the Seating Choice Menu
}
//This method will return the class choice menu
public static int presentClassChoice(String menuId, int
ccChoicemenu)
{
Scanner scan = new Scanner(System.in);
if (menuId.equals("cc-menu"))// This will also equal to the menuId
for
// the class choice menu to appear
{
System.out.println("Class Choice Menu");
System.out.println("1. Firstclass");
System.out.println("2. Businessclass");
System.out.println("3. Economyclass");
System.out.println("0. Exit to the MainMenu");
System.out.println("Please choose a Class choice or type '0'to
return to return to the main menu");
ccChoicemenu = scan.nextInt();
}
int cChoice = ccChoicemenu;
return cChoice;// This will return the Class Choice Menu
}
//This method will let the user to choose what row they like to
seat in
public static int presentRowChoiceMenu(String menuId, int
rwChoicemenu)
{
Scanner scan = new Scanner(System.in);
if(menuId.equals("rc-menu"));//Row Choice Menu inside a if
statement that
//Will equals to the choices below
System.out.println("Row Choice Menu");
System.out.println("1)(For first class type numbers type
'1-2'");
System.out.println("2)(For Business class type '3-7'");
System.out.println("3)(For Economy class type '8-13' ");
System.out.println("Choose a option to proceed to the column
choice");
rwChoicemenu= scan.nextInt();
int rwChoice= rwChoicemenu;
return rwChoice;
}
//This method is where the column choices will take place to let
the user
//Decide what column they like to place in
public static int presentColumnChoiceMenu(String menuId, int
cwChoice)
{
Scanner scan = new Scanner(System.in);
System.out.println("Seat Choice Menu");
if(menuId.equals("col-menu"));//Column Choice Menu will also be
equal to the
//choices below
{
System.out.println("Pick a letter which you want to reserve in
'A=1' , 'B=2', 'C=3', 'D=4', 'E=5', 'F=6' ");
System.out.println("Choose a option to proceed || Pres '0' to
exit to main menu ");
cwChoice = scan.nextInt();
}
int cChoice=cwChoice;
return cwChoice;
}
}
//Seating System:
package com.test.java;
public class SeatingSystem {
public static final int ROWS = 13;
public static final int COLS = 6;
public static final void seat(char[][]
seatingChart) {
for (int i = 0; i < ROWS; i++)
{
for (int j = 0;
j < COLS; j++) {
seatingChart[i][j] = '*';
}
}
}// this is where the seatingSystem will determine if
the seat is Available
// or not
public static boolean seatAvailable(char[][]
seatingChart, String seatCode) {
int row = 1, index = 1, col =
1;
while (seatCode.charAt(index) >=
'0' && seatCode.charAt(index) <= '9') {
row = row * 10 +
(int) seatCode.charAt(index) - 48;
index++;
}
if(index>(int) 'A')
col = (int) index - (int)
'A';
System.out.println(row
+"--->"+col);
if (seatingChart[row][col] ==
'*')
return
true;
else
return
false;
}
// This method will be an integer and a char
statement with a nested
// if else statment to assign the seat
public static int seatAssign(char[][] seatingChart,
String seatCode) {
int row = 0, index = 0, col =
0;
while (seatCode.charAt(index) >=
'0' && seatCode.charAt(index) <= '9') {
row = row * 10 +
(int) seatCode.charAt(index) - 48;
index++;
}
if(index>(int) 'A')
col = (int) index - (int)
'A';
System.out.println("roiw"+row+"----->"+col);
if (seatingChart[row][col] == '*')
{
seatingChart[row][col] = 'X';
return 1;
}
return 0;
}
public static int seatUnAssign(char[][]
seatingChart, String seatCode) {
int row = 0, index = 0, col =
0;
while (seatCode.charAt(index) >=
'0' && seatCode.charAt(index) <= '9') {
row = row * 10 +
(int) seatCode.charAt(index) - 48;
index++;
}
if(index>(int) 'A')
col = (int) index - (int)
'A';
if (seatingChart[row][col] == 'X')
{
seatingChart[row][col] = '*';
return 1;
}
return 0;
}
// this method will display and print the seating
chart
public static void displaySeatingchart(char[][]
seatingChart) {
System.out.print("\t");
for (int j = 0; j < COLS; j++)
{
System.out.print((char) ((int) 'A' + j) + "\t");
}
System.out.println();
for (int i = 0; i < ROWS; i++)
{
System.out.print("Row" + String.valueOf(i + 1) + "\t");
for (int j =
0; j < COLS; j++)
System.out.print(seatingChart[i][j] +
"\t");
}
System.out.println();
}
}
Hi I need help with a java program that I need to create a Airline Reservation...
This is for Java. Create ONE method/function that will return an array containing the row and column of the largest integer i the 2D array. If the largest number is located on row 2, column 1, the method needs to return row 2 and column one. Do not use more than one method. Use the code below as the main. Please comment any changes. in java Given the main, create a method that RETURNS the largest number found in the...
Look for some finshing touches java help with this program. I just two more things added to this code. A loop at the end that will ask the user if they want to quit if they do want to quit the program stops if they don't it loads a new number sequence. import java.util.Random; import java.util.ArrayList; import java.util.Scanner; import java.util.Arrays; import java.util.List; import java.util.Collections; public class main { public static void main(String[] args) { List < Sequence > list =...
the code needs to be modifed. require a output for the code Java Program to Implement Insertion Sort import java.util.Scanner; /Class InsertionSort * public class Insertion Sort { /Insertion Sort function */ public static void sort( int arr) int N- arr.length; int i, j, temp; for (i-1; i< N; i++) j-i temp arrli; while (j> 0 && temp < arrli-1) arrli]-arrli-1]; j-j-1; } arrlj] temp; /Main method * public static void main(String [] args) { Scanner scan new Scanner( System.in...
The following code is a Java code for insertion sort. I would like this code to be modified by not allowing more than 10 numbers of integer elements (if the user enters 11 or a higher number, an error should appear) and also finding the range of the elements after sorting. /* * Java Program to Implement Insertion Sort */ import java.util.Scanner; /* Class InsertionSort */ public class InsertionSortTwo { /* Insertion Sort function */ public static void sort( int...
need help editing or rewriting java code, I have this program running that creates random numbers and finds min, max, median ect. from a group of numbers,array. I need to use a data class and a constructor to run the code instead of how I have it written right now. this is an example of what i'm being asked for. This is my code: import java.util.Random; import java.util.Scanner; public class RandomArray { // method to find the minimum number in...
Need Help ASAP!! Below is my code and i am getting error in (public interface stack) and in StackImplementation class. Please help me fix it. Please provide a solution so i can fix the error. thank you.... package mazeGame; import java.io.*; import java.util.*; public class mazeGame { static String[][]maze; public static void main(String[] args) { maze=new String[30][30]; maze=fillArray("mazefile.txt"); } public static String[][]fillArray(String file) { maze = new String[30][30]; try{...
JAVA Can you make this return the first letter of first and last name capitalized? import java.io.File; import java.io.IOException; import java.util.*; public class M1 { public static void main(String[] args) { //scanner input from user Scanner scanner = new Scanner(System.in); // System.out.print("Please enter your full name: "); String fullname = scanner.nextLine(); //creating a for loop to call first and last name separately int i,k=0; String first="",last=""; for(i=0;i<fullname.length();i++) { char j=fullname.charAt(i); if(j==' ') { k=i; break; } first=first+j;...
In this same program I need to create a new method called “int findItem(String[] shoppingList, String item)” that takes an array of strings that is a shopping list and a string for an item name and searches through the “shoppingList” array for find if the “item” exists. If it does exist print a confirmation and return the item index. If the item does not exist in the array print a failure message and return -1. import java.util.Scanner; public class ShoppingList...
Complete the following Java program by writing the missing methods. public class 02 { public static void main(String[] args) { Scanner scan = new Scanner(System.in); System.out.println("Enter a number: int n = scan.nextInt(); if (isOdd (n)) { //Print n to 1 System.out.println("Print all numbers from "+n+" to 1"); printNumToOne (n); } else { System.out.println(n + " is //End of main()
5. Write a static method "f(n)" in the space provide, that returns O if n is even, and if n is odd, returns 1 or -1 according as n is greater than or less than 0. importjava.util.Scanner; public class Q_05 Your "f(n)" method: public static void main(String args[]) mana int n; Scanner input = new Scanner(System.in); System.out.print("Please enetrn: "); n=input.nextInt(); System.out.println(f(n)); "Method f(n)" 7. Write a static method "max" in the space provide, that returns the maximum value from 3...