Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package menu;
- import java.io.BufferedReader;
- import java.io.File;
- import java.io.FileNotFoundException;
- import java.io.FileReader;
- import java.io.IOException;
- import java.util.HashMap;
- import java.util.Map;
- import p2.util.Data;
- import p2.util.Hora;
- public class Main {
- public static Cruzeiro[] cruzeiros;
- public static Map<Integer, Porto> portos = new HashMap<Integer, Porto>();
- public static Map<Integer, Excursao> excursoes = new HashMap<Integer, Excursao>();
- /**
- * @param args
- */
- public static void main(String[] args) {
- readCruzeiros( );
- MenuAluguer aluguer = new MenuAluguer( 20, 100, 550, 500 );
- aluguer.menuPrincipal();
- }
- /** método que lê o ficheiro de texto com a informação dos cruzeiros
- */
- private static void readCruzeiros( ){
- System.out.println("Lendo Cruzeiros");
- String file = "cruzeiros.txt";
- File f=new File(file);
- try {
- FileReader freader=new FileReader(f);
- BufferedReader buffer=new BufferedReader(freader);
- String aLer=buffer.readLine();
- int numCruzeiros = Integer.parseInt(aLer);
- while(aLer!=null && !aLer.equals("")){
- if(aLer.startsWith("-")){
- aLer=buffer.readLine();
- String[] parte=aLer.split(" ");
- int idCruzeiro=Integer.parseInt(parte[0]);
- String nomeCruzeiro=parte[1];
- Data dataCruzeiro=new Data(parte[2]);
- int nCamarotes=Integer.parseInt(parte[3]);
- double precoCruzeiro=Double.parseDouble(parte[4]);
- int nEscalas=Integer.parseInt(parte[5]);
- Cruzeiro cruzeiro = new Cruzeiro(idCruzeiro, nomeCruzeiro, dataCruzeiro, nCamarotes, precoCruzeiro, nEscalas);
- cruzeiros = new Cruzeiro[numCruzeiros];
- cruzeiros[0] = cruzeiro;
- }else if(aLer.startsWith("V")){
- aLer = buffer.readLine();
- String[] parte=aLer.split(" ");
- String nomeExcursao = parte[0];
- double precoExcursao = Double.parseDouble(parte[1]);
- int nVagas = Integer.parseInt(parte[2]);
- Excursao excursao = new Excursao(nomeExcursao, precoExcursao, nVagas);
- System.out.println("Excursao Adicionado");
- excursoes.put(1, excursao);
- }else{
- aLer = buffer.readLine();
- String[] parte = aLer.split(" ");
- int dia=Integer.parseInt(parte[0]);
- String nomePorto=parte[1];
- Hora horaPartida=new Hora(parte[2]);
- Hora horaChegada=new Hora(parte[3]);
- int nExcursoes=Integer.parseInt(parte[4]);
- Porto porto = new Porto(dia, nomePorto, horaPartida, horaChegada, nExcursoes);
- System.out.println("Porto Adicionado" );
- portos.put(dia, porto);
- System.out.println("adicionei porto");
- }
- }
- } catch (FileNotFoundException e) {
- System.out.println("O ficheiro "+file+" não existe!" );
- e.printStackTrace();
- } catch (NumberFormatException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (IOException e) {
- System.out.println("Erro na escrita do ficheiro "+file);
- e.printStackTrace();
- }
- System.out.println("Cruzeiros lidos" );
- }
- public static Map<Integer, Cruzeiro> getCruzeiros() {
- return cruzeiros;
- }
- public static Map<Integer, Porto> getPortos() {
- return portos;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement