/* Projeto de MC726 * Representaçao de encomendas no sistema de planejamento de transportes */ /* Alunos : Alexandre Luti Telles (980575), * Alexandre Takayama (980583), * Andre Duarte Veras (980645), * Reinaldo Yoshio Simizu(981993), * Junior S. Predes (981458), */ /**--------------------------------------------------- * Classe: Encomendas * Descriçao: Classe que descreve as encomendas *---------------------------------------------------- */ package pckDemanda; import java.util.*; import java.io.FileReader; import java.io.*; import pckMapa.*; public class EncomendaImpl extends Encomenda { /** * Atributos */ private int encomendaID; private String nome; private float volume; private Trecho origem; private Trecho destino; private double tempoCarga; private double tempoDescarga; private double horaOrigem; private double horaDestino; /** * CONSTRUTORES */ /** * Cria uma encomenda vazia (sem dados) */ /* Alunos : * Reinaldo Yoshio Simizu(981993), * Junior S. Predes (981458), */ public EncomendaImpl (){ volume = 0; origem = null; destino = null; tempoCarga = 0; tempoDescarga = 0; horaOrigem = 0; horaDestino = 0; nome=new String("vazio"); encomendaID=0; } /* Alunos : * Alexandre Takayama (980583), * Andre Duarte Veras (980645), */ public EncomendaImpl (float vol, Trecho ori, Trecho dest, double tCarga, double tDescarga, double hOrigem, double hDestino ){ volume = vol; origem = ori; destino = dest; tempoCarga = tCarga; tempoDescarga = tDescarga; horaOrigem = hOrigem; horaDestino = hDestino; } /* Alunos : Alexandre Luti Telles (980575), * Reinaldo Yoshio Simizu(981993), */ public EncomendaImpl (int id, String nom, float vol, Trecho ori, Trecho dest, double tCarga, double tDescarga, double hOrigem, double hDestino ) { nome=nom; encomendaID=id; volume = vol; origem = ori; destino = dest; tempoCarga = tCarga; tempoDescarga = tDescarga; horaOrigem = hOrigem; horaDestino = hDestino; } /*Metodo transforma um objeto encomenda em uma string. Alunos : * Andre Duarte Veras (980645), * Junior S. Predes (981458), */ public String toString(){ StringBuffer temp=new StringBuffer(); temp.append( encomendaID);temp.append(" "); temp.append( nome);temp.append(" "); temp.append( volume);temp.append(" "); temp.append( origem.id());temp.append(" "); temp.append( destino.id());temp.append(" "); temp.append( tempoCarga);temp.append(" "); temp.append( tempoDescarga);temp.append(" "); temp.append( horaOrigem);temp.append(" "); temp.append( horaDestino);temp.append(" "); return temp.toString(); } /** * Retorna o ID da encomenda * Alexandre Takayama (980583), */ public int getEncomendaID(){ return encomendaID; } /** * Retorna o nome da encomenda * Alexandre Takayama (980583), */ public String getNome(){ return nome; } /** * Retorna o volume da encomenda * Alexandre Takayama (980583), */ public float getVolume(){ return volume; } /** * Retorna a origem da encomenda * Alexandre Takayama (980583), */ public Trecho getOrigem(){ return origem; } /** * Retorna o destino da encomenda */ //aluno: Alexandre Luti Telles (980575), public Trecho getDestino(){ return destino; } /** * Retorna o tempo de carga da encomenda */ //aluno: Alexandre Luti Telles (980575), public double getTempoCarga(){ return tempoCarga; } /** * Retorna o tempo de descarga da encomenda */ //aluno: Alexandre Luti Telles (980575), public double getTempoDescarga(){ return tempoDescarga; } /** * Retorna a hora da origem */ //aluno: Alexandre Luti Telles (980575), public double getHoraOrigem(){ return horaOrigem; } /** * Retorna a hora da destino */ //aluno: Alexandre Luti Telles (980575), public double getHoraDestino(){ return horaDestino; } /** * METODOS SET */ /** * Atribui o id da encomenda */ //aluno: Alexandre Luti Telles (980575), public void setID(int id){ this.encomendaID = id; } /** * Atribui o nome a encomenda */ //aluno: Alexandre Luti Telles (980575), public void setNome(String nome){ this.nome = nome; } /** * Atribui o volume a encomenda */ //aluno: Alexandre Luti Telles (980575), public void setVolume (float vol){ this.volume= vol; } /** * Atribui a origem a encomenda */ //aluno: *Junior S. Predes (981458) public void setOrigem (Trecho trecho){ this.origem = trecho; } /** * Atribui o destino a encomenda */ //aluno: *Junior S. Predes (981458) public void setDestino (Trecho trecho){ this.destino = trecho; } /** * Atribui o tempo de carga a encomenda */ // * Aluno: Reinaldo Yoshio Simizu(981993), public void setTempoCarga (double tempo){ this.tempoCarga = tempo; } /** * Atribui o tempo de descarga a encomenda */ // * Aluno: Reinaldo Yoshio Simizu(981993), public void setTempoDescarga (double tempo){ this.tempoDescarga = tempo; } /** * Atribui a hora de origem a encomenda */ // * Aluno: Reinaldo Yoshio Simizu(981993), public void setHoraOrigem (double data){ this.horaOrigem = data; } /** * Atribui a hora de destino a encomenda */ //* Andre Duarte Veras (980645), public void setHoraDestino (double data){ this.horaDestino = data; } /** * Leitura de uma encomenda a partir do arquivo */ /* antiga public Encomenda LeArquivo(FileReader inputFile) { BufferedReader leitor = new BufferedReader(inputFile); EncomendaImpl enc = new EncomendaImpl(); try{ String linha = leitor.readLine(); System.out.println(linha); StringTokenizer atributo = new StringTokenizer(linha,";"); System.out.println("criou tolkenizer"); //System.out.println("Primeiro tolken"+atributo.nextToken()); enc.setID(Integer.parseInt(atributo.nextToken())); enc.setNome(atributo.nextToken()); enc.setVolume(Float.parseFloat(atributo.nextToken())); //ans duas linhas abaixo vamos precisar do construtor de trecho que recebe o id e cria o objeto enc.setOrigem(new TrechoImpl(Integer.parseInt(atributo.nextToken()))); //(Trecho trecho); enc.setDestino(new TrechoImpl(Integer.parseInt(atributo.nextToken())));//(Trecho trecho); enc.setTempoCarga(Double.parseDouble(atributo.nextToken())); enc.setTempoDescarga (Double.parseDouble(atributo.nextToken())); enc.setHoraOrigem (ConverteData(atributo.nextToken())); //(Date data); enc.setHoraDestino (ConverteData(atributo.nextToken())); //(Date data); } catch(Exception e){ System.out.println("Deu pau no metodo de le do arquivo: "+e.toString()); }; return enc; } /* /** * Leitura de uma encomenda a partir do arquivo * novo com o novo requisito de passar um streamTokenizer */ /*Alunos * Andre Duarte Veras (980645), * Junior S. Predes (981458), */ public Encomenda LeArquivo(StreamTokenizer tok) { EncomendaImpl enc = new EncomendaImpl(); try{ System.out.println("criou tolkenizer"); tok.nextToken(); enc.setID(Integer.parseInt(tok.nval())); tok.nextToken(); enc.setNome(tok.sval()); tok.nextToken(); enc.setVolume(Float.parseFloat(tok.nval())); tok.nextToken(); //ans duas linhas abaixo vamos precisar do construtor de trecho que recebe o id e cria o objeto Trecho t = new Trecho(); t.setid(Integer.parseInt(tok.nval())); enc.setOrigem(t); //(Trecho trecho); tok.nextToken(); Trecho t = new Trecho(); t.setid(Integer.parseInt(tok.nval())); enc.setDestino(t);//(Trecho trecho); tok.nextToken(); enc.setTempoCarga(Double.parseDouble(tok.nval())); tok.nextToken(); enc.setTempoDescarga (Double.parseDouble(tok.nval())); tok.nextToken(); enc.setHoraOrigem (ConverteData(tok.sval())); //(Date data); tok.nextToken(); enc.setHoraDestino (ConverteData(tok.sval())); //(Date data); } catch(Exception e){ System.out.println("Deu pau no metodo de le do arquivo: "+e.toString()); }; return enc; } /* Alunos : Alexandre Luti Telles (980575), * Alexandre Takayama (980583), */ static double ConverteData (String data){ double hora, minuto, segundo, soma; hora = Integer.parseInt(data.substring(0, 2)); minuto = Integer.parseInt(data.substring(3, 5)); segundo = Integer.parseInt(data.substring(6)); soma = (hora*3600)+(minuto*60)+segundo; return soma; } /* public static void main(String args[]){ Encomenda e; FileReader fr; StreamTokenizer tok; e=new EncomendaImpl(); try{ fr=new FileReader("arquivoEncomendas.txt"); e=e.LeArquivo(fr); System.out.println("ToString: "+e.toString()); }catch(Exception err){ System.out.println("deu pau!!!!!!!!: "+err.toString()); } } */ }