Advertisement
Guest User

ArquivoPrincipal

a guest
Nov 21st, 2019
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.58 KB | None | 0 0
  1. package empresa;
  2.  
  3. import java.io.File;
  4. import java.io.FileNotFoundException;
  5. import java.util.Scanner;
  6.  
  7. public class Empresa {
  8.  
  9. public static void main(String[] args) throws FileNotFoundException {
  10. Scanner leia = new Scanner(System.in);
  11.  
  12. Funcionario func[] = new Funcionario[10];
  13. lerdados(func);
  14.  
  15. int opcao = 0;
  16.  
  17. while (opcao != 3) {
  18. System.out.printf("\nControle de salários\n");
  19. System.out.printf("1 – Salários finais\n");
  20. System.out.printf("2 – Pesquisa salário por filial\n");
  21. System.out.println("3 – Sair");
  22. System.out.println("Digite a opção");
  23. opcao = leia.nextInt();
  24.  
  25. switch (opcao) {
  26. case 1:
  27.  
  28. System.out.println("");
  29. salario_Final(func);
  30. System.out.println("");
  31. System.out.println("Valor total da folha de pagamento: " + pagamentoTotal_Empresa(func));
  32. break;
  33. case 2:
  34.  
  35. System.out.println("Digite a Filial");
  36. char cod = leia.next().charAt(0);
  37. if (cod == 'a' || cod == 'b' || cod == 'c') {
  38. System.out.println("");
  39. System.out.println("O Menor salario da Filial é do " + func[menorSalario_Filial(func, cod)].getNome() + " " + func[menorSalario_Filial(func, cod)].getSalbase());
  40. } else {
  41. System.out.println("Filial não encontrada");
  42. }
  43. break;
  44. case 3:
  45. System.out.println("Sair");
  46. break;
  47. default:
  48. System.out.println("Opcão Invalida");
  49. break;
  50. }
  51. }
  52.  
  53. }
  54.  
  55. public static void lerdados(Funcionario func[]) throws FileNotFoundException {
  56.  
  57. File arq = new File("dados.txt");
  58. Scanner leiaArq = new Scanner(arq);
  59.  
  60. System.out.printf("%15s %15s %15s\n", leiaArq.next(), leiaArq.next(), leiaArq.next());
  61. for (int i = 0; i < 10; i++) {
  62. func[i] = new Funcionario(leiaArq.next(), leiaArq.next().charAt(0), leiaArq.nextDouble());
  63. System.out.printf("%9s %15c %20.2f\n", func[i].getNome(), func[i].getCodFilial(), func[i].getSalbase());
  64. }
  65. }
  66.  
  67. public static void salario_Final(Funcionario func[]) {
  68. System.out.printf("%10s %10s\n", "Nome", "Salário Final");
  69. for (int i = 0; i < 10; i++) {
  70. System.out.printf("%10s %10.2f\n", func[i].getNome(), func[i].calcSalFinal());
  71. }
  72. }
  73.  
  74. public static double pagamentoTotal_Empresa(Funcionario func[]) {
  75. double soma = 0;
  76. for (int i = 0; i < 10; i++) {
  77. soma = soma + func[i].calcSalFinal();
  78. }
  79. return soma;
  80. }
  81.  
  82. public static int menorSalario_Filial(Funcionario func[], char cod) {
  83. int ind = 0;
  84. double salario = 0;
  85. int cont = 0;
  86. for (int i = 0; i < 10; i++) {
  87. if (cod == func[i].getCodFilial()) {
  88. if (cont == 0) {
  89. ind = i;
  90. salario = func[i].getSalbase();
  91. cont++;
  92. } else {
  93. if (salario > func[i].getSalbase()) {
  94. ind = i;
  95. salario = func[i].getSalbase();
  96. cont++;
  97. }
  98. }
  99. }
  100. }
  101. return ind;
  102. }
  103.  
  104. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement