Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Atleta
- {
- private static int proximoNumero = 1; //numera automaticamente o numero de atletas criados
- public int numero; // numero do atleta
- public String nome; // nome do atleta
- public String idadeGrupo; // media, junior ou senior
- public int tempo; // tempo demurado pelo atleta na maratona
- /**
- * Constructor para os objectos da class Atleta.
- */
- public Atleta() {
- super();
- this.nome = "";
- this.idadeGrupo = "media";
- this.tempo = 0;
- this.numero = this.proximoNumero;
- this.proximoNumero++;
- }
- import java.util.*;
- import java.io.*;
- /**
- * Class MaratonaAdmin - administra a maratona
- */
- public class MaratonaAdmin
- {
- private Atleta osAtletas;
- /**
- * Constructor para os objectos da class MaratonaAdmin
- */
- public MaratonaAdmin() {
- List<Atleta> listaAtletas = new ArrayList<>();
- // Para debug
- int tamanho = listaAtletas.size();
- System.out.println("Tamanho da lista " + tamanho);
- }
- /**
- * Metodo que lê de arquive .CSV
- * Não tem argumento
- * Não retorna valores
- */
- public void lerOsAtletas() {
- FileReader arq = new FileReader("test.csv");
- String nome;
- String idadeGrupo;
- int tempo;
- Scanner linhaScanner;
- String linhaCurrente;
- Scanner bufferedScanner = null;
- bufferedScanner = new Scanner(new BufferedReader(new FileReader("test.csv")));
- try {
- while (bufferedScanner.hasNextLine()) {
- linhaCurrente = bufferedScanner.nextLine();
- linhaScanner = new Scanner(linhaCurrente);
- linhaScanner.useDelimiter(",");
- nome = linhaScanner.next();
- idadeGrupo = linhaScanner.next();
- tempo = linhaScanner.next();
- listaAtletas.add(new Account(accountHolder, accountNumber, accountBalance));
- }
- }
- catch (Exception anException) {
- System.out.println("Erro: " + anException);
- }
- finally {
- try {
- bufferedScanner.close();
- }
- catch (Exception anException) {
- System.out.println("Error: " + anException);
- }
- }
- }
- }
- listaAtletas.add(new Account(accountHolder, accountNumber, accountBalance));
- import java.util.*;
- import java.io.*;
- public class MaratonaAdmin {
- static List<Atleta> listaAtletas;
- public static void main(String[] args) throws FileNotFoundException {
- listaAtletas = new ArrayList<>();
- lerOsAtletas();
- System.out.println("Tamanho da lista " + listaAtletas.size());
- for (Atleta atl : listaAtletas) {
- System.out.println("Atleta no.: " + atl.numero);
- System.out.println("Nome: " + atl.nome);
- System.out.println("Grupo: " + atl.idadeGrupo);
- System.out.println("Tempo: " + atl.tempo);
- System.out.println("#######");
- }
- }
- public static void lerOsAtletas() throws FileNotFoundException {
- FileReader arq = new FileReader("C://Users//danie//Documents//test.csv");
- Scanner bufferedScanner = new Scanner(new BufferedReader(arq));
- try {
- while (bufferedScanner.hasNextLine()) {
- String linhaCurrente = bufferedScanner.nextLine();
- Scanner linhaScanner = new Scanner(linhaCurrente);
- linhaScanner.useDelimiter(",");
- listaAtletas.add(new Atleta(linhaScanner.next(),
- linhaScanner.next(), linhaScanner.next()));
- linhaScanner.close();
- }
- } catch (Exception anException) {
- System.out.println("Erro: " + anException);
- } finally {
- try {
- bufferedScanner.close();
- } catch (Exception anException) {
- System.out.println("Error: " + anException);
- }
- }
- }
- }
- public class Atleta {
- private static int proximoNumero = 1;
- public int numero;
- public String nome;
- public String idadeGrupo;
- public String tempo;
- public Atleta(String nome, String idadeGrupo, String tempo) {
- this.nome = nome;
- this.idadeGrupo = idadeGrupo;
- this.tempo = tempo;
- this.numero = Atleta.proximoNumero;
- Atleta.proximoNumero++;
- }
- }
- stackoverflow,junior,2:02:57
- Torre Eiffel,senior,3:14:41
- Empire State,media,4:21:18
- Tamanho da lista 3
- Atleta no.: 1
- Nome: stackoverflow
- Grupo: junior
- Tempo: 2:02:57
- #######
- Atleta no.: 2
- Nome: Torre Eiffel
- Grupo: senior
- Tempo: 3:14:41
- #######
- Atleta no.: 3
- Nome: Empire State
- Grupo: media
- Tempo: 4:21:18
- #######
- import java.util.*;
- import java.io.*;
- /**
- * Class MaratonaAdmin - administra a maratona
- */
- public class MaratonaAdmin
- {
- //private Atleta osAtletas;
- static List<Atleta> listaAtletas;
- /**
- * Constructor para os objectos da class MaratonaAdmin
- */
- public MaratonaAdmin() throws FileNotFoundException
- {
- listaAtletas = new ArrayList<>();
- lerOsAtletas();
- for (Atleta atl : listaAtletas) {
- System.out.println("Atleta no.: " + atl.numero);
- System.out.println("Nome: " + atl.nome);
- System.out.println("Grupo: " + atl.idadeGrupo);
- System.out.println("Tempo: " + atl.tempo);
- System.out.println("#######");
- }
- }
- /**
- * Metodo que lê de arquive .CSV
- * Não tem argumento
- * Não retorna valores
- */
- public static void lerOsAtletas() throws FileNotFoundException
- {
- Scanner bufferedScanner = new Scanner(new BufferedReader(new FileReader("C://Users//danie//Documents//test.csv")));
- try {
- while (bufferedScanner.hasNextLine()) {
- String linhaCurrente = bufferedScanner.nextLine();
- Scanner linhaScanner = new Scanner(linhaCurrente);
- linhaScanner.useDelimiter(",");
- listaAtletas.add(new Atleta(linhaScanner.next(),
- linhaScanner.next(), linhaScanner.next()));
- linhaScanner.close();
- }
- } catch (Exception anException) {
- System.out.println("Erro: " + anException);
- } finally {
- try {
- bufferedScanner.close();
- } catch (Exception anException) {
- System.out.println("Error: " + anException);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement