Airline Reservations Assignment

File read in, Searching with Binary and serial

Page 1 of 1

12 Replies - 4573 Views - Last Post: 10 May 2010 - 06:10 AM Rate Topic: -----

#1 hottestchica2004  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 17
  • Joined: 11-October 09

Airline Reservations Assignment

Posted 09 May 2010 - 02:57 PM

Assignment:
Airline Reservations Program
Produce an airline reservations program to read up to 50 entries from the data file airline.txt into an array of records. Each record will contain the following fields : Flight number (integer), space, Origination point ( String[15]), space, Destination point (String[15]), space, Departure time (String[8]), and Departure date (String[8]).
The program should then provide a user-friendly menu screen to allow the user to
1. Search by Flight number
2. Search by Origination Point
3. Search by Destination point
Choice 1: The program will then perform a binary search by flight number to display the Origination point, Destination point, and Departure time.
Choice 2 & 3: The program will do a serial search by city name, displaying each city with the entered name.
An error message should print if the flight number or city name is not found.

Airline.java
import java.awt.*;
package com.apress.jsf;

public class Airline extends java.applet.Applet {
    int flightNum;
    int count;
    String origination;
    String destination;
    String departDate;
    String departTime;
    final int ODPT = 15;
    final int DEPTDT = 8;

    //-----------------------------------------------------------
    //Constructor: Creates an empty record of flight information
    //-----------------------------------------------------------
    public void Airline(){
    	Airline [] flight = new flight [50];
    	counter = 0;
    }

    //-----------------------------------------------------------
    //						Add a Flight
    //-----------------------------------------------------------
    public void addFlight(int flightNum, String origination, String destination,
    						String departTime, String departDate){
    	int count = 0;
    	records[count] = new flight(flightNum, origination, destination, departTime, departDate);
    	count++;
    }
    //-----------------------------------------------------------
    //						Read in Flights
    //-----------------------------------------------------------
    public void readFlights(Scanner scan){
    	int prt = 0;
    	fNum = scan.nextInt();
    	temp = scan.nextLine();
    	ptr++;
    	orig = temp.substring(ptr, ptr+ODPT);
    	system.out.println(origination);

    	ptr += ODPT+1;
    	dest = temp.substring(ptr, ptr+ODPT);
    	System.out.println(destination);

    	ptr += ODPT+1;
    	dTime = temp.substring(ptr, ptr+DEPTDT);
    	System.out.println(departTime);

    	ptr += DEPTDT+1;
    	dDate = temp.substring(ptr, endofstring);
    	System.out.println(departDate);
    }

    //---------------------------------------------------------
    //---------------------------------------------------------

    public int getFlightNum() {
    	return flightNum;
    }

    public void setFlightNum(int flightNum) {
    	this.flightNum = flightNum;
    }

    public String getDepartDate() {
    	return departDate;
    }

    public void setDepartDate(String departDate) {
    	this.departDate = departDate;
    }

    public String getDepartTime() {
    	return departTime;
    }

    public void setDepartTime(String departTime) {
    	this.departTime = departTime;
    }

    public String getDestination() {
    	return destination;
    }

    public void setDestination(String destination) {
    	this.destination = destination;
    }

    public String getOrigination() {
    	return origination;
    }
    public void setOrigination(String origination){
    	this.origination = origination;
    }

    //---------------------------------------------------------------------
    //---------------------------------------------------------------------

    public String toString() {
    	String report = "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n";
    	report += "Flight Plans\n";
    	report += "Number of Flights: " + count + "\n";
    	report += "\t Flight List: \n";

    	for (int x=0; x <count; x++)
    		report += records[x].toString() + "\n";

    	return report;
    }
}



AirlineInput.java
public class AirlineInput {

   public static void main (String[] args) throws IOException {
   	Scanner scan = new Scanner(new File("airline.txt"));
   	Airline [] flight = new flight[50];

   	int count = 0;
   	while (scan.hasnext()){
   		flight[count] = readFlights(scan);
   		count++;
   	}
    }
}



AirlineSearch.java
package com.apress.jsf;

import java.util.List;
import java.util.ArrayList;

public class AirlineSearch{
	String origination;
	String destination;
	String departDate;
	String departTime;
	ArrayList matchingFlights = new ArrayList();

	public String getDepartDate(){
		return departDate;
	}

	public void setDepartDate(String departDate) {
		this.departDate = departDate;
		((Airline) matchingAirline.get(0)).setDepartDate(departDate);
		((Airline) matchingAirline.get(1)).setDepartDate(departDate);
	}

	public String getDepartTime(){
		return departTime;
	}

	public void setDepartTime(String departTime){
		this.departTime = departTime;
		((Airline) matchingAirline.get(0)).setDestination(destination);
		((Airline) matchingAirline.get(1)).setDestination(destination);
		((Airline) matchingAirline.get(0)).setFlightNum(flightNum);
		((Airline) matchingAirline.get(1)).setFlightNum(flightNum);
	}

	public String getOrigination(){
		return origination;
	}

	public void setOrigination(String origination){
    	this.origination = origination;
    	((Airline) matchingAirline.get(0)).setOrigination(origination);
    	((Airline) matchingAirline.get(1)).setOrigination(origination);
    }

    public List getMatchingFlights() {
    	return matchingFlights;
    }
    public void setMatchingFlights(List matchingFlights){
    	this.matchingFlights.addAll(matchingFlights);
    }
}



Any help and suggestions would be greatly appreciated i'm stuck. I have been researching sources but i'm having trouble in this subject in general.

Thanks

Attached File(s)



Is This A Good Question/Topic? 0
  • +

Replies To: Airline Reservations Assignment

#2 japanir  Icon User is offline

  • jaVanir
  • member icon

Reputation: 1011
  • View blog
  • Posts: 3,025
  • Joined: 20-August 09

Re: Airline Reservations Assignment

Posted 09 May 2010 - 03:04 PM

What exactly is the problem?
What do you mean by:

Quote

I have been researching sources but i'm having trouble in this subject in general.

what subject?
Was This Post Helpful? 0
  • +
  • -

#3 hottestchica2004  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 17
  • Joined: 11-October 09

Re: Airline Reservations Assignment

Posted 09 May 2010 - 03:12 PM

View Postjapanir, on 09 May 2010 - 02:04 PM, said:

What exactly is the problem?
What do you mean by:

Quote

I have been researching sources but i'm having trouble in this subject in general.

what subject?

Java 1 mainly the searching part.
Was This Post Helpful? 0
  • +
  • -

#4 japanir  Icon User is offline

  • jaVanir
  • member icon

Reputation: 1011
  • View blog
  • Posts: 3,025
  • Joined: 20-August 09

Re: Airline Reservations Assignment

Posted 09 May 2010 - 03:26 PM

first i suggest that you create a Flight class.
a flight class will have those members:
Flight number (integer), space, Origination point ( String[15]), space, Destination point (String[15]), space, Departure time (String[8]), and Departure date (String[8]).

you can pass this variables in the class constructor.
then when you read the file, create an array \ List of Flight objects (each new Flight will be added to that Coleection).
I would also suggest to implement Comparator interface 3 times. once to compare by Flight number, once to compare by destination and once by departure.

everytime you have to search, sort yor array\List by this comparator. That way it should be really easy to search.
here is some tutorial about comparator just in case:
API:
http://java.sun.com/...Comparator.html
Tutorial:
http://java.sun.com/...aces/order.html
Was This Post Helpful? 0
  • +
  • -

#5 hottestchica2004  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 17
  • Joined: 11-October 09

Re: Airline Reservations Assignment

Posted 09 May 2010 - 06:06 PM

awesome i'm gonna try that thanks.
Was This Post Helpful? 0
  • +
  • -

#6 macosxnerd101  Icon User is online

  • Self-Trained Economist
  • member icon




Reputation: 10814
  • View blog
  • Posts: 40,313
  • Joined: 27-December 08

Re: Airline Reservations Assignment

Posted 09 May 2010 - 06:07 PM

View Postjapanir, on 09 May 2010 - 06:26 PM, said:

I would also suggest to implement Comparator interface 3 times. once to compare by Flight number, once to compare by destination and once by departure.


How about creating a class to implement Comparator<E>, with an instance variable to represent the field to sort by. This way, you only need one Comparator object instead of 3.
Was This Post Helpful? 0
  • +
  • -

#7 Dogstopper  Icon User is offline

  • The Ninjaducky
  • member icon



Reputation: 2876
  • View blog
  • Posts: 11,051
  • Joined: 15-July 08

Re: Airline Reservations Assignment

Posted 09 May 2010 - 06:58 PM

Martyr2 has a good blog post on Comparators here:
http://www.dreaminco...are-to-compare/

Pg 10 - took a while.
Was This Post Helpful? 0
  • +
  • -

#8 hottestchica2004  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 17
  • Joined: 11-October 09

Re: Airline Reservations Assignment

Posted 09 May 2010 - 07:40 PM

Still having trouble:

Flight.java
/**
 * @(#)Flight.java
 *
 *
 * @author
 * @version 1.00 2010/5/9
 */
import java.util.ArrayList;
import java.util.Collections;
import java.util.*;
import java.awt.*;

public class Flight extends java.applet.Applet {
	public static void main(String[] args){

		//instantiate new ArrayList:
		FlightPlan flightplan = new FlightPlan(50);
		Scanner fscan = new Scanner(new File("airline.txt"));
		Scanner scan = new Scanner(System.in);

		//read in values:
		int count = 0;
   		while (scan.hasnext()){
   		flightPlan [count] = readFlights(scan);
   		count++;
   		}

   		//Sort the Array list:
   		Collections.sort(flightPlan);
   		System.out.println("Sorted FlightPlan contains: " + flightPlan);

		//User Input:
		System.out.println("Would you like to search by flight number or city name?"+
			" Please type in origin, destination, or flight to choose.");
		String option = scan.nextLine();
		}

		if (option.equalsIgnoreCase(flight)){

   		//Binary Search on Array:
   		int index = Collections.binarySearch(flightPlan, input);

   		//Output
   		System.out.println("The flight plan for flight number " + input + " is: "
   			+ flightPlan[index]);
		}
		else{
			if(option.equalsIgnoreCase(origination)){
				System.out.println("Please enter origin city: ");
				city = scan.nextLine();

				static final Comaprator<city>ORIGINATION_ORDER =
					new Comparator<city>(){
						public int compare(city, origination){
							return city.compareTo(origination);
							}
						}
				 //Origination database
				 static final Collection<city>;

				 List<city>c = new ArrayList,city>();
				 Collections.sort(c, ORIGINATION_ORDER);
				 System.out.println("Your search for " + city + " returned:")
				 System.out.println(c);
				}
		    	else{
					System.out.println("Please enter destination city: ");
					city = scan.nextLine();

					static final Comparator<city>DESTINATION_ORDER =
						new Comparator<city>(){
							public int compare(city, destination){
								return city.compareTo(destination);
							}

						}
						//Destination Database
						static final Collection<city>;

						List<city>c = new ArrayList<city>();
						Collections.sort(c, DESTINATION_ORDER);
						System.out.println("Your search for " + city + " returned:")
						System.out.println(c);
				}


		}



Airline.java
/**
 * @(#)Airline.java
 *
 *
 * Ami Soliz
 * @version 1.00 2010/5/9
 */

import java.awt.*;
package com.apress.jsf;

public class Airline extends java.applet.Applet {
    int flightNum;
    int count;
    String origination;
    String destination;
    String departDate;
    String departTime;
    final int ODPT = 15;
    final int DEPTDT = 8;

    //-----------------------------------------------------------
    //Constructor: Creates an empty record of flight information
    //-----------------------------------------------------------
    public void Airline(){
    	FlightPlan flightPlan = new FlightPlan (50);
    	counter = 0;
    }

    //-----------------------------------------------------------
    //						Add a Flight
    //-----------------------------------------------------------
    public void addFlight(int flightNum, String origination, String destination,
    						String departTime, String departDate){
    	int count = 0;
    	flightPlan[count] = new flightPlan(flightNum, origination, destination, departTime, departDate);
    	count++;
    }
    //-----------------------------------------------------------
    //						Read in Flights
    //-----------------------------------------------------------
    public void readFlights(Scanner scan){
    	int prt = 0;
    	fNum = scan.nextInt();
    	temp = scan.nextLine();
    	ptr++;
    	orig = temp.substring(ptr, ptr+ODPT);
    	system.out.println(origination);

    	ptr += ODPT+1;
    	dest = temp.substring(ptr, ptr+ODPT);
    	System.out.println(destination);

    	ptr += ODPT+1;
    	dTime = temp.substring(ptr, ptr+DEPTDT);
    	System.out.println(departTime);

    	ptr += DEPTDT+1;
    	dDate = temp.substring(ptr, endofstring);
    	System.out.println(departDate);
    }

    //---------------------------------------------------------
    //---------------------------------------------------------

    public int getFlightNum() {
    	return flightNum;
    }

    public void setFlightNum(int flightNum) {
    	this.flightNum = flightNum;
    }

    public String getDepartDate() {
    	return departDate;
    }

    public void setDepartDate(String departDate) {
    	this.departDate = departDate;
    }

    public String getDepartTime() {
    	return departTime;
    }

    public void setDepartTime(String departTime) {
    	this.departTime = departTime;
    }

    public String getDestination() {
    	return destination;
    }

    public void setDestination(String destination) {
    	this.destination = destination;
    }

    public String getOrigination() {
    	return origination;
    }
    public void setOrigination(String origination){
    	this.origination = origination;
    }

    //---------------------------------------------------------------------
    //---------------------------------------------------------------------

    public String toString() {
    	String report = "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n";
    	report += "Flight Plans\n";
    	report += "Number of Flights: " + count + "\n";
    	report += "\t Flight List: \n";

    	for (int x=0; x <count; x++)
    		report += records[x].toString() + "\n";

    	return report;
    }
}


Was This Post Helpful? 0
  • +
  • -

#9 macosxnerd101  Icon User is online

  • Self-Trained Economist
  • member icon




Reputation: 10814
  • View blog
  • Posts: 40,313
  • Joined: 27-December 08

Re: Airline Reservations Assignment

Posted 09 May 2010 - 07:43 PM

We can't help you if you don't tell us what your problems or errors are.
Was This Post Helpful? 0
  • +
  • -

#10 hottestchica2004  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 17
  • Joined: 11-October 09

Re: Airline Reservations Assignment

Posted 09 May 2010 - 07:46 PM

View Postmacosxnerd101, on 09 May 2010 - 06:43 PM, said:

We can't help you if you don't tell us what your problems or errors are.

Errors for Flight.java:
--------------------Configuration: <Default>--------------------
C:\Users\Admin\Documents\Flight.java:38: illegal start of type
if (option.equalsIgnoreCase(flight)){
^
C:\Users\Admin\Documents\Flight.java:38: <identifier> expected
if (option.equalsIgnoreCase(flight)){
^
C:\Users\Admin\Documents\Flight.java:38: ';' expected
if (option.equalsIgnoreCase(flight)){
^
C:\Users\Admin\Documents\Flight.java:38: illegal start of type
if (option.equalsIgnoreCase(flight)){
^
C:\Users\Admin\Documents\Flight.java:38: <identifier> expected
if (option.equalsIgnoreCase(flight)){
^
C:\Users\Admin\Documents\Flight.java:38: ';' expected
if (option.equalsIgnoreCase(flight)){
^
C:\Users\Admin\Documents\Flight.java:44: <identifier> expected
System.out.println("The flight plan for flight number " + input + " is: "
^
C:\Users\Admin\Documents\Flight.java:44: illegal start of type
System.out.println("The flight plan for flight number " + input + " is: "
^
C:\Users\Admin\Documents\Flight.java:44: ')' expected
System.out.println("The flight plan for flight number " + input + " is: "
^
C:\Users\Admin\Documents\Flight.java:44: ';' expected
System.out.println("The flight plan for flight number " + input + " is: "
^
C:\Users\Admin\Documents\Flight.java:44: illegal start of type
System.out.println("The flight plan for flight number " + input + " is: "
^
C:\Users\Admin\Documents\Flight.java:44: <identifier> expected
System.out.println("The flight plan for flight number " + input + " is: "
^
C:\Users\Admin\Documents\Flight.java:44: ';' expected
System.out.println("The flight plan for flight number " + input + " is: "
^
C:\Users\Admin\Documents\Flight.java:45: ']' expected
+ flightPlan[index]);
^
C:\Users\Admin\Documents\Flight.java:45: ';' expected
+ flightPlan[index]);
^
C:\Users\Admin\Documents\Flight.java:47: class, interface, or enum expected
else{
^
C:\Users\Admin\Documents\Flight.java:50: class, interface, or enum expected
city = scan.nextLine();
^
C:\Users\Admin\Documents\Flight.java:52: class, interface, or enum expected
static final Comaprator<city>ORIGINATION_ORDER =
^
C:\Users\Admin\Documents\Flight.java:54: class, interface, or enum expected
public int compare(city, origination){
^
C:\Users\Admin\Documents\Flight.java:56: class, interface, or enum expected
}
^
C:\Users\Admin\Documents\Flight.java:59: class, interface, or enum expected
static final Collection<city>;
^
C:\Users\Admin\Documents\Flight.java:61: class, interface, or enum expected
List<city>c = new ArrayList,city>();
^
C:\Users\Admin\Documents\Flight.java:62: class, interface, or enum expected
Collections.sort(c, ORIGINATION_ORDER);
^
C:\Users\Admin\Documents\Flight.java:63: class, interface, or enum expected
System.out.println("Your search for " + city + " returned:")
^
C:\Users\Admin\Documents\Flight.java:65: class, interface, or enum expected
}
^
C:\Users\Admin\Documents\Flight.java:68: class, interface, or enum expected
city = scan.nextLine();
^
C:\Users\Admin\Documents\Flight.java:70: class, interface, or enum expected
static final Comparator<city>DESTINATION_ORDER =
^
C:\Users\Admin\Documents\Flight.java:72: class, interface, or enum expected
public int compare(city, destination){
^
C:\Users\Admin\Documents\Flight.java:74: class, interface, or enum expected
}
^
C:\Users\Admin\Documents\Flight.java:78: class, interface, or enum expected
static final Collection<city>;
^
C:\Users\Admin\Documents\Flight.java:80: class, interface, or enum expected
List<city>c = new ArrayList<city>();
^
C:\Users\Admin\Documents\Flight.java:81: class, interface, or enum expected
Collections.sort(c, DESTINATION_ORDER);
^
C:\Users\Admin\Documents\Flight.java:82: class, interface, or enum expected
System.out.println("Your search for " + city + " returned:")
^
C:\Users\Admin\Documents\Flight.java:84: class, interface, or enum expected
}
^
34 errors

Process completed.

Errors with Airline.java:
<Default>--------------------
C:\Users\Admin\Documents\Airline.java:10: class, interface, or enum expected
package com.apress.jsf;
^
1 error

Process completed.
Was This Post Helpful? 0
  • +
  • -

#11 macosxnerd101  Icon User is online

  • Self-Trained Economist
  • member icon




Reputation: 10814
  • View blog
  • Posts: 40,313
  • Joined: 27-December 08

Re: Airline Reservations Assignment

Posted 09 May 2010 - 08:03 PM

Airline.java::
-You must package your File, then import any necesssary classes, then define your class.

Flight.java:
-You end your main() method prematurely, which is causing many of your errors. Most of your remaining errors are due to having code outside of your class definition. Check your braces to see which end brace ends which block of code. I have commented the end of your main() method to show you what is contained in it.
public static void main(String[] args){ 
 
                //instantiate new ArrayList: 
                FlightPlan flightplan = new FlightPlan(50); 
                Scanner fscan = new Scanner(new File("airline.txt")); 
                Scanner scan = new Scanner(System.in); 
 
                //read in values: 
                int count = 0; 
                while (scan.hasnext()){ 
                flightPlan [count] = readFlights(scan); 
                count++; 
                } 
 
                //Sort the Array list: 
                Collections.sort(flightPlan); 
                System.out.println("Sorted FlightPlan contains: " + flightPlan); 
 
                //User Input: 
                System.out.println("Would you like to search by flight number or city name?"+ 
                        " Please type in origin, destination, or flight to choose."); 
                String option = scan.nextLine(); 
        } //end main 


Was This Post Helpful? 0
  • +
  • -

#12 hottestchica2004  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 17
  • Joined: 11-October 09

Re: Airline Reservations Assignment

Posted 10 May 2010 - 01:03 AM

almost done just having trouble since i have no notes on a "serial search" and the book doesnt say anything about that particular one. The rest is error free just need help on how to do the city search part.
FlightPlan.java
import java.util.*;
import java.lang.*;
public class FlightPlan{
	private int count;
	public static int flightNum;
	public static String origin;
	public static String dest;
	public String dTime;
	public String dDate;

	//Create a new Flight Plan with the given attributes.
	public FlightPlan (int flightNumber, String origination, String destination,
				String departTime, String departDate){
					flightNum = flightNumber;
					origin = origination;
					dest = destination;
					dTime = departTime;
					dDate = departDate;
				}
	//Return a string with flight plan information
	public String toString(){
		return (flightNum + "\t" + origin + "\t" + dest + "\t" + dTime +
			"\t" + dDate);
	}

	//Returns flight number
	public static int getFlightNumber(){
		return flightNum;
	}

	public static String getOrigination(){
		return origin;
	}

	public static String getDestination(){
		return dest;
	}

	public String getDepartTime(){
		return dTime;
	}

	public String getDepartDate(){
		return dDate;
	}
}



Airline.java
/**
 * @(#)Airline.java
 *
 *
 * Ami Soliz
 * @version 1.00 2010/5/9
 */

import java.util.*;
import java.io.*;

public class Airline{
    static int flightNum;
    private int counter;
    static String origination;
    static String destination;
    String departDate;
    String departTime;
    final int ODPT = 15;
    final int DEPTDT = 8;

    //-----------------------------------------------------------
    //Constructor: Creates an empty record of flight information
    //-----------------------------------------------------------
    public static FlightPlan [] flight = new FlightPlan[50];
    public Airline(){
    	counter = 0;
    }

    //-----------------------------------------------------------
    //						Add a Flight
    //-----------------------------------------------------------
    public void addFlight(int flightNum, String origination, String destination,
    						String departTime, String departDate){

    	flight[counter] = new FlightPlan(flightNum, origination, destination, departTime, departDate);
    	counter++;
    }
    //-----------------------------------------------------------
    //						Read in Flights
    //-----------------------------------------------------------
    public void readFlights(Scanner fscan){
    	int fNum = fscan.nextInt();
    	String temp = fscan.nextLine();
    	String speech = temp;
		StringTokenizer st = new StringTokenizer(speech);
		String orig = st.nextToken();
		String dest = st.nextToken();
		String dTime  = st.nextToken();
		String dDate = st.nextToken();

		System.out.println("Flight Number:  " + fNum);
		System.out.println("Origination:   " + orig);
		System.out.println("Destination:        " + dest);
		System.out.println("Depart Time:       " + dTime);
		System.out.println("Depart Date:       " + dDate);

    }

    //---------------------------------------------------------
    //Returns the flight plans
    //---------------------------------------------------------
    public String toString() {
    	String report = "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n";
    	report += "Flight Plans\n";
    	report += "Number of Flights: " + counter + "\n";
    	report += "\t Flight List: \n";

    	for (int x = 0; x < counter; x++)
    		report += flight[x].toString() + "\n";

    	return report;
    }
}



Flight2.java
/**
 * @(#)Airline.java
 *
 *
 * @version 1.00 2010/5/9
 */

import java.util.*;
import java.io.*;

public class Airline{
    static int flightNum;
    private int counter;
    static String origination;
    static String destination;
    String departDate;
    String departTime;
    final int ODPT = 15;
    final int DEPTDT = 8;

    //-----------------------------------------------------------
    //Constructor: Creates an empty record of flight information
    //-----------------------------------------------------------
    public static FlightPlan [] flight = new FlightPlan[50];
    public Airline(){
    	counter = 0;
    }

    //-----------------------------------------------------------
    //						Add a Flight
    //-----------------------------------------------------------
    public void addFlight(int flightNum, String origination, String destination,
    						String departTime, String departDate){

    	flight[counter] = new FlightPlan(flightNum, origination, destination, departTime, departDate);
    	counter++;
    }
    //-----------------------------------------------------------
    //						Read in Flights
    //-----------------------------------------------------------
    public void readFlights(Scanner fscan){
    	int fNum = fscan.nextInt();
    	String temp = fscan.nextLine();
    	String speech = temp;
		StringTokenizer st = new StringTokenizer(speech);
		String orig = st.nextToken();
		String dest = st.nextToken();
		String dTime  = st.nextToken();
		String dDate = st.nextToken();

		System.out.println("Flight Number:  " + fNum);
		System.out.println("Origination:   " + orig);
		System.out.println("Destination:        " + dest);
		System.out.println("Depart Time:       " + dTime);
		System.out.println("Depart Date:       " + dDate);

    }

    //---------------------------------------------------------
    //Returns the flight plans
    //---------------------------------------------------------
    public String toString() {
    	String report = "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n";
    	report += "Flight Plans\n";
    	report += "Number of Flights: " + counter + "\n";
    	report += "\t Flight List: \n";

    	for (int x = 0; x < counter; x++)
    		report += flight[x].toString() + "\n";

    	return report;
    }
}


this last part has errors:
--------------------Configuration: <Default>--------------------
C:\Users\Admin\Documents\Flight2.java:48: ';' expected
Airline.compare(origination, city){
^
C:\Users\Admin\Documents\Flight2.java:51: illegal start of expression
}
^
C:\Users\Admin\Documents\Flight2.java:55: reached end of file while parsing
}
^
3 errors

Process completed.

oops i been up too long!
Flight2.java should look like this:
/**
 * @(#)Flight.java
 *
 *
 * @author
 * @version 1.00 2010/5/9
 */
import java.util.*;
import java.util.Arrays;
import java.awt.*;
import java.io.*;
import java.lang.*;

public class Flight2 extends Airline {
	public static void main(String[] args) throws IOException{

	String city;
	String option;

	Scanner scan = new Scanner (System.in);

   		//Sort the Array list:
   		Arrays.sort(flight);
   		System.out.println("Sorted FlightPlan contains: " + flight);

		//User Input:
		System.out.println("Would you like to search by flight number or city name?"+
			" Please type in origin, destination, or number to choose.");
		option = scan.nextLine();

		if (option.equalsIgnoreCase("number")){


   		System.out.print("Please enter the flight number: ");
   		int key = scan.nextInt();
   		int p;
           Arrays.sort(flight);
           p=Arrays.binarySearch(flight, key);
   			System.out.println("The flight plan for flight number " + key + " is: "
   			+ flight[p]);
		}


		else{
			ArrayList arrayList = new ArrayList(flight);
			System.out.println("Please enter the origin: ");
			city = scan.nextLine();
			Airline.compare(origination, city){
				if (origination == city)
					return
			}

			}
		}
}


Was This Post Helpful? 0
  • +
  • -

#13 japanir  Icon User is offline

  • jaVanir
  • member icon

Reputation: 1011
  • View blog
  • Posts: 3,025
  • Joined: 20-August 09

Re: Airline Reservations Assignment

Posted 10 May 2010 - 06:10 AM

I am not sure what you try to do here, (this is what causing the errors)
Airline.compare(origination, city){ 
               if (origination == city) 
                        return 
              } 

you miss ";" after the return statement, and you don't need the curly braces after the call to compare there.
I didn't see a static method named compare in Airline class.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1