Last active
May 19, 2024 03:25
-
-
Save ClavijoJaider/7832bf58310ce6436fb95c42b4dd41f7 to your computer and use it in GitHub Desktop.
Proyecto 3 Apo 2, paquete estructural Empleado.java, paquete servicios ServiciosEmpleado.java
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
package estructural; | |
import lombok.AllArgsConstructor; | |
import lombok.Data; | |
@Data | |
@AllArgsConstructor | |
public class Empleado | |
{ | |
private int identificacion; | |
private String nombre; | |
private double salario; | |
private int experiencia; | |
public String estado = "Activo "; | |
private Empleado sgte; | |
@Override | |
public String toString() { | |
return "Empleado{" + | |
"identificacion=" + identificacion + | |
", nombre='" + nombre + '\'' + | |
", salario=" + salario + | |
", experiencia=" + experiencia + | |
", estado='" + estado + '\'' + | |
", sgte=" + sgte + | |
'}'; | |
} | |
} |
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
import estructural.Empleado; | |
import servicios.ServiciosEmpleado; | |
import java.util.Scanner; | |
public class Main { | |
public static void main(String[] args) | |
{ | |
Scanner scanner = new Scanner(System.in);//creo el scanner | |
ServiciosEmpleado serviciosempleado = new ServiciosEmpleado(); | |
Empleado empleado = null; | |
int opcion = -1; | |
while (opcion != 0) | |
{ | |
opcion = mostrarMenu(); | |
switch (opcion) { | |
case 0: | |
break; | |
case 1: { | |
System.out.println("Ingrese la identificacion: "); | |
int identificacion = scanner.nextInt(); | |
scanner.nextLine(); | |
System.out.println("Ingrese el nombre: "); | |
String nombre = scanner.nextLine(); | |
System.out.println("Ingrese el salario: "); | |
double salario = scanner.nextDouble(); | |
System.out.println("Ingrese la experiencia: "); | |
int experiencia = scanner.nextInt(); | |
Empleado v = new Empleado(identificacion, nombre, salario, experiencia, "Activo", null); | |
System.out.println("Ingrese 0. para añadir al inicio, 1. para añadir al final, 2. medio: "); | |
int opcion1 = scanner.nextInt(); | |
switch (opcion1) | |
{ | |
case 0: { | |
serviciosempleado.AñadirInicio(v); | |
break; | |
} | |
case 1: { | |
serviciosempleado.AñadirFinal(v); | |
break; | |
} | |
case 2: { | |
System.out.println("Ingrese la posicion: "); | |
int posicion = scanner.nextInt(); | |
serviciosempleado.AñadirMedio(v,posicion); | |
break; | |
} | |
} | |
System.out.println("Añadiendo..."); | |
break; | |
} | |
case 2: { | |
System.out.println("Actualizacion de salario y experiencia"); | |
System.out.println("numero de identificacion: "); | |
int identificacion = scanner.nextInt(); | |
scanner.nextLine(); | |
System.out.println("Ingrese el salario: "); | |
double salario = scanner.nextDouble(); | |
System.out.println("Ingrese la experiencia: "); | |
int experiencia = scanner.nextInt(); | |
serviciosempleado.actualizarNode(identificacion,salario,experiencia); | |
break; | |
} | |
case 3: | |
{ | |
System.out.println("Eliminacion de un empleado (Cambio de estado)"); | |
System.out.println("numero de identificacion: "); | |
int identificacion = scanner.nextInt(); | |
scanner.nextLine(); | |
//serviciosempleado.deleteLastNode(); | |
serviciosempleado.cambiarEstado(identificacion); | |
//serviciosempleado.eliminarNodo(identificacion); | |
break; | |
} | |
case 4: | |
{ | |
System.out.println("Buscar y visualizacion de un empleado"); | |
System.out.println("numero de identificacion: "); | |
int identificacion = scanner.nextInt(); | |
scanner.nextLine(); | |
serviciosempleado.busquedayvisualisacion(identificacion); | |
break; | |
} | |
case 5: | |
serviciosempleado.ImprimirTodos(); | |
break; | |
case 6: | |
serviciosempleado.imprimirSoloActivos(); | |
break; | |
case 7: | |
{ | |
System.out.println("Calculando nomina..."); | |
System.out.println("Nomina: " + serviciosempleado.nomina()); | |
} | |
break; | |
default: | |
System.out.println("Opción NO válida!"); | |
System.out.println("Digite una tecla para continuar..."); | |
scanner.nextLine(); | |
} | |
} | |
} | |
public static int mostrarMenu() { | |
Scanner scanner = new Scanner(System.in); | |
int opcion = -1; | |
System.out.println(); | |
System.out.println("=== Sistema de Empleados ==="); | |
System.out.println(); | |
System.out.println("\t\t\tMENU"); | |
System.out.println("1. Creación (adición) de un nuevo empleado"); | |
System.out.println("2. Actualización de los datos de un empleado"); | |
System.out.println("3. Eliminación del empleado "); | |
System.out.println("4. Búsqueda y visualización de un empleado "); | |
System.out.println("5. Listado de todos los empleados de la empresa (ACTIVOS e INACTIVOS)"); | |
System.out.println("6. Listado de todos los empleados de la empresa (ACTIVOS)"); | |
System.out.println("7. Calculo de la nómina de la empresa a partir de los salarios de los empleados (ACTIVOS)"); | |
System.out.println("0. Salir"); | |
opcion = scanner.nextInt(); | |
return opcion; | |
} | |
} |
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
package servicios; | |
import estructural.Empleado; | |
public class ServiciosEmpleado { | |
private Empleado cab; | |
public void AñadirInicio(Empleado nuevo) { | |
if (cab == null) { | |
cab = nuevo; | |
return; | |
} | |
nuevo.setSgte(cab); | |
cab = nuevo; | |
} | |
public void AñadirFinal(Empleado nuevo) { | |
Empleado rec = cab; | |
if (cab == null) { | |
cab = nuevo; | |
return; | |
} | |
while (rec != null) { | |
if (rec.getSgte() == null) { | |
rec.setSgte(nuevo); | |
break; | |
} | |
rec = rec.getSgte(); | |
} | |
} | |
public void AñadirMedio(Empleado nuevo, int posicion) { | |
int contador = 0; | |
Empleado anterior = cab; | |
while (anterior != null) { | |
System.out.println(anterior); | |
contador++; | |
if (contador == posicion - 1) { | |
nuevo.setSgte(anterior.getSgte()); | |
anterior.setSgte(nuevo); | |
break; | |
} | |
anterior = anterior.getSgte(); | |
} | |
} | |
public void ImprimirTodos() { | |
Empleado rec = cab; | |
while (rec != null) { | |
System.out.println(rec); | |
rec = rec.getSgte(); | |
} | |
} | |
public void imprimirSoloActivos() { | |
Empleado rec = cab; | |
while (rec != null) { | |
if (rec.getEstado().equalsIgnoreCase("activo")) { | |
System.out.println(rec); | |
} | |
rec = rec.getSgte(); | |
} | |
} | |
public double nomina() { | |
Empleado rec = cab; | |
double nomina = 0; | |
while (rec != null) { | |
if(rec.getEstado().equalsIgnoreCase("activo")){ | |
nomina = nomina + rec.getSalario(); | |
} | |
rec = rec.getSgte(); | |
} | |
return nomina; | |
} | |
public void busquedayvisualisacion(int id) { | |
Empleado rec = cab; | |
while (rec != null) { | |
if (rec.getIdentificacion() == id) { | |
System.out.println(rec); | |
return; | |
} | |
rec = rec.getSgte(); | |
} | |
} | |
public void actualizarNode(int identificacion, double salario, int experiencia) { | |
Empleado rec = cab; | |
while (rec != null) { | |
if (rec.getIdentificacion() == identificacion) { | |
rec.setSalario(salario); | |
rec.setExperiencia(experiencia); | |
return; | |
} | |
rec = rec.getSgte(); | |
} | |
return; | |
} | |
public void cambiarEstado(int identificacion) { | |
Empleado rec = cab; | |
while (rec != null) { | |
if (rec.getIdentificacion() == identificacion) { | |
rec.setEstado("Inactivo"); | |
return; | |
} | |
rec = rec.getSgte(); | |
} | |
return; | |
} | |
//ESTOS ELIMINAN DE LA LISTA NO CAMBIAN EL ESTADO | |
public void deleteFirstNode() { | |
Empleado rec = cab; | |
if (cab == null) { | |
return; | |
} | |
cab = cab.getSgte(); | |
} | |
public void deleteLastNode() { | |
Empleado rec = cab; | |
//si esta vacio | |
if (cab == null) { | |
return; | |
} | |
//si solo esta el mismo | |
if (cab.getSgte() == null) { | |
cab = null; | |
return; | |
} | |
while (rec.getSgte() != null) { | |
if (rec.getSgte().getSgte() == null) { | |
rec.setSgte(null); | |
return; | |
} | |
rec = rec.getSgte(); | |
} | |
} | |
public void eliminarNodo(int id) { | |
Empleado rec = cab; | |
if (cab == null) { | |
return; | |
} | |
if (cab.getIdentificacion() == id) { | |
cab = cab.getSgte(); | |
return; | |
} | |
while (rec != null) { | |
if (rec.getIdentificacion() == id) { | |
Empleado ant = findPreviousNode(id); | |
ant.setSgte(rec.getSgte()); | |
rec = ant; | |
return; | |
} | |
rec = rec.getSgte(); | |
} | |
} | |
public Empleado findPreviousNode(int id) { | |
Empleado rec = cab; | |
Empleado ant = cab; | |
if (cab == null) { | |
return null; | |
} | |
if (cab.getIdentificacion() == id) { | |
return null; | |
} | |
ant = cab; | |
rec = cab.getSgte(); | |
while (rec != null) { | |
if (rec.getIdentificacion() == id) { | |
return ant; | |
} | |
ant = rec; | |
rec = rec.getSgte(); | |
} | |
return rec; | |
} | |
public void EliminarPrimerNodo() { | |
if (cab == null) { | |
return; | |
} | |
cab = cab.getSgte(); | |
} | |
public void EliminarUltimoNodo() | |
{ | |
Empleado rec = cab; | |
if (cab == null) { | |
return; | |
} | |
if (cab.getSgte() == null) { | |
cab = null; | |
return; | |
} | |
while (rec != null) | |
{ | |
if (rec.getSgte().getSgte() == null) | |
{ | |
rec.setSgte(null); | |
break; | |
} | |
rec = rec.getSgte(); | |
} | |
} | |
public void EliminarNodoCualquiera(int posicion) | |
{ | |
int contador = 0; | |
Empleado anterior = cab; | |
Empleado temp; | |
if (cab == null) | |
{ | |
return; | |
} | |
if (posicion - 1 == 0) | |
{ | |
cab = cab.getSgte(); | |
} | |
while (anterior != null) { | |
System.out.println(anterior); | |
contador++; | |
if (contador == posicion - 2) | |
{ | |
temp = anterior.getSgte().getSgte(); | |
anterior.setSgte(temp); | |
break; | |
} | |
anterior = anterior.getSgte(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment