⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 n2006131015_lerficheiros.java

📁 Its a project that i create. The program its like an helpdesk, that allows the user to introduce re
💻 JAVA
字号:
/**
*
*@author Diogo Mestre 2006131015
*
*/

import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.StringTokenizer;


public class n2006131015_LerFicheiros {

	n2006131015_LerFicheiros(){
	}

	FicheiroDeObjectos fo = new FicheiroDeObjectos();
	FicheiroDeTexto ft = new FicheiroDeTexto();
	ArrayList array[]={null,null},postoTrabalhoTemp,utilizadorTemp,tecnicoTemp ;

	//------------- LER OS FICHEIROS -------------
	/**
	 * Le o ficheiro Pedidos.txt e coloca o seu conteudo nas Arraylists sistema e formacao.
	 * 
	 * @param sistema ArrayList com os pedidos de sistema
	 * @param formacao ArrayList com os pedidos de formacao
	 * 
	 */
	public void lerPedidos(ArrayList<n2006131015_Sistema> sistema, ArrayList<n2006131015_Formacao> formacao){
		String temp,descricao = null,tema=null;
		int numU=0,numP=0,numPT=0,dia=0,mes=0,ano=0,coloca=0,entra=0; 

		try{
			ft.abreLeitura("Pedidos.txt");
			while ((temp=ft.lerLinha())!=null){
				StringTokenizer st=new StringTokenizer(temp);
				while (st.hasMoreTokens()){
					String temp2 = st.nextToken();
					if(temp2.equals("terminou")){
						entra=1;
					}
					if(temp2.equals("Pedido:")){  
						numP= Integer.parseInt(st.nextToken());
					}
					if(temp2.equals("Utilizador:")){  
						numU= Integer.parseInt(st.nextToken());
					}
					if(temp2.equals("Data:")){
						StringTokenizer st2=new StringTokenizer(st.nextToken());
						while (st2.hasMoreTokens()){
							dia = Integer.parseInt(st2.nextToken("/"));
							mes = Integer.parseInt(st2.nextToken("/"));
							ano = Integer.parseInt(st2.nextToken("/"));
						}
					}
					//Caso seja um pedido de sistema
					if(entra==0){
						if(temp2.equals("Trabalho:")){   
							numPT= Integer.parseInt(st.nextToken());
						}
						if(temp2.equals("Descri玢o:")){  
							descricao=null;
							while (st.hasMoreTokens()){
								if(descricao==null){
									descricao=st.nextToken();
								}
								else{
									descricao= descricao+" "+st.nextToken();
								}
							}
							coloca=1;
						}
						if (coloca==1){
							sistema.add(new n2006131015_Sistema (numP,numU,numPT,descricao));
							//Poe o dia, mes e ano que estavam no ficheiro no Arraylist
							Iterator<n2006131015_Sistema> i = sistema.iterator();
							while (i.hasNext()) {
								n2006131015_Pedido_Assitencia P = (n2006131015_Pedido_Assitencia) i.next();
								if(P.getNumPedido()==numP){
									P.setDia(dia);
									P.setMes(mes);
									P.setAno(ano);
								}
							}
							coloca=0;
						}
					}
					//Caso seja um pedido de formacao
					if (entra==1){
						if(temp2.equals("Tema:")){ 
							tema=null;
							while (st.hasMoreTokens()){
								if(tema==null){
									tema=st.nextToken();
								}
								else{
									tema= tema+" "+st.nextToken();
								}
							}
							coloca=1;
						}
						if (coloca==1){
							formacao.add(new n2006131015_Formacao (numP,numU,tema));
							//Poe o dia, mes e ano que estavam no ficheiro no Arraylist
							Iterator<n2006131015_Formacao> i = formacao.iterator();
							while (i.hasNext()) {
								n2006131015_Pedido_Assitencia P = (n2006131015_Pedido_Assitencia) i.next();
								if(P.getNumPedido()==numP){
									P.setDia(dia);
									P.setMes(mes);
									P.setAno(ano);
								}
							}
							coloca=0;
						}
					}

				}
			}
			ft.fechaLeitura();
			System.out.println("Pedidos.txt carregado com sucesso.");
		}

		// Trata excep珲es
		catch (FileNotFoundException e) { 
			System.out.println("Ficheiro Pedidos.txt inexistente! ");
		}
		catch (IOException e) {
			System.out.println("Erro de IO! ");
		}
	}

	/**
	 * Le o ficheiro Intervencoes.txt e coloca o seu conteudo naa Arraylist intervencoes.
	 * 
	 * @param intervencoes ArrayList com as intervencoes realizadas
	 * 
	 */
	public void lerIntervencoes(ArrayList<n2006131015_Intervencao> intervencoes){
		String temp,descricao = null;
		int numI=0,numP=0,numT=0,dia=0,mes=0,ano=0,duracao=0,estado=0,coloca=0; 

		try{
			ft.abreLeitura("Intervencoes.txt");
			while ((temp=ft.lerLinha())!=null){
				StringTokenizer st=new StringTokenizer(temp);
				while (st.hasMoreTokens()){
					String temp2 = st.nextToken();
					if(temp2.equals("Interven珲es:")){  
						numI= Integer.parseInt(st.nextToken());
					}
					if(temp2.equals("Pedido:")){  
						numP= Integer.parseInt(st.nextToken());
					}
					if(temp2.equals("Tecnico:")){   
						numT= Integer.parseInt(st.nextToken());
					}
					if(temp2.equals("Descri玢o:")){ 
						while (st.hasMoreTokens()){
							if(descricao==null){
								descricao=st.nextToken();
							}
							else{
								descricao= descricao+" "+st.nextToken();
							}
						}
					}
					if(temp2.equals("Data:")){ 
						StringTokenizer st2=new StringTokenizer(st.nextToken());
						while (st2.hasMoreTokens()){
							dia = Integer.parseInt(st2.nextToken("/"));
							mes = Integer.parseInt(st2.nextToken("/"));
							ano = Integer.parseInt(st2.nextToken("/"));
						}
					}
					if(temp2.equals("horas):")){   
						duracao= Integer.parseInt(st.nextToken());
					}
					if(temp2.equals("Estado:")){  
						if (st.nextToken().equals("N鉶")){
							estado=2;
						}
						else{
							estado=1;
						}
						coloca=1;
					}
					if (coloca==1){
						intervencoes.add(new n2006131015_Intervencao (numI,numP,numT,descricao,duracao,estado));
						//Poe o dia, mes e ano que estavam no ficheiro no Arraylist
						Iterator<n2006131015_Intervencao> i = intervencoes.iterator();
						while (i.hasNext()) {
							n2006131015_Intervencao I = (n2006131015_Intervencao) i.next();
							if(I.getNumI()==numI){
								I.setDia(dia);
								I.setMes(mes);
								I.setAno(ano);
							}
						}
						coloca=0;
					}
				}
			}
			ft.fechaLeitura();
			System.out.println("Intervencoes.txt carregado com sucesso.");
		}

		// Trata excep珲es
		catch (FileNotFoundException e) { 
			System.out.println("Ficheiro Intervencoes.txt inexistente! ");
		}
		catch (IOException e) {
			System.out.println("Erro de IO! ");
		}
	}

	/**
	 * Le o ficheiro Pessoas.dat e  devolve para uma ArrayList[].
	 * 
	 * @return array ArrayList[] devolve as ArrayList utilizador e tecnico.
	 * 
	 */
	public ArrayList[] lerPessoas(){
		fo.abreLeitura("Pessoas.dat");
		utilizadorTemp=(ArrayList) fo.leObjecto();
		tecnicoTemp=(ArrayList) fo.leObjecto();
		fo.fechaLeitura();
		if (utilizadorTemp!=null){
			array[0]=utilizadorTemp;
		}
		if (tecnicoTemp!=null){
			array[1]=tecnicoTemp;
		}
		System.out.println("Pessoas.dat carregado com sucesso.");
		return array;
	}

	/**
	 * Le o ficheiro Postos_trab.dat e  devolve para uma ArrayList.
	 * 
	 * @return postoTrabalhoTemp ArrayList devolve a ArrayList postoTrabalho.
	 * 
	 */
	public ArrayList lerPostosTrabalho(){	
		fo.abreLeitura("Postos_trab.dat");
		postoTrabalhoTemp= (ArrayList) fo.leObjecto();
		fo.fechaLeitura();
		System.out.println("Postos_trab.dat carregado com sucesso.");
		return postoTrabalhoTemp;
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -