Java Airplane Booking Program?

Java Airplane Booking Program?

Postby egan » Fri Jun 22, 2012 5:07 am

Program Description: Create an application that will act as an airplane-booking program. You will first need to create an object that will have the following attributes listed below. You will then need to create an ArrayList of this object. You then need to book the seats according to the list below. You will need several methods for this program.

Methods to include:
Seat Open (determines if the seat is available)
Print seat information

Attributes of the seat object:
Seat letter
Row number
Name of passenger
Age of passenger


Passengers to book a seat for:
James Jones, 4A
Aaron Adams, 7C
Shirley Simms, 12D
Charlie Chan, 8E
Maria Madison, 43F


Seat Object:

public class Seat {
String seatLetter;
int seatRow;
String passengerName;
int passengerAge;
boolean seatOpen = true;

public boolean open() {
if (seatOpen = true) {
return true;
} else {
return false;
}
}

public void printInfo() {
System.out.println ("Seat: " + seatRow + seatLetter);
System.out.println ("Passenger: " + passengerName);
}
}

Program:

import java.util.*;

public class SeatBooker {
public static void main (String[] args) {
ArrayList<Seat> seatArray = new ArrayList<Seat>();
int counter = 1;
int lettercode = 65;
int number = 1;
int objIndex = 0;
Seat seat = new Seat();

while (counter <= 258) {
seatArray.add(seat);
counter++;
}

counter = 1;

while (objIndex < 258) {
Seat current = seatArray.get(objIndex);
char currentLetter = (char)lettercode;
current.seatLetter = Character.toString(currentLetter);
if (counter < 6) {
lettercode++;
} else {
lettercode = 65;
counter = 0;
}
objIndex++;
counter++;
}

objIndex = 0;
counter = 1;

while (objIndex < 258) {
Seat current = seatArray.get(objIndex);
current.seatRow = number;
if (counter < 6) {
counter++;
} else {
number++;
counter = 1;
}
objIndex++;
}

System.out.print ("Enter name: ");
Scanner s = new Scanner(System.in);

String name = s.nextLine();

System.out.print ("Enter seat: ");
Scanner s2 = new Scanner(System.in);

String seatID = s2.nextLine();
char row = seatID.charAt(0);
char column = seatID.charAt(1);
int rowNum = Character.getNumericValue(row) - 1;
int columnvalue = (int)column - 65;

int index = (rowNum * 6) + columnvalue;

Seat Booked = seatArray.get(index);

if (Booked.open()) {
Booked.passengerName = name;
Booked.seatOpen = false;
System.out.println ("Seat booked! Info: ");
Booked.printInfo();
} else {
System.out.println ("Seat taken!");
}
}
}

Problem:

The code compiles and runs error free, but the seat outputted is always 43F, the last seat. I'm thinking the problem is the assigning of the variables to the objects in the array, but i don't know how to fix it. Please help?
egan
 
Posts: 755
Joined: Fri Apr 01, 2011 2:12 pm
Top

Java Airplane Booking Program?

Postby ealahweemah72 » Fri Jun 22, 2012 5:10 am

Check your Seat Object. Need's a }, after true;.
ealahweemah72
 
Posts: 738
Joined: Thu Mar 31, 2011 9:30 am
Top


Return to Maritime Law

Who is online

Users browsing this forum: beacher, bocley, cumhea, jerard, maddox, roche, sherborne16, stein74 and 0 guests









Sponsored by: