The last line of the code below gives the following error: " expected
illegal start of type
package arrEmpleados does not exist"
package javaPrueba2;
import java.util.ArrayList;
class Principal {
ArrayList<Empleado> arrEmpleados = new ArrayList<Empleado>();
arrEmpleados.add(new Empleado(541000, 2400.0, 40.0, 16, 20.0, 2));
Empleado is a class in another file. That one, this one and the main are all in the package javaPrueba2 displayed in the 1st line...
The same error is returned if I just create a simple string ArrayList
ArrayList<String> arrEmpleados = new ArrayList();
arrEmpleados.add("ana"));
What's going on? I almost copied the way to do the ArrayList from here: StackOverflow: Creating an Arraylist of Objects
So if this is wrong, how should I do it?
EDIT: Per request, this is the Empleado Class:
package javaPrueba2;
public class Empleado{
int nif, horasExtra, numHijos; // horasExtra son mensuales
double sueldoBase, pagoHora, porcIRPF;
Empleado(int nif, double sueldoBase, double pagoHora, int horasExtra, double porcIRPF, int numHijos){
this.nif = nif;
this.sueldoBase = sueldoBase;
this.pagoHora = pagoHora;
this.horasExtra = horasExtra;
this.porcIRPF = porcIRPF;
this.numHijos = numHijos;
}
//Calcula el complemento por horas extras realizadas
double complemento(){
return pagoHora * horasExtra;
}
//Calcula el sueldo bruto
double bruto(){
return sueldoBase + this.complemento();
}
//Calcula las retenciones
double retenciones(){
int puntosDescuento;
double porcentajeFinal;
if (numHijos > 2){
puntosDescuento = 2;
} else puntosDescuento = 1;
porcentajeFinal = porcIRPF - puntosDescuento;
return porcentajeFinal * this.bruto() / 100;
}
}