For loop not working & way to include an external file

Hi everyone, i am new to java and am having some problems with my program.

I have a for loop but it doesnt work it completely gets ignored and i have

no idea why it does that.

IS there a way that i add another option in the menu to open an external file

which would be similar to this but it would be for cabinBooking. If so how do

i do that. if opening an external file is impossible then could you please show me an example of how to extend the booking class.

Any help would be appreciated.

Thank you very much

import java.util.Scanner;

import java.io.*;

public class Booking{

Booking(String bId,String bName,int bNum){

bookId = bId;

bookName = bName;

bookNum= bNum;

}

String bookId;

String bookName;

intbookNum;

public double calculateBookingPrice(){

double cost= bookNum *genBookingcost;

return cost;

}

double genBookingcost =80;

public voidsummary(){

System.out.println();

System.out.println("Booking Number is: " + bookId + ", ");

System.out.println("Booking Made for : " + bookName);

System.out.println("Cost of booking = $" + calculateBookingPrice());

System.out.println();

}

public static void main(String[] args) throws IOException{

Scannerkeyboard = new Scanner(System.in);

BufferedReader charInput = new BufferedReader

(new InputStreamReader (System.in));

int bookCount = 0;

char answer;

Booking[] bookings = new Booking[6];

do {

menu();

System.out.println("book Count = " + bookCount);

answer = charInput.readLine().charAt(0);

if (answer == 'a' || answer == 'A'){

System.out.println("BookingID : ");

String idstring= keyboard.nextLine();

System.out.println("BookingName : ");

String namestring =keyboard.nextLine();

System.out.println("number of people : ");

intppl= keyboard.nextInt();

bookings[bookCount] = new Booking(idstring,namestring,ppl);

bookings[bookCount].summary();

bookCount++;

}else if (answer == 'b' || answer == 'B'){

System.out.println("Enter printing");

bookings[0].summary();

bookings[1].summary();

// this is the loop that it is ignoring GGRRRR!!!

for(int i = 0; i >= bookCount; i++){

System.out.println("Counter: " + i);

bookings.summary();

}

}else if (answer == 'x' || answer == 'X'){

System.out.println("Exiting the programme...");

System.out.println();

System.exit(0);

}

}while (answer != 'x' || answer != 'X');

}

public static void menu(){

System.out.println("********** Main Menu ***********");

System.out.println("A. Make General Booking");

System.out.println("B. Print Summary");

System.out.println("X. Exit program");

System.out.println("*****************************");

System.out.println("Select one of the options above");

}

}

[3059 byte] By [PiZaRrOa] at [2007-11-27 11:45:22]
# 1

> I have a for loop but it doesnt work it completely

> gets ignored and i have

> no idea why it does that.

It's ignoring the loop because (i >= bookCount) is false at that point.

~

yawmarka at 2007-7-29 18:01:21 > top of Java-index,Java Essentials,New To Java...
# 2

in order to extend the Booking class, you can create anew class like this..

public class CabinBooking extends Booking

{

public CabinBooking( /*String bId, String bName,int bNum .. more args or fewer, or none.. */)

// add new methods or override ones from Booking

}

smithdale87a at 2007-7-29 18:01:21 > top of Java-index,Java Essentials,New To Java...
# 3

Hey,

thnx heaps for your help.

Much appreciated

Cheers

PiZaRro

PiZaRrOa at 2007-7-29 18:01:21 > top of Java-index,Java Essentials,New To Java...