I got an error calling the method, the error that shows me is the following one. I want to call the method, but i get an error. Sorry i’m a begginer. If you can help me, ‘ll be very grateful, i really don’t know what to do. I’m getting the error, creating the the object to call the method.
`
package Scooters;
import java.util.Scanner;
public class Empleado {
String nombre, genero;
int aniodenacimiento, edad;
public void edad(){
if(aniodenacimiento >= 18){
System.out.println("Es mayor de edad");
}}
public void sexo(){
if (genero == "Masculino"){
System.out.println("Es hombre");
}
else if(genero == "Femenino"){
System.out.println("Es mujer");
}
else if(genero == "Otro"){
System.out.println("No binario");
}
else{
System.out.println("No tiene genero");
}
}
public void vacio(){
if(nombre == ""){
System.out.println("NO HA INGRESADO NOMBRE");
}
}
public void pedirDatos(){
Scanner sc = new Scanner(System.in);
System.out.println("Ingrese su nombre");
nombre = sc.nextLine();
System.out.println("Ingrese su genero");
genero = sc.nextLine();
System.out.println("Cuántos años tiene");
edad = sc.nextInt();
}
}
`
`
public class Principal {
public static void main(String[] args) {
obj ob = new obj();
ob.pedirDatos();
ob.edad();
ob.sexo();
ob.vacio();
}
}
`
I you can help me i’ll be very grateful, this is my second question in the forum.
>Solution :
You didn’t create an Empleado object:
Empleado obj = new Empleado();
// if you're in the same package you can set the attributes nombre, genero, ...
// but I'd suggest writing a constructor for that