Why my if and else if block is not running in my java code? Here i given software engineering as input but web developer is getting printed. but actually software engineering only should be printed. Here if and else if condition is not working in setRole method. Can anyone help to sort this out?
public class MyClass{
String education;
String role;
Scanner sc=new Scanner(System.in);
//Getters
public String getEducation(){
return education;
}
public String getRole(){
return role;
}
//Setters
public void setEducation(String newEducation){
this.education=newEducation;
}
public void setRole(String newRole){
this.role=newRole;
}
//Getting input from the user
public void enterEducation(){
System.out.println("Enter your education:");
setEducation(sc.nextLine());
}
public void enterRole(){
String[] arrayrole={"CEO","Web developer","Software engineer"};
if(education=="software engineering"){
setRole(arrayrole[2]);
}
else if(education=="MBA"){
setRole(arrayrole[0]);
}
else{
setRole(arrayrole[1]);
}
}
public void play(){
enterEducation();
enterRole();
}
public void About(){
System.out.print("Your education is "+education+
". so,Your job role is "+role);
}
public static void main(String[] args){
MyClass p=new MyClass();
p.play();
p.About();
}
}
Aucun commentaire:
Enregistrer un commentaire