Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.ArrayList;
- import java.util.Scanner;
- import java.io.*;
- public class DataManager {
- public static void exportData(String filename, ArrayList<Passenger> passengers, ArrayList<Flight> flights) throws IOException
- {
- PrintStream exportText;
- exportText = new PrintStream(filename);
- exportText.println("#flightCount " + flights.size());
- for(int i = 0; i < flights.size(); i++)
- {
- exportText.println("#newFlight");
- exportText.println(flights.get(i).getSourceAirport() + " , " + flights.get(i).getDestinationAirport() + " , " + flights.get(i).getTakeoffTime() + " , " + flights.get(i).getLandingTime());
- exportText.println(flights.get(i).getCapacity());
- }
- exportText.println("#passCount " + passengers.size());
- for(int i = 0; i < passengers.size(); i++)
- {
- exportText.println("#newPass");
- exportText.println(passengers.get(i).getFirstName() + " , " + passengers.get(i).getLastName());
- exportText.println(passengers.get(i).getAlerts().size());
- for(int j = 0; j < passengers.get(i).getAlerts().size(); j++)
- {
- exportText.println(passengers.get(i).getAlerts().get(j));
- }
- exportText.println(passengers.get(i).getBookedFlights().size());
- for(int j = 0; j < passengers.get(i).getBookedFlights().size(); j++)
- {
- exportText.println(passengers.get(i).getBookedFlights().get(j).getSourceAirport() + " , " + passengers.get(i).getBookedFlights().get(j).getDestinationAirport() + " , " + passengers.get(i).getBookedFlights().get(j).getTakeoffTime() + " , " + passengers.get(i).getBookedFlights().get(j).getLandingTime());
- }
- exportText.println(passengers.get(i).getStandbyFlights().size());
- for(int j = 0; j < passengers.get(i).getStandbyFlights().size(); j++)
- {
- exportText.println(passengers.get(i).getStandbyFlights().get(j).getSourceAirport() + " , " + passengers.get(i).getStandbyFlights().get(j).getDestinationAirport() + " , " + passengers.get(i).getStandbyFlights().get(j).getTakeoffTime() + " , " + passengers.get(i).getStandbyFlights().get(j).getLandingTime());
- }
- }
- }
- public static ImportData importData(String filename) throws IOException
- {
- ArrayList passengers = new ArrayList<Passenger>();
- ArrayList flights = new ArrayList<Flight>();
- ImportData data = new ImportData(passengers, flights);
- Scanner scan = new Scanner(new File(filename));
- scan.next();
- int fSize = scan.nextInt();
- scan.nextLine();
- for(int i = 0; i < fSize; i++)
- {
- scan.nextLine();
- String[] newFlight = scan.nextLine().split(" , ");
- Flight thisFlight = new Flight(newFlight[0], newFlight[1], Integer.valueOf(newFlight[2]), Integer.valueOf(newFlight[3]), scan.nextInt());
- data.flights.add(thisFlight);
- scan.nextLine();
- }
- scan.next();
- int pSize = scan.nextInt();
- scan.nextLine();
- for(int i = 0; i < pSize; i++)
- {
- scan.nextLine();
- String[] newPass = scan.nextLine().split(" , ");
- Passenger johnDoe = new Passenger(newPass[0], newPass[1]);
- int alertSize = scan.nextInt();
- scan.nextLine();
- for(int j = 0; j < alertSize; j++)
- {
- johnDoe.addAlert(scan.nextLine());
- }
- int bookedFlightSize = scan.nextInt();
- scan.nextLine();
- for(int j = 0; j < bookedFlightSize; j++)
- {
- String[] thisArray = scan.nextLine().split(" , ");
- // int thisFlightCapacity = 0;
- // for(int k = 0; k < data.flights.size(); k++)
- // {
- // if(thisArray[0] == data.flights.get(i).getSourceAirport())
- // {
- // thisFlightCapacity = data.flights.get(i).getCapacity();
- //
- // }
- // }
- Flight currentLine = new Flight(thisArray[0], thisArray[1], Integer.valueOf(thisArray[2]), Integer.valueOf(thisArray[3]), 1);
- johnDoe.getBookedFlights().add(currentLine);
- }
- int SBFlightSize = scan.nextInt();
- scan.nextLine();
- for(int j = 0; j < SBFlightSize; j++)
- {
- String[] thisArray = scan.nextLine().split(" , ");
- // int thisFlightCapacity = 0;
- //
- // for(int k = 0; k < data.flights.size(); k++)
- // {
- // if(thisArray[0] == data.flights.get(i).getSourceAirport())
- // {
- // thisFlightCapacity = data.flights.get(i).getCapacity();
- //
- // }
- // }
- Flight currentLine = new Flight(thisArray[0], thisArray[1], Integer.valueOf(thisArray[2]), Integer.valueOf(thisArray[3]), 1);
- johnDoe.getStandbyFlights().add(currentLine);
- }
- data.passengers.add(johnDoe);
- }
- return data;
- }
- public static void main(String[] args) throws IOException
- {
- importData("ProjStage3BasicFile.txt");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement