Advertisement
srvelososantos

Untitled

May 20th, 2019
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.88 KB | None | 0 0
  1. package funcionarios_pizzaria;
  2.  
  3. import java.io.BufferedReader;
  4. import java.io.FileReader;
  5. import java.io.FileWriter;
  6. import java.io.IOException;
  7. import javax.swing.JOptionPane;
  8. import java.util.ArrayList;
  9.  
  10. public class Main {
  11.  
  12. public static void main(String[] args) {
  13. ArrayList<Funcionarios> funcs = new ArrayList<Funcionarios>();
  14. int n = 0;
  15. boolean sair = false;
  16.  
  17. try{
  18. BufferedReader leitor = new BufferedReader(new FileReader("dados.txt"));
  19. String linha = "";
  20. while((linha = leitor.readLine()) != null){
  21. String[] partes = linha.split(";");
  22. System.out.println("");
  23. Funcionarios fun = new Funcionarios(partes[0], partes[1], partes[2], partes[3], partes[4], partes[5]);
  24. funcs.add(fun);
  25. }
  26. }catch(IOException ex){
  27. ex.printStackTrace();
  28. }
  29.  
  30.  
  31.  
  32. while (sair == false) {
  33. String e = JOptionPane.showInputDialog("escolha:");
  34. if (e.equals("add")) {
  35.  
  36. //INSTANCIAMENTO DE ATRIBUTOS DA CLASSE FUNCIONARIOS
  37. String nome = JOptionPane.showInputDialog("entre com o nome do funcionario");
  38. int sal = Integer.parseInt(JOptionPane.showInputDialog("entre com o valor do salario"));
  39. String setor = JOptionPane.showInputDialog("entre com o setor");
  40. int tel = Integer.parseInt(JOptionPane.showInputDialog("entre com o numero"));
  41. int idade = Integer.parseInt(JOptionPane.showInputDialog("entre com a idade"));
  42. int tempo = Integer.parseInt(JOptionPane.showInputDialog("entre com o tempo na empresa"));
  43.  
  44. funcs.add(n, new Funcionarios(sal, setor, nome, tel, idade, tempo));
  45. n++;
  46. } else if (e.equals("show")) {
  47. String nome = JOptionPane.showInputDialog(null, "digite o nome");
  48. for (Funcionarios f : funcs) {
  49. if(f.getNome().equals(nome));{
  50. JOptionPane.showMessageDialog(null, "nome: "+f.getNome());
  51. }
  52. }
  53. }else if (e.equals("exit")){
  54. sair = true;
  55. try{
  56. JOptionPane.showMessageDialog(null, "irmao ja vai grava calma");
  57. FileWriter arq = new FileWriter("dados.txt");
  58. for(Funcionarios fun : funcs){
  59. arq.write(fun.toString()+"\n");
  60. }
  61. arq.close();
  62. JOptionPane.showMessageDialog(null,"gravado");
  63. }catch(IOException ex){
  64. ex.printStackTrace();
  65. }
  66. }else{
  67. JOptionPane.showMessageDialog(null, "opcao invalida");
  68. }
  69.  
  70. }
  71. }
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement