Advertisement
Guest User

Untitled

a guest
Feb 21st, 2019
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.30 KB | None | 0 0
  1. public class Atleta
  2. {
  3. private static int proximoNumero = 1; //numera automaticamente o numero de atletas criados
  4.  
  5. public int numero; // numero do atleta
  6. public String nome; // nome do atleta
  7. public String idadeGrupo; // media, junior ou senior
  8. public int tempo; // tempo demurado pelo atleta na maratona
  9.  
  10. /**
  11. * Constructor para os objectos da class Atleta.
  12. */
  13. public Atleta() {
  14. super();
  15. this.nome = "";
  16. this.idadeGrupo = "media";
  17. this.tempo = 0;
  18. this.numero = this.proximoNumero;
  19. this.proximoNumero++;
  20.  
  21. }
  22.  
  23. import java.util.*;
  24. import java.io.*;
  25. /**
  26. * Class MaratonaAdmin - administra a maratona
  27. */
  28. public class MaratonaAdmin
  29. {
  30.  
  31. private Atleta osAtletas;
  32.  
  33. /**
  34. * Constructor para os objectos da class MaratonaAdmin
  35. */
  36. public MaratonaAdmin() {
  37. List<Atleta> listaAtletas = new ArrayList<>();
  38. // Para debug
  39. int tamanho = listaAtletas.size();
  40. System.out.println("Tamanho da lista " + tamanho);
  41. }
  42.  
  43. /**
  44. * Metodo que lê de arquive .CSV
  45. * Não tem argumento
  46. * Não retorna valores
  47. */
  48. public void lerOsAtletas() {
  49. FileReader arq = new FileReader("test.csv");
  50. String nome;
  51. String idadeGrupo;
  52. int tempo;
  53. Scanner linhaScanner;
  54. String linhaCurrente;
  55. Scanner bufferedScanner = null;
  56. bufferedScanner = new Scanner(new BufferedReader(new FileReader("test.csv")));
  57. try {
  58. while (bufferedScanner.hasNextLine()) {
  59. linhaCurrente = bufferedScanner.nextLine();
  60. linhaScanner = new Scanner(linhaCurrente);
  61. linhaScanner.useDelimiter(",");
  62. nome = linhaScanner.next();
  63. idadeGrupo = linhaScanner.next();
  64. tempo = linhaScanner.next();
  65. listaAtletas.add(new Account(accountHolder, accountNumber, accountBalance));
  66. }
  67. }
  68. catch (Exception anException) {
  69. System.out.println("Erro: " + anException);
  70. }
  71. finally {
  72. try {
  73. bufferedScanner.close();
  74. }
  75. catch (Exception anException) {
  76. System.out.println("Error: " + anException);
  77. }
  78. }
  79. }
  80. }
  81.  
  82. listaAtletas.add(new Account(accountHolder, accountNumber, accountBalance));
  83.  
  84. import java.util.*;
  85. import java.io.*;
  86.  
  87. public class MaratonaAdmin {
  88.  
  89. static List<Atleta> listaAtletas;
  90.  
  91. public static void main(String[] args) throws FileNotFoundException {
  92.  
  93. listaAtletas = new ArrayList<>();
  94. lerOsAtletas();
  95.  
  96. System.out.println("Tamanho da lista " + listaAtletas.size());
  97.  
  98. for (Atleta atl : listaAtletas) {
  99. System.out.println("Atleta no.: " + atl.numero);
  100. System.out.println("Nome: " + atl.nome);
  101. System.out.println("Grupo: " + atl.idadeGrupo);
  102. System.out.println("Tempo: " + atl.tempo);
  103. System.out.println("#######");
  104. }
  105. }
  106.  
  107. public static void lerOsAtletas() throws FileNotFoundException {
  108.  
  109. FileReader arq = new FileReader("C://Users//danie//Documents//test.csv");
  110.  
  111. Scanner bufferedScanner = new Scanner(new BufferedReader(arq));
  112. try {
  113. while (bufferedScanner.hasNextLine()) {
  114. String linhaCurrente = bufferedScanner.nextLine();
  115. Scanner linhaScanner = new Scanner(linhaCurrente);
  116. linhaScanner.useDelimiter(",");
  117. listaAtletas.add(new Atleta(linhaScanner.next(),
  118. linhaScanner.next(), linhaScanner.next()));
  119. linhaScanner.close();
  120. }
  121. } catch (Exception anException) {
  122. System.out.println("Erro: " + anException);
  123. } finally {
  124. try {
  125. bufferedScanner.close();
  126. } catch (Exception anException) {
  127. System.out.println("Error: " + anException);
  128. }
  129. }
  130. }
  131. }
  132.  
  133. public class Atleta {
  134. private static int proximoNumero = 1;
  135. public int numero;
  136. public String nome;
  137. public String idadeGrupo;
  138. public String tempo;
  139.  
  140. public Atleta(String nome, String idadeGrupo, String tempo) {
  141. this.nome = nome;
  142. this.idadeGrupo = idadeGrupo;
  143. this.tempo = tempo;
  144. this.numero = Atleta.proximoNumero;
  145. Atleta.proximoNumero++;
  146. }
  147. }
  148.  
  149. stackoverflow,junior,2:02:57
  150. Torre Eiffel,senior,3:14:41
  151. Empire State,media,4:21:18
  152.  
  153. Tamanho da lista 3
  154. Atleta no.: 1
  155. Nome: stackoverflow
  156. Grupo: junior
  157. Tempo: 2:02:57
  158. #######
  159. Atleta no.: 2
  160. Nome: Torre Eiffel
  161. Grupo: senior
  162. Tempo: 3:14:41
  163. #######
  164. Atleta no.: 3
  165. Nome: Empire State
  166. Grupo: media
  167. Tempo: 4:21:18
  168. #######
  169.  
  170. import java.util.*;
  171. import java.io.*;
  172.  
  173. /**
  174. * Class MaratonaAdmin - administra a maratona
  175. */
  176. public class MaratonaAdmin
  177. {
  178.  
  179. //private Atleta osAtletas;
  180. static List<Atleta> listaAtletas;
  181.  
  182. /**
  183. * Constructor para os objectos da class MaratonaAdmin
  184. */
  185. public MaratonaAdmin() throws FileNotFoundException
  186. {
  187. listaAtletas = new ArrayList<>();
  188. lerOsAtletas();
  189. for (Atleta atl : listaAtletas) {
  190. System.out.println("Atleta no.: " + atl.numero);
  191. System.out.println("Nome: " + atl.nome);
  192. System.out.println("Grupo: " + atl.idadeGrupo);
  193. System.out.println("Tempo: " + atl.tempo);
  194. System.out.println("#######");
  195. }
  196.  
  197. }
  198.  
  199. /**
  200. * Metodo que lê de arquive .CSV
  201. * Não tem argumento
  202. * Não retorna valores
  203. */
  204. public static void lerOsAtletas() throws FileNotFoundException
  205. {
  206. Scanner bufferedScanner = new Scanner(new BufferedReader(new FileReader("C://Users//danie//Documents//test.csv")));
  207. try {
  208. while (bufferedScanner.hasNextLine()) {
  209. String linhaCurrente = bufferedScanner.nextLine();
  210. Scanner linhaScanner = new Scanner(linhaCurrente);
  211. linhaScanner.useDelimiter(",");
  212. listaAtletas.add(new Atleta(linhaScanner.next(),
  213. linhaScanner.next(), linhaScanner.next()));
  214. linhaScanner.close();
  215. }
  216. } catch (Exception anException) {
  217. System.out.println("Erro: " + anException);
  218. } finally {
  219. try {
  220. bufferedScanner.close();
  221. } catch (Exception anException) {
  222. System.out.println("Error: " + anException);
  223. }
  224. }
  225. }
  226. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement