JAVA assignment-advice/information needed!
807589Dec 14 2008 — edited Dec 15 2008I am working on the following assignment: You have to write a seat booking program for a 10 seated aircraft (4 luxery and 6 exectutive).
The software should be able to do the following:
1. Keep track of seating to show availability and allow bookings
2. When a seat is sold the program displays an onscreen ticket showing: seat class, seat number and customer name.
3. The program must continue until all seats are sold or the exit option is made.
4. When all seats are sold, a suitable message must be displayed followed by the program exiting automatically.
So far I have two main programs attempting to work this out:
Program 1:_
import java.util.Scanner;
class jets
{
public static void main(String[]args)
{
Scanner input=new Scanner(System.in);
//delare variables
int option;
int option1;
int option2;
int option3;
int option4;
int luxerySeatsSold=0;
int exectutiveSeatsSold=0;
String customerName=null;
System.out.println( "Hello and welcome to CCNJet! ");
System.out.println("Please select an option from the following menu: ");
{
System.out.println( "1. Book a luxury seat" );
System.out.println( "2. Book an Executive seat " );
System.out.println( "3. Display seat details/availability ");
System.out.println( "4. Exit menu ");
option=input.nextInt();
while ((option==1)&&(luxerySeatsSold<4))
if(option==1)
{
System.out.println(" Please enter your name ");
customerName=input.next();
System.out.println(" ");
luxerySeatsSold++;
System.out.println(" Thank you for your luxery seat order " + customerName + " You have seat number " + luxerySeatsSold);
}
while ((option==2)&&(exectutiveSeatsSold<6))
if (option==2)
{
System.out.println(" Please enter your name ");
System.out.println(" ");
customerName=input.next();
exectutiveSeatsSold++;
System.out.println(" Thank you for your exectutive seat order " + customerName + " You have seat number " + exectutiveSeatsSold);
if (option==3)
System.out.println(" Here is a report of available/unavailable seats on the aircraft ");
}
else if (option==4)
System.out.println("=============");
System.out.println(" Good bye,thanks for looking!");
System.out.println("=========");
}
}
}
Program 2*
import java.util.Scanner;
public class BookFlights {
Scanner scan;
Customer[] customer;
}
public BookFlights()
scan = new Scanner(System.in);
customer = new Customer[10];
}
public void displayMenu() {
System.out.println( "Hello and welcome to CCNJet! ");
System.out.println("Please select an option from the following menu: ");
System.out.println( "1. Book a luxury seat" );
System.out.println( "2. Book an Executive seat " );
System.out.println( "4. Exit menu ");
}
public void bookLuxury()
{
System.out.println(" Please enter your name ");
customerName=input.next();
System.out.println(" ");
luxerySeatsSold++;
System.out.println(" Thank you for your luxery seat order " + customerName + " You have seat number " + luxerySeatsSold);
}
public void processChoice(int c)
{
switch (c) {
case 1 : bookLuxury(); break;
case 2 : bookExecutive(); break;
default : System.out.println("invalid"); break;
}
}
}
Any advice or information which can be given to allow me to meet the specification or to strengthen either program, would be much appreciated.
Thanks,
Ben