Advertisement
Guest User

Untitled

a guest
Nov 24th, 2014
166
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.30 KB | None | 0 0
  1. package menu;
  2.  
  3. import java.io.BufferedReader;
  4. import java.io.File;
  5. import java.io.FileNotFoundException;
  6. import java.io.FileReader;
  7. import java.io.IOException;
  8. import java.util.HashMap;
  9. import java.util.Map;
  10.  
  11. import p2.util.Data;
  12. import p2.util.Hora;
  13.  
  14. public class Main {
  15.  
  16.  
  17. public static Cruzeiro[] cruzeiros;
  18. public static Map<Integer, Porto> portos = new HashMap<Integer, Porto>();
  19. public static Map<Integer, Excursao> excursoes = new HashMap<Integer, Excursao>();
  20.  
  21. /**
  22. * @param args
  23. */
  24. public static void main(String[] args) {
  25. readCruzeiros( );
  26.  
  27. MenuAluguer aluguer = new MenuAluguer( 20, 100, 550, 500 );
  28. aluguer.menuPrincipal();
  29. }
  30.  
  31. /** método que lê o ficheiro de texto com a informação dos cruzeiros
  32. */
  33. private static void readCruzeiros( ){
  34.  
  35. System.out.println("Lendo Cruzeiros");
  36.  
  37. String file = "cruzeiros.txt";
  38. File f=new File(file);
  39. try {
  40. FileReader freader=new FileReader(f);
  41.  
  42. BufferedReader buffer=new BufferedReader(freader);
  43.  
  44.  
  45.  
  46. String aLer=buffer.readLine();
  47. int numCruzeiros = Integer.parseInt(aLer);
  48.  
  49. while(aLer!=null && !aLer.equals("")){
  50.  
  51. if(aLer.startsWith("-")){
  52. aLer=buffer.readLine();
  53. String[] parte=aLer.split(" ");
  54.  
  55. int idCruzeiro=Integer.parseInt(parte[0]);
  56.  
  57. String nomeCruzeiro=parte[1];
  58.  
  59. Data dataCruzeiro=new Data(parte[2]);
  60.  
  61. int nCamarotes=Integer.parseInt(parte[3]);
  62.  
  63. double precoCruzeiro=Double.parseDouble(parte[4]);
  64.  
  65. int nEscalas=Integer.parseInt(parte[5]);
  66.  
  67. Cruzeiro cruzeiro = new Cruzeiro(idCruzeiro, nomeCruzeiro, dataCruzeiro, nCamarotes, precoCruzeiro, nEscalas);
  68.  
  69. cruzeiros = new Cruzeiro[numCruzeiros];
  70. cruzeiros[0] = cruzeiro;
  71.  
  72. }else if(aLer.startsWith("V")){
  73.  
  74. aLer = buffer.readLine();
  75. String[] parte=aLer.split(" ");
  76.  
  77. String nomeExcursao = parte[0];
  78.  
  79. double precoExcursao = Double.parseDouble(parte[1]);
  80.  
  81. int nVagas = Integer.parseInt(parte[2]);
  82. Excursao excursao = new Excursao(nomeExcursao, precoExcursao, nVagas);
  83. System.out.println("Excursao Adicionado");
  84. excursoes.put(1, excursao);
  85.  
  86. }else{
  87.  
  88. aLer = buffer.readLine();
  89. String[] parte = aLer.split(" ");
  90.  
  91. int dia=Integer.parseInt(parte[0]);
  92.  
  93. String nomePorto=parte[1];
  94.  
  95. Hora horaPartida=new Hora(parte[2]);
  96.  
  97. Hora horaChegada=new Hora(parte[3]);
  98.  
  99. int nExcursoes=Integer.parseInt(parte[4]);
  100.  
  101. Porto porto = new Porto(dia, nomePorto, horaPartida, horaChegada, nExcursoes);
  102. System.out.println("Porto Adicionado" );
  103. portos.put(dia, porto);
  104. System.out.println("adicionei porto");
  105. }
  106. }
  107. } catch (FileNotFoundException e) {
  108. System.out.println("O ficheiro "+file+" não existe!" );
  109. e.printStackTrace();
  110. } catch (NumberFormatException e) {
  111. // TODO Auto-generated catch block
  112. e.printStackTrace();
  113. } catch (IOException e) {
  114. System.out.println("Erro na escrita do ficheiro "+file);
  115. e.printStackTrace();
  116. }
  117.  
  118. System.out.println("Cruzeiros lidos" );
  119. }
  120.  
  121. public static Map<Integer, Cruzeiro> getCruzeiros() {
  122. return cruzeiros;
  123. }
  124.  
  125. public static Map<Integer, Porto> getPortos() {
  126. return portos;
  127. }
  128.  
  129.  
  130. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement