reservation

reservation

Page 1 of 1

2 Replies - 2943 Views - Last Post: 23 February 2009 - 07:00 AM Rate Topic: -----

#1 bluegirltulbo  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 13
  • Joined: 09-February 09

reservation

Post icon  Posted 23 February 2009 - 12:37 AM

please improve this code
i dont know how to override or overload this program...
somebody can make...?
this is creteria i need to improved this prpgram..
* atleast two loops
*override or overload
*atleast 100 lines...
*using private
*array optional
*user define
this is the code i want to improve please help me...
tomorrow is my defend about this program
and please give me an explanation every line and every method
thanxxxx

godbless you all....


package xexamp;

import java.util.Scanner;
import java.util.Date;

public class reservation {


// Create an array of 12 seats, 6 window and 6 aisle.
private static int[] seats = new int[12];

public static void main(String args[]) {
System.out.println("Welcome to the DIC lovin train reservation system!");
System.out.println("Code ninjas, code newbies, one fabulous DIC ride!");
System.out.println();


// Lets start by setting all seats equal to 0 (aka Empty)
for (int i = 0; i < 12; i++) {
seats[i] = 0;
}

// Setup our scanner and default the choice to window.
Scanner s = new Scanner(System.in);
int choice = 1;

// Ask user for a window or an aisle seat and store their coice.
System.out.print("Please enter 1 for window, 2 for aisle, or 0 to exit: ");
choice = s.nextInt();


// While their choice is not the one for exit, execute our booking.
while (choice != 0) {
int seatnumber = 0;


// If they chose a window seat, attempt to book it.
if (choice == 1) {
seatnumber = bookWindow();


// No window seats available, try booking an aisle seat for them instead.
if (seatnumber == -1) {
seatnumber = bookAisle();

if (seatnumber != -1) {
System.out.println("Sorry, we were not able to book a window seat. But do have an aisle seat.");
printBoardingPass(seatnumber);
}
}
else {
// Booking a window seat was successful.
System.out.println("You are in luck, we have a window seat available!");
printBoardingPass(seatnumber);
}
}
else if (choice == 2) {

// If they chose booking an isle, check to see if it is available.
seatnumber = bookAisle();

// If not available, see if we have window seats available.
if (seatnumber == -1) {
seatnumber = bookWindow();

if (seatnumber != -1) {
System.out.println("Sorry, we were not able to book an aisle seat. But do have a window seat.");
printBoardingPass(seatnumber);
}
}
else {
// Booking an aisle seat was successful.
System.out.println("You are in luck, we have an aisle seat available!");
printBoardingPass(seatnumber);
}
}
else {
// Print an error message if they did not choose 1, 2, or 0 for their choice.
System.out.println("Invalid choice made. Please try again!");
choice = 0;
}


// No window or aisle seats were available.
if (seatnumber == -1) {
System.out.println("We are sorry, there are no window or aisle seats available.");
System.out.println();
}


// Reprompt for a choice
System.out.print("Please enter 1 for window, 2 for aisle, or 0 to exit: ");
choice = s.nextInt();
}


}


// This function checks for window seats and returns seat number or -1 if full.
private static int bookWindow() {
for (int i = 0; i < 6; i++) {
if (seats[i] == 0) {
seats[i] = 1;
return i + 1;
}
}
return -1;
}


// This function checks to see if aisle seats were available, -1 if full.
private static int bookAisle() {
for (int i = 6; i < 12; i++) {
if (seats[i] == 0) {
seats[i] = 1;
return i + 1;
}
}
return -1;

}


// This simply prints out a nice little boarding pass message with their seat number and date of issue.
private static void printBoardingPass(int seatnumber) {
Date timenow = new Date();
System.out.println();
System.out.println("Date: " + timenow.toString());
System.out.println("Boarding pass for seat number: " + seatnumber);
System.out.println("This ticket is non-refundable and non-transferable.");
System.out.println("Please be curteous, do not smoke. Enjoy your trip.");
System.out.println();
}

Is This A Good Question/Topic? 0
  • +

Replies To: reservation

#2 evha01_comsci  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 11-February 09

Re: reservation

Posted 23 February 2009 - 01:51 AM

hi!!!!!!!!!!
tats...... you know what gutom nko au...
and then la pjd meh kta og codes...
hahay....
Was This Post Helpful? 0
  • +
  • -

#3 ayman_mastermind  Icon User is offline

  • human.setType("geek");
  • member icon

Reputation: 126
  • View blog
  • Posts: 1,860
  • Joined: 12-December 08

Re: reservation

Posted 23 February 2009 - 07:00 AM

@bluegirltulbo Please post your code in code tags to be better readable :code: In addition, evha01_comsci, please make helpful or useful post and please use English, Thanks
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1