Created
August 15, 2021 00:48
-
-
Save enzobonggio/a66b8bb2b222067567068390872c596b 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
public class Contratista extends Empleado { | |
double valorHora; | |
public Contratista(String nombre, String profesion, int experiencia,double valorHora) { | |
super(nombre, profesion, experiencia); | |
this.valorHora = valorHora; | |
} | |
@Override | |
public String toString(){ | |
return "\tEmpleado de planta - Nombre: " + nombre + " \n" + | |
"\tProfesión: "+profesion+"\n" + | |
"\tExperiencia:"+experiencia+"\n" + | |
"\tValor hora:"+ valorHora; | |
} | |
} |
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
public abstract class Empleado { | |
String nombre, profesion; | |
int experiencia; | |
public Empleado(String nombre, String profesion, int experiencia) { | |
this.nombre = nombre; | |
this.profesion = profesion; | |
this.experiencia = experiencia; | |
} | |
} |
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 java.util.ArrayList; | |
import java.util.List; | |
import java.util.Scanner; | |
public class Empresa { | |
List<Empleado> empleados; | |
public Empresa() { | |
this.empleados = new ArrayList<>(); | |
} | |
public void agregarEmpleado(String[] partes) { | |
// partes = ["1", "Contratista", "Luisa Lopez"...] | |
String tipo = partes[1]; | |
String nombre = partes[2]; | |
String profesion = partes[3]; | |
int experiencia = Integer.parseInt(partes[4]); | |
if (tipo.equals("Contratista")) { | |
int salario = Integer.parseInt(partes[5]); | |
Empleado contratista = new Contratista(nombre, profesion, experiencia, salario); | |
empleados.add(contratista); | |
} else if (tipo.equals("Planta")) { | |
int valor = Integer.parseInt(partes[5]); | |
Empleado planta = new Planta(nombre, profesion, experiencia, valor); | |
empleados.add(planta); | |
} | |
} | |
public void listarEmpleados() { | |
System.out.println("***Lista de Empleados***"); | |
for(Empleado i:empleados){ | |
System.out.println(i.toString()); | |
} | |
} | |
public boolean procesar() { | |
Scanner sc = new Scanner(System.in); | |
String comando = sc.nextLine(); | |
String[] partes = comando.split("&"); | |
String opcion = partes[0]; | |
switch (opcion) { | |
case "1": | |
agregarEmpleado(partes); | |
return true; | |
case "2": | |
listarEmpleados(); | |
return true; | |
case "3": | |
return false; | |
default:return false; | |
} | |
// comando = "1&Contratista&Luisa Lopez&Diseñador&11&54000"; | |
// partes = ["1", "Contratista", "Luisa Lopez"...] | |
} | |
public static void main(String[] args) { | |
Empresa empresa=new Empresa(); | |
while(empresa.procesar()){} | |
} | |
} |
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
public class Planta extends Empleado { | |
double salarioBase; | |
public Planta(String nombre, String profesion, int experiencia, double salarioBase) { | |
super(nombre, profesion, experiencia); | |
this.salarioBase = salarioBase; | |
} | |
@Override | |
public String toString(){ | |
return "\tEmpleado de planta - Nombre: " + nombre + " \n" + | |
"\tProfesión: "+profesion+"\n" + | |
"\tExperiencia:"+experiencia+"\n" + | |
"\tSalario base:"+ salarioBase; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment