Created
November 15, 2024 23:49
-
-
Save MarioCares/b780ae0ff90a4ab966d93aed7bca9860 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license | |
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Main.java to edit this template | |
*/ | |
package appestadistica; | |
import appestadistica.clases.Trabajador; | |
import java.util.ArrayList; | |
import java.util.Scanner; | |
/** | |
* | |
* @author infopunto | |
*/ | |
public class AppEstadistica { | |
/** | |
* @param args the command line arguments | |
*/ | |
public static void main(String[] args) { | |
ArrayList<Trabajador> trabajadores = new ArrayList<>(); | |
for(int i = 1; i <= 3; i++) { | |
System.out.println("Ingresando trabajador Nº:" + i); | |
Scanner sc = new Scanner(System.in); | |
try { | |
System.out.println("Ingrese run trabajador"); | |
Integer run = Integer.valueOf(sc.next()); | |
System.out.println("Ingrese nombre trabajador"); | |
String nombre = sc.next(); | |
System.out.println("Ingrese sexo(H/M) trabajador"); | |
String sexo = sc.next(); | |
if ("H".equals(sexo) || "M".equals(sexo)) { | |
System.out.println("Ingrese salario trabajador"); | |
Integer salario = Integer.valueOf(sc.next()); | |
// CREO USUARIO | |
Trabajador t = new Trabajador(run, salario, nombre, sexo); | |
trabajadores.add(t); | |
} else { | |
System.out.println("El valor ingresado no es correcto"); | |
} | |
} catch(Exception ex) { | |
System.out.println("Tuvimos el siguiente error: " + ex.getMessage()); | |
} | |
} | |
// GENERO ESTADÍSTICAS | |
Integer countMen = 0; | |
Integer countWomen = 0; | |
Integer averageSalary = 0; | |
Integer accumulateSalary = 0; | |
String minSalaryName = ""; | |
String maxSalaryName = ""; | |
for(int i = 0; i < trabajadores.size(); i++) { | |
if ("H".equals(trabajadores.get(i).getSexo())) { | |
countMen++; | |
} else { | |
countWomen++; | |
} | |
accumulateSalary += trabajadores.get(i).getSalario(); | |
} | |
averageSalary = accumulateSalary / trabajadores.size(); | |
System.out.println("La cantidad de hombres: " + countMen); | |
System.out.println("La cantidad de mujeres: " + countWomen); | |
System.out.println("El sueldo promedio es: " + averageSalary); | |
// TAREA: Nombre del trabajador con mayor y menor sueldo | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment