Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- John Long
- -Checks for a valid date
- */
- public static boolean isValidDate(String userInput)
- {
- String dateElements[];
- int ddInt, mmInt, yyInt;
- int[] daysArray = {31,28,31,30,31,30,31,31,30,31,30,31};
- boolean dateIsValid = true;
- dateElements = userInput.split("/");
- ddInt = Integer.parseInt(dateElements[0]);
- mmInt = Integer.parseInt(dateElements[1]);
- yyInt = Integer.parseInt(dateElements[2]);
- if((ddInt == 0) || (mmInt == 0) || (yyInt == 0))
- dateIsValid = false;
- else if(mmInt > 12)
- dateIsValid = false;
- else if((ddInt == 29) && (mmInt == 2) && ((((yyInt % 4 == 0) && (yyInt % 100 != 0)) || (yyInt % 400 = 0))))
- dateIsValid = true;
- else if(ddInt > daysArray[mmInt - 1])
- dateIsValid = false;
- return dateIsValid;
- }
- /*
- John Long
- -This method searches for flights by departing airport and destination airport and prints the details of all
- relevant flights
- -It takes 2 arguments, the source and destination airports as Strings
- -It returns void
- */
- public static void searchFlightsSF(String source, String destination)
- {
- String aSource = "";
- String aDestination = "";
- int matches = 0;
- aSource = getAirportCode(source);
- aDestination = getAirportCode(destination);
- for(int i=0; i<flights.get(0).size(); i++)
- {
- if(aSource.equalsIgnoreCase(flights.get(1).get(i)) && aDestination.equalsIgnoreCase(flights.get(2).get(i)))
- {
- // Display flight details
- for(int j=0; j<8; j++)
- {
- System.out.print(flights.get(j).get(i));
- }
- System.out.println("");
- matches++;
- }
- }
- if (matches == 0)
- displayMessage(10);
- }
- /*
- John Long
- -This method searches for flights by departing airport, destination airport and departure date and prints the details of all
- relevant flights
- -It takes 3 arguments, the source and destination airports as Strings and the departure date as a String
- -It returns void
- */
- public static void searchFlightsSD(String source, String destination, String date) throws ParseException
- {
- String aSource = "";
- String aDestination = "";
- int matches = 0;
- SimpleDateFormat sdf = new SimpleDateFormat("dd/mm/yyyy");
- Date date1 = sdf.parse(date);
- aSource = getAirportCode(source);
- aDestination = getAirportCode(destination);
- boolean display1;
- boolean display2;
- for(int i=0; i<flights.get(0).size(); i++)
- {
- Date date2 = sdf.parse(flights.get(6).get(i));
- display1 = false;
- display2 = false;
- if(aSource.equalsIgnoreCase(flights.get(1).get(i)) && aDestination.equalsIgnoreCase(flights.get(2).get(i)))
- {
- display1 = true;
- }
- if(date1.equals(date2))
- display2 = true;
- if(display1 == true && display2 == true)
- {
- // Display flight details
- for(int j=0; j<8; j++)
- {
- System.out.print(flights.get(j).get(i));
- }
- System.out.println("");
- matches++;
- }
- }
- if(matches==0)
- displayMessage(10);
- }
- /*
- John Long
- -This method gets the airport code for a particular airport name
- -It returns a String and takes 1 parameter, a String which is the name of the airport
- */
- public static String getAirportCode(String name)
- {
- boolean found = false;
- String airportCode = "";
- for(int i = 0; i<airports.get(0).size() && !found; i++)
- {
- if(name.equalsIgnoreCase(airports.get(0).get(i)))
- {
- airportCode = airports.get(0).get(i);
- found = true;
- }
- }
- return airportCode;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement