Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 11-07-2007, 05:36 AM
Member
 
Join Date: Jul 2007
Posts: 46
Rep Power: 0
adlb1300 is on a distinguished road
Default 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++){
            
        }
   }
 
}
Bookmark Post in Technorati
Reply With Quote
  #2 (permalink)  
Old 11-07-2007, 10:09 AM
Senior Member
 
Join Date: Jul 2007
Posts: 1,389
Rep Power: 3
hardwired is on a distinguished road
Default
Code:
import java.util.ArrayList;
import java.util.List;
import javax.swing.JOptionPane;
 
public class FlightTest {
    static List<Flight> flights = new ArrayList<Flight>();

    public static void main(String[] args) {
        boolean keepGoing = true;
        
        while(keepGoing == true) {
            String[] options = { "enter flight data", "find a flight" };
            String choice = (String)JOptionPane.showInputDialog(null,
                                  "What do you want to do?",
                                  "Input", JOptionPane.QUESTION_MESSAGE,
                                   null, options, options[0]);
            System.out.println("choice = " + choice);
            if(choice == null) { // null -> user canceled/dismissed dialog
                keepGoing = false;
                break;
            }
            if(choice.indexOf("enter") != -1) {
                receiveData();
            } else if(choice.indexOf("find") != -1) {
                search();
            }
        }
        System.exit(0);
    }

    private static void receiveData() {
        String name = JOptionPane.showInputDialog("Flight Info Input\n\n" +
                    "Please enter the name of the Airline of the new record.\n\n");

        String fltNumStr = JOptionPane.showInputDialog("Flight Info Input\n\n" +
                    "Please enter the flight number of the new record.\n\n");
        int flightNum = Integer.parseInt(fltNumStr);

        String origin = JOptionPane.showInputDialog("Flight Info Input\n\n" +
                    "Please enter the city of origin for the new record.\n\n");

        String dest = JOptionPane.showInputDialog("Flight Info Input\n\n" +
                    "Please enter the destination city for the new record.\n\n");
            
        flights.add(new Flight(name, origin, dest, flightNum));
    }

    private static void search() {
        //System.out.println("Number of flights = " + flights.size());
        String searchType = JOptionPane.showInputDialog("Would you like to " +
                               "complete a search by flight number (enter s)\n" +
                               "or a search by city of Destination (enter d)?\n\n");
        boolean found = false;

        if(searchType.equalsIgnoreCase("s")){
            String fltNumStr = JOptionPane.showInputDialog("Please enter the " +
                                     "flight number that you wish to search for:\n\n");
            int numSearch = Integer.parseInt(fltNumStr);
            for(int j = 0; j < flights.size(); j++) {
                Flight flight = flights.get(j);
                if(numSearch == flight.getFlightNumber()) {
                    System.out.println("Found flight with flightNmber " +
                                        numSearch + ":");
                    System.out.println(flight);
                    found = true;

                    break;
                }
            }
            if(!found)
                System.out.println("no joy");
        }
 
        if(searchType.equalsIgnoreCase("d")){
            String destSearch = JOptionPane.showInputDialog("Please enter the " +
                                "city of destination that you wish to search for:\n\n");
            for(int j = 0; j < flights.size(); j++) {
                Flight flight = flights.get(j);
                if(destSearch.equals(flight.getDestCity())) {
                    System.out.println("Found flight with destination " +
                                        destSearch + ":");
                    System.out.println(flight);
                    found = true;
                    break;
                }
            }
            if(!found)
                System.out.println("no joy");
        }
    }
}

class Flight {
    String airlineName;
    String originCity;
    String destinationCity;
    int flightNumber;
    
    public Flight(String name, String orig, String dest, int fltNum) {
        this.airlineName = name;
        this.originCity = orig;
        this.destinationCity = dest;
        this.flightNumber = fltNum;
    }

    public String getAirlineName() { return airlineName; }

    public String getOriginCity() { return originCity; }

    public String getDestCity() { return destinationCity; }

    public int getFlightNumber() { return flightNumber; }

    public String toString() {
        return "Flight[airlineName:"     + airlineName +
                     " originCity:"      + originCity +
                     " destinationCity:" + destinationCity +
                     " flightNumber:"    + flightNumber + "]";
    }
}
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 11-07-2007, 11:59 AM
Member
 
Join Date: Jul 2007
Posts: 46
Rep Power: 0
adlb1300 is on a distinguished road
Default
THanks Hardwired I was nowhere close. I ended up making it harder than it needed to be and than when trying to simplify got lost.I appreciate the help.
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 11-14-2007, 01:54 AM
Member
 
Join Date: Nov 2007
Posts: 2
Rep Power: 0
nitroxx is on a distinguished road
Default can someone pls help
Using methods, re-write the popular song "My Bonnie Lies Over the Ocean". There is more than one efficient way to answer this question. Check the web for the lyrics.
Bookmark Post in Technorati
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
need help with program im lost lifeturn JCreator 1 10-28-2008 07:09 PM
Lost my javadocs orchid Eclipse 3 04-30-2008 09:45 PM
A little lost with for loops and making a design LinxuS New To Java 5 01-22-2008 09:05 AM
help needed. dirtycash New To Java 3 12-03-2007 09:17 PM
Absolutely Lost Lehane_9 New To Java 2 12-03-2007 06:25 PM


All times are GMT +2. The time now is 03:51 AM.



VBulletin, Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2009, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org