Advertisement
Guest User

Untitled

a guest
Apr 20th, 2015
240
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.69 KB | None | 0 0
  1. import java.util.ArrayList;
  2. import java.util.Scanner;
  3. import java.io.*;
  4. public class DataManager {
  5.  
  6. public static void exportData(String filename, ArrayList<Passenger> passengers, ArrayList<Flight> flights) throws IOException
  7. {
  8. PrintStream exportText;
  9. exportText = new PrintStream(filename);
  10.  
  11. exportText.println("#flightCount " + flights.size());
  12. for(int i = 0; i < flights.size(); i++)
  13. {
  14. exportText.println("#newFlight");
  15. exportText.println(flights.get(i).getSourceAirport() + " , " + flights.get(i).getDestinationAirport() + " , " + flights.get(i).getTakeoffTime() + " , " + flights.get(i).getLandingTime());
  16. exportText.println(flights.get(i).getCapacity());
  17. }
  18. exportText.println("#passCount " + passengers.size());
  19. for(int i = 0; i < passengers.size(); i++)
  20. {
  21. exportText.println("#newPass");
  22. exportText.println(passengers.get(i).getFirstName() + " , " + passengers.get(i).getLastName());
  23. exportText.println(passengers.get(i).getAlerts().size());
  24. for(int j = 0; j < passengers.get(i).getAlerts().size(); j++)
  25. {
  26. exportText.println(passengers.get(i).getAlerts().get(j));
  27. }
  28.  
  29. exportText.println(passengers.get(i).getBookedFlights().size());
  30. for(int j = 0; j < passengers.get(i).getBookedFlights().size(); j++)
  31. {
  32. 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());
  33. }
  34. exportText.println(passengers.get(i).getStandbyFlights().size());
  35. for(int j = 0; j < passengers.get(i).getStandbyFlights().size(); j++)
  36. {
  37. 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());
  38. }
  39. }
  40.  
  41. }
  42.  
  43. public static ImportData importData(String filename) throws IOException
  44. {
  45. ArrayList passengers = new ArrayList<Passenger>();
  46. ArrayList flights = new ArrayList<Flight>();
  47. ImportData data = new ImportData(passengers, flights);
  48.  
  49.  
  50. Scanner scan = new Scanner(new File(filename));
  51. scan.next();
  52. int fSize = scan.nextInt();
  53. scan.nextLine();
  54. for(int i = 0; i < fSize; i++)
  55. {
  56. scan.nextLine();
  57. String[] newFlight = scan.nextLine().split(" , ");
  58. Flight thisFlight = new Flight(newFlight[0], newFlight[1], Integer.valueOf(newFlight[2]), Integer.valueOf(newFlight[3]), scan.nextInt());
  59. data.flights.add(thisFlight);
  60. scan.nextLine();
  61. }
  62.  
  63. scan.next();
  64. int pSize = scan.nextInt();
  65. scan.nextLine();
  66. for(int i = 0; i < pSize; i++)
  67. {
  68. scan.nextLine();
  69. String[] newPass = scan.nextLine().split(" , ");
  70. Passenger johnDoe = new Passenger(newPass[0], newPass[1]);
  71. int alertSize = scan.nextInt();
  72. scan.nextLine();
  73. for(int j = 0; j < alertSize; j++)
  74. {
  75. johnDoe.addAlert(scan.nextLine());
  76. }
  77. int bookedFlightSize = scan.nextInt();
  78. scan.nextLine();
  79. for(int j = 0; j < bookedFlightSize; j++)
  80. {
  81. String[] thisArray = scan.nextLine().split(" , ");
  82. // int thisFlightCapacity = 0;
  83.  
  84. // for(int k = 0; k < data.flights.size(); k++)
  85. // {
  86. // if(thisArray[0] == data.flights.get(i).getSourceAirport())
  87. // {
  88. // thisFlightCapacity = data.flights.get(i).getCapacity();
  89. //
  90. // }
  91. // }
  92.  
  93.  
  94. Flight currentLine = new Flight(thisArray[0], thisArray[1], Integer.valueOf(thisArray[2]), Integer.valueOf(thisArray[3]), 1);
  95. johnDoe.getBookedFlights().add(currentLine);
  96. }
  97. int SBFlightSize = scan.nextInt();
  98. scan.nextLine();
  99. for(int j = 0; j < SBFlightSize; j++)
  100. {
  101. String[] thisArray = scan.nextLine().split(" , ");
  102. // int thisFlightCapacity = 0;
  103. //
  104. // for(int k = 0; k < data.flights.size(); k++)
  105. // {
  106. // if(thisArray[0] == data.flights.get(i).getSourceAirport())
  107. // {
  108. // thisFlightCapacity = data.flights.get(i).getCapacity();
  109. //
  110. // }
  111. // }
  112. Flight currentLine = new Flight(thisArray[0], thisArray[1], Integer.valueOf(thisArray[2]), Integer.valueOf(thisArray[3]), 1);
  113. johnDoe.getStandbyFlights().add(currentLine);
  114. }
  115. data.passengers.add(johnDoe);
  116. }
  117. return data;
  118. }
  119.  
  120. public static void main(String[] args) throws IOException
  121. {
  122. importData("ProjStage3BasicFile.txt");
  123.  
  124. }
  125. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement