Código:
package superEmpleado.modelo;
public class Empleado {
/**
* @attribute
*/
private String apeEmpleado;
/**
* @attribute
*/
private int auxTrans;
/**
* @attribute
*/
private int codigo;
/**
* @attribute
*/
private int fsp;
/**
* @attribute
*/
private String nombreEmpleado;
/**
* @attribute
*/
private int pension;
/**
* @attribute
*/
private int quincena;
/**
* @attribute
*/
private int salario;
/**
* @attribute
*/
private int salud;
/**
* @attribute
*/
private int totalDescuento;
/**
* @attribute
*/
private int totalDevengado;
/**
* @attribute
*/
private int totalPagar;
public Empleado() {
codigo = 0;
nombreEmpleado = "";
apeEmpleado = "";
salario = 0;
quincena = 0;
auxTrans = 0;
totalDevengado = 0;
salud = 0;
pension = 0;
fsp = 0;
totalDescuento = 0;
totalPagar = 0;
}
public void asignarEmpleado(int codP, String nomP, String apeP, int salP) {
codigo = codP;
nombreEmpleado = nomP;
apeEmpleado = apeP;
salario = salP;
quincena = 0;
auxTrans = 0;
totalDevengado = 0;
salud = 0;
pension = 0;
fsp = 0;
totalDescuento = 0;
totalPagar = 0;
}
public void calcularAuxTransporte(int dias) {
if (salario <= 2 * Empresa.SML)
auxTrans = (dias * Empresa.AT / 30);
else
auxTrans = 0;
}
public void calcularFSP(int dias) {
if (salario >= 4 * Empresa.SML)
fsp = (int) (salario * dias / 30 * Empresa.FSP);
else
fsp = 0;
}
public void calcularPension(int dias) {
pension = (int) (salario * dias / 30 * Empresa.PENSION);
}
public void calcularQuincena(int dias) {
quincena = (int) (salario * dias / 30);
}
public void calcularSalud(int dias) {
salud = (int) (salario * dias / 30 * Empresa.SALUD);
}
public void calcularTotalDescuentos() {
totalDescuento = salud + pension + fsp;
}
public void calcularTotalDevengado() {
totalDevengado = quincena + auxTrans;
}
public void calcularTotalPagar() {
totalPagar = totalDevengado - totalDescuento;
}
public String getApeEmpleado() {
return apeEmpleado;
}
public int getAuxTrans() {
return auxTrans;
}
public int getCodigo() {
return codigo;
}
public int getFSP() {
return fsp;
}
public String getNombreEmpleado() {
return nombreEmpleado;
}
public int getPension() {
return pension;
}
public int getQuincena() {
return quincena;
}
public int getSalario() {
return salario;
}
public int getSalud() {
return salud;
}
public int getTotalDevengado() {
return totalDevengado;
}
public int getTotalPagar(){
return totalPagar;
}
public int getTotalDescuentos(){
return totalDescuento;
}
}
ese se llama empelado
Código:
package superEmpleado.modelo;
public class Empresa {
/**
* @attribute
*/
final public static int AT = 70500;
/**
* @attribute
*/
final public static double CAJA = 0.04;
/**
* @attribute
*/
final public static double FSP = 0.01;
/**
* @attribute
*/
final public static double ICBF = 0.03;
/**
* @attribute
*/
final public static double PENSION = 0.04;
/**
* @attribute
*/
final public static double SALUD = 0.04;
/**
* @attribute
*/
final public static double SENA = 0.02;
/**
* @attribute
*/
final public static int SML = 589500;
private Empleado empleado[];
/**
* @attribute
*/
private int caja;
/**
* @attribute
*/
private int cesantias;
/**
* @attribute
*/
private int icbf;
/**
* @attribute
*/
private int interesesCesantias;
/**
* @attribute
*/
private int sena;
/**
* @attribute
*/
private int totalNomina;
/**
* @attribute
*/
private int totalParafiscales;
/**
* @attribute
*/
private int totalPagar;
public Empresa() {
sena = 0;
icbf = 0;
caja = 0;
totalParafiscales = 0;
interesesCesantias = 0;
totalNomina = 0;
empleado = new Empleado[5];
}
public void CalcularParafiscales() {
totalParafiscales = (sena + icbf + caja);
}
public void calcularCaja() {
caja = (int) (totalNomina * CAJA);
}
public void calcularCesantias() {
cesantias = (int)(totalNomina / 12);
}
public void calcularICBF() {
icbf = (int) (totalNomina * ICBF);
}
public void calcularSena() {
sena = (int)(totalNomina * SENA);
}
public void calcularTotalNomina(int totalPago) {
totalNomina += totalPago;
}
public int getCaja() {
return caja;
}
public int getCesantias() {
return cesantias;
}
public int getIcbf() {
return icbf;
}
public int getInteresesCesantias() {
return interesesCesantias;
}
public int getSena() {
return sena;
}
public int getTotalNomina() {
return totalNomina;
}
public int getTotalParafiscales() {
return totalParafiscales;
}
}
este se llama empresa
Código:
package superEmpleado.modelo;
import java.awt.Button;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.EventQueue;
import java.awt.Font;
import java.awt.Rectangle;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.text.DecimalFormat;
import java.text.NumberFormat;
import javax.swing.JEditorPane;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JSeparator;
public class Frame1 extends JFrame {
private Empleado empleado[] = new Empleado[5];
private Empresa empresa = new Empresa();
private JLabel jLabel1 = new JLabel();
private JEditorPane textCodigo= new JEditorPane();
private JLabel jLabel2 = new JLabel();
private JEditorPane textNombre = new JEditorPane();
private JLabel jLabel3 = new JLabel();
private JEditorPane textApellido = new JEditorPane();
private JSeparator jSeparator1 = new JSeparator();
private Button button1 = new Button();
private Button button2 = new Button();
private Button button3 = new Button();
private JSeparator jSeparator2 = new JSeparator();
private JLabel jLabel4 = new JLabel();
private JLabel jLabel5 = new JLabel();
private JLabel jLabel6 = new JLabel();
private JLabel jLabel7 = new JLabel();
private JLabel jLabel8 = new JLabel();
private JEditorPane textSalario = new JEditorPane();
private JEditorPane textQuincena = new JEditorPane();
private JEditorPane textTransporte = new JEditorPane();
private JEditorPane textTotalDevengado = new JEditorPane();
private JLabel jLabel9 = new JLabel();
private JLabel jLabel10 = new JLabel();
private JLabel jLabel11 = new JLabel();
private JLabel jLabel12 = new JLabel();
private JEditorPane textPension = new JEditorPane();
private JEditorPane textSalud = new JEditorPane();
private JEditorPane textFSP = new JEditorPane();
private JEditorPane textTotalDescuentos = new JEditorPane();
private JLabel jLabel13 = new JLabel();
private JLabel jLabel14 = new JLabel();
private JEditorPane textPagar = new JEditorPane();
private JEditorPane textAcumuladoNomina = new JEditorPane();
public Frame1() {
try {
jbInit();
} catch (Exception e) {
e.printStackTrace();
}
}
private void jbInit() throws Exception {
this.getContentPane().setLayout( null );
this.setSize(new Dimension(565, 458));
this.setForeground(new Color(66, 132, 255));
jLabel1.setText("Codigo");
jLabel1.setBounds(new Rectangle(35, 20, 55, 15));
jLabel1.setFont(new Font("Tahoma", 0, 17));
jLabel1.setForeground(new Color(0, 0, 214));
textCodigo.setBounds(new Rectangle(90, 15, 85, 20));
textCodigo.setFont(new Font("Tahoma", 0, 14));
textCodigo.setForeground(new Color(0, 0, 214));
jLabel2.setText("Nombre");
jLabel2.setBounds(new Rectangle(195, 20, 55, 15));
jLabel2.setFont(new Font("Tahoma", 0, 17));
jLabel2.setForeground(new Color(0, 0, 214));
textNombre.setBounds(new Rectangle(260, 15, 95, 20));
textNombre.setFont(new Font("Tahoma", 0, 14));
textNombre.setForeground(new Color(0, 0, 214));
jLabel3.setText("Apellido");
jLabel3.setBounds(new Rectangle(365, 20, 55, 15));
jLabel3.setFont(new Font("Tahoma", 0, 17));
jLabel3.setForeground(new Color(0, 0, 214));
textApellido.setBounds(new Rectangle(425, 15, 103, 18));
textApellido.setFont(new Font("Tahoma", 0, 14));
textApellido.setForeground(new Color(0, 0, 214));
jSeparator1.setBounds(new Rectangle(40, 55, 475, 5));
jSeparator1.setFont(new Font("Tahoma", 0, 14));
jSeparator1.setForeground(new Color(0, 0, 214));
button1.setLabel("Adiciona Empleado");
button1.setBounds(new Rectangle(40, 70, 155, 20));
button1.setFont(new Font("Tahoma", 0, 14));
button1.setForeground(new Color(0, 0, 214));
button1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
btnDatos_actionPerformed(e);
}
});
button2.setLabel("Nomina");
button2.setBounds(new Rectangle(240, 70, 135, 20));
button2.setFont(new Font("Tahoma", 0, 14));
button2.setForeground(new Color(0, 0, 214));
button2.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
btnNomina_actionPerformed(e);
}
});
button3.setLabel("Salir");
button3.setBounds(new Rectangle(425, 70, 90, 20));
button3.setFont(new Font("Tahoma", 0, 14));
button3.setForeground(new Color(0, 0, 214));
button3.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
btnSalir_actionPerformed(e);
}
});
jSeparator2.setBounds(new Rectangle(40, 100, 475, 5));
jSeparator2.setFont(new Font("Tahoma", 0, 14));
jSeparator2.setForeground(new Color(0, 0, 214));
jLabel4.setText("RESULTADO NOMINA");
jLabel4.setBounds(new Rectangle(200, 130, 200, 15));
jLabel4.setFont(new Font("Tahoma", 1, 17));
jLabel4.setForeground(new Color(0, 0, 214));
jLabel5.setText("Salario Base");
jLabel5.setBounds(new Rectangle(45, 195, 105, 15));
jLabel5.setFont(new Font("Tahoma", 0, 17));
jLabel5.setForeground(new Color(0, 0, 214));
jLabel6.setText("Quncena");
jLabel6.setBounds(new Rectangle(45, 220, 100, 15));
jLabel6.setFont(new Font("Tahoma", 0, 17));
jLabel6.setForeground(new Color(0, 0, 214));
jLabel7.setText("Transporte");
jLabel7.setBounds(new Rectangle(45, 245, 110, 15));
jLabel7.setFont(new Font("Tahoma", 0, 17));
jLabel7.setForeground(new Color(0, 0, 214));
jLabel8.setText("Total");
jLabel8.setBounds(new Rectangle(45, 270, 34, 14));
jLabel8.setFont(new Font("Tahoma", 0, 17));
jLabel8.setForeground(new Color(0, 0, 214));
textSalario.setBounds(new Rectangle(160, 190, 103, 18));
textSalario.setFont(new Font("Tahoma", 0, 14));
textSalario.setForeground(new Color(0, 0, 214));
textQuincena.setBounds(new Rectangle(160, 215, 103, 18));
textQuincena.setFont(new Font("Tahoma", 0, 14));
textQuincena.setForeground(new Color(0, 0, 214));
textTransporte.setBounds(new Rectangle(160, 240, 103, 18));
textTransporte.setFont(new Font("Tahoma", 0, 14));
textTransporte.setForeground(new Color(0, 0, 214));
textTotalDevengado.setBounds(new Rectangle(160, 265, 103, 18));
textTotalDevengado.setFont(new Font("Tahoma", 0, 14));
textTotalDevengado.setForeground(new Color(0, 0, 214));
jLabel9.setText("Pension");
jLabel9.setBounds(new Rectangle(285, 190, 85, 15));
jLabel9.setFont(new Font("Tahoma", 0, 17));
jLabel9.setForeground(new Color(0, 0, 214));
jLabel10.setText("Salud");
jLabel10.setBounds(new Rectangle(285, 215, 40, 15));
jLabel10.setFont(new Font("Tahoma", 0, 17));
jLabel10.setForeground(new Color(0, 0, 214));
jLabel11.setText("FSP");
jLabel11.setBounds(new Rectangle(285, 240, 40, 14));
jLabel11.setFont(new Font("Tahoma", 0, 17));
jLabel11.setForeground(new Color(0, 0, 214));
jLabel12.setText("Total Parafiscales");
jLabel12.setBounds(new Rectangle(285, 265, 110, 15));
jLabel12.setFont(new Font("Tahoma", 0, 17));
jLabel12.setForeground(new Color(0, 0, 214));
textPension.setBounds(new Rectangle(405, 185, 103, 18));
textPension.setFont(new Font("Tahoma", 0, 14));
textPension.setForeground(new Color(0, 0, 214));
textSalud.setBounds(new Rectangle(405, 210, 103, 18));
textSalud.setFont(new Font("Tahoma", 0, 14));
textSalud.setForeground(new Color(0, 0, 214));
textFSP.setBounds(new Rectangle(405, 235, 103, 18));
textFSP.setFont(new Font("Tahoma", 0, 14));
textFSP.setForeground(new Color(0, 0, 214));
textTotalDescuentos.setBounds(new Rectangle(405, 260, 103, 18));
textTotalDescuentos.setFont(new Font("Tahoma", 0, 14));
textTotalDescuentos.setForeground(new Color(0, 0, 214));
jLabel13.setText("Total a Pagar");
jLabel13.setBounds(new Rectangle(45, 325, 105, 15));
jLabel13.setFont(new Font("Tahoma", 0, 17));
jLabel13.setForeground(new Color(0, 0, 214));
jLabel14.setText("Acumulado Nomina");
jLabel14.setBounds(new Rectangle(45, 360, 105, 15));
jLabel14.setFont(new Font("Tahoma", 0, 17));
jLabel14.setForeground(new Color(0, 0, 214));
textPagar.setBounds(new Rectangle(275, 315, 160, 20));
textPagar.setFont(new Font("Tahoma", 0, 14));
textPagar.setForeground(new Color(0, 0, 214));
textAcumuladoNomina.setBounds(new Rectangle(275, 350, 160, 20));
textAcumuladoNomina.setFont(new Font("Tahoma", 0, 14));
textAcumuladoNomina.setForeground(new Color(0, 0, 214));
this.getContentPane().add(textAcumuladoNomina, null);
this.getContentPane().add(textPagar, null);
this.getContentPane().add(jLabel14, null);
this.getContentPane().add(jLabel13, null);
this.getContentPane().add(textTotalDescuentos, null);
this.getContentPane().add(textFSP, null);
this.getContentPane().add(textSalud, null);
this.getContentPane().add(textPension, null);
this.getContentPane().add(jLabel12, null);
this.getContentPane().add(jLabel11, null);
this.getContentPane().add(jLabel10, null);
this.getContentPane().add(jLabel9, null);
this.getContentPane().add(textTotalDevengado, null);
this.getContentPane().add(textTransporte, null);
this.getContentPane().add(textQuincena, null);
this.getContentPane().add(textSalario, null);
this.getContentPane().add(jLabel8, null);
this.getContentPane().add(jLabel7, null);
this.getContentPane().add(jLabel6, null);
this.getContentPane().add(jLabel5, null);
this.getContentPane().add(jLabel4, null);
this.getContentPane().add(jSeparator2, null);
this.getContentPane().add(button3, null);
this.getContentPane().add(button2, null);
this.getContentPane().add(button1, null);
this.getContentPane().add(jSeparator1, null);
this.getContentPane().add(textApellido, null);
this.getContentPane().add(jLabel3, null);
this.getContentPane().add(textNombre, null);
this.getContentPane().add(jLabel2, null);
this.getContentPane().add(textCodigo, null);
this.getContentPane().add(jLabel1, null);
}
private void btnDatos_actionPerformed(ActionEvent e) {
int i = 0, codigo=0, salario=0;
String cadena, nombre, apellido;
cadena = JOptionPane.showInputDialog("CODIGO EMPLEADO");
codigo = Integer.parseInt(cadena);
nombre = JOptionPane.showInputDialog("NOMBRE EMPLEADO");
apellido = JOptionPane.showInputDialog("APELLIDO EMPLEADO");
cadena = JOptionPane.showInputDialog("SALARIO DEL EMPLEADO");
salario = Integer.parseInt(cadena);
empleado[i] = new Empleado();
empleado[i].asignarEmpleado(codigo, nombre, apellido,salario);
mostrar(i);
i++;
}
private void btnNomina_actionPerformed(ActionEvent e) {
int i=0;
String cadena =JOptionPane.showInputDialog("Digite los días laborados por el empleado");
empleado[i].calcularQuincena(Integer.parseInt(cadena));
empleado[i].calcularAuxTransporte(Integer.parseInt(cadena));
empleado[i].calcularTotalDevengado();
empleado[i].calcularSalud(Integer.parseInt(cadena));
empleado[i].calcularPension(Integer.parseInt(cadena));
empleado[i].calcularFSP(Integer.parseInt(cadena));
empleado[i].calcularTotalDescuentos();
empleado[i].calcularTotalPagar();
//empresa.calcularTotalNomina(empleado[i].darTotalPagar());
mostrar(i);
i++;
}
public void mostrar(int i)
{
DecimalFormat df = ( DecimalFormat )NumberFormat.getInstance( );
df.applyPattern( "$###,##0.##" );
textCodigo.setText(String.valueOf(empleado[i].getCodigo()));
textNombre.setText(empleado[i].getNombreEmpleado());
textApellido.setText(empleado[i].getApeEmpleado());
textSalario.setText(df.format(empleado[i].getSalario()));
textQuincena.setText(df.format(empleado[i].getQuincena()));
textTransporte.setText(df.format(empleado[i].getAuxTrans()));
textTotalDevengado.setText(df.format(empleado[i].getTotalDevengado()));
textSalud.setText(df.format(empleado[i].getSalud()));
textPension.setText(df.format(empleado[i].getPension()));
textFSP.setText(df.format(empleado[i].getFSP()));
textTotalDescuentos.setText(df.format(empleado[i].getTotalDescuentos()));
textPagar.setText(df.format(empleado[i].getTotalPagar()));
//acumula el total a pagar del empleado utilizando el metodo calcularTotalNomina de Empresa
empresa.calcularTotalNomina(empleado[i].getTotalPagar());
//Asigna al textbox el total que se acumula mediante el método darTotalNomina
textAcumuladoNomina.setText(df.format(empresa.getTotalNomina()));
}
private void btnSalir_actionPerformed(ActionEvent e) {
dispose();
}
public static void main(String args[]) {
EventQueue.invokeLater(new Runnable() {
public void run() {
new Frame1().setVisible(true);
}
});
}
}
y este es el frame1. la parte grafica es parecida, este código funciona perfecto, desede ahí me he estado guiando.
Gracias nuevamente.
estare en contacto el dia de mañana nuevamente.