View Single Post
  #1 (permalink)  
Old 11-07-2007, 07:36 AM
adlb1300 adlb1300 is offline
Member
 
Join Date: Jul 2007
Posts: 46
adlb1300 is on a distinguished road
Help Needed - I'm so lost
I have a project that is due in a few hours that involves creating a flight class to handle flight data provided by the user. The user is requested to supply airline name, flight number, city of origin and city of destination. I'm compiling the data in ArrayLists. Once the user is done entering data the data is being passed to a new instance of the flight class. I than have to instantiate the variables in the constructor and within the flight class use get and set methods to search either by flight number or city of destination. The program should than use a toString to output a list of all matching flights to the user. I have must of it written but cannot seem to figure out how to pass the data to the flight class, search for each matching item and output the results of the search. Any help would be greatly appreciated.

Thanks in advance and here is the code that I have so far:

Code:
import java.util.ArrayList; import javax.swing.JOptionPane; public class FlightGUI { ArrayList<String> airlineNames = new ArrayList<String>(); ArrayList<String> flightNums = new ArrayList<String>(); ArrayList<String> originCities = new ArrayList<String>(); ArrayList<String> destinationCities = new ArrayList<String>(); public static void main(String[] args) { ArrayList<String> airlineNames = new ArrayList<String>(); ArrayList<String> flightNums = new ArrayList<String>(); ArrayList<String> originCities = new ArrayList<String>(); ArrayList<String> destinationCities = new ArrayList<String>(); boolean keepGoing = true; String inputtedAirlineName = ""; int flightCount = 0; while(keepGoing == true){ inputtedAirlineName = JOptionPane.showInputDialog("Flight Info Input\n\n" + "Please enter the name of the Airline of the new record.\n" + "Please enter the phrase search to begin searching flights\n\n"); String inputtedFlightNum = JOptionPane.showInputDialog("Flight Info Input\n\n" + "Please enter the flight number of the new record.\n\n"); String inputtedOriginCity = JOptionPane.showInputDialog("Flight Info Input\n\n" + "Please enter the city of origin for the new record.\n\n"); String inputtedDestinationCity = JOptionPane.showInputDialog("Flight Info Input\n\n" + "Please enter the destination city for the new record.\n\n"); airlineNames.add(inputtedAirlineName); flightNums.add(inputtedFlightNum); originCities.add(inputtedOriginCity); destinationCities.add(inputtedDestinationCity); flightCount++; String askForMore = JOptionPane.showInputDialog("Flight Info Input\n\n" + "Do you wish to enter more flights? (Y/N)\n\n"); if(askForMore.equalsIgnoreCase("n")){ keepGoing = false; Flight flight = new Flight(airlineNames, flightNums, originCities, destinationCities, flightCount); String searchType = JOptionPane.showInputDialog("Would you like to complete a search by flight number (enter f)\n" + "or a search by city of Destination (enter d)?\n" + "Enter x to exit program\n\n"); if(searchType.equalsIgnoreCase("s")){ String flightSearch = JOptionPane.showInputDialog("Please enter the flight number that you wish to search for:\n\n"); flight = Flight.searchFlightNums(flightSearch); } if(searchType.equalsIgnoreCase("d")){ String destinationSearch = JOptionPane.showInputDialog("Please enter the city of destination that you wish to search for:\n\n"); } if(searchType.equalsIgnoreCase("x")){ break; } } } // end while } // end main } // end FlightGUI
Code:
import java.util.ArrayList; public class Flight { ArrayList<String> airlineName = new ArrayList<String>(); ArrayList<String> flightNum = new ArrayList<String>(); ArrayList<String> originCity = new ArrayList<String>(); ArrayList<String> destinationCity = new ArrayList<String>(); private static int numFlights; public Flight(ArrayList<String> a, ArrayList<String> fn, ArrayList<String> oc, ArrayList<String> dc, int flightCount){ this.numFlights = flightCount; this.airlineName.addAll(a); this.flightNum.addAll(fn); this.originCity.addAll(oc); this.destinationCity.addAll(dc); } // end constructor public String searchFlightNums(String flightSearch) { for(int i = 0; i < flightNum.length; i++){ } } }
Reply With Quote
Sponsored Links