How to use nested if for this kind of problems:
if the object was Student and GPA greater than something else if GPA is less than..
else if the object was GradStudent and GPA greater than something else if GPA is less than..
if(first condition && second condition)
else //second condition
else if (first condition && second condition)
and so on.
this is my code but its not working
if (person instanceof Student && ((Student) person).calculateGPA() > 4.5) {
System.out.print("This Student is above the average");
} else if (person instanceof GradStudent && ((GradStudent) person).calculateGPA() > 4.5) {
System.out.print("This GradStudent is above the average");
} else {
System.out.print("This Student is below the average");
} else {
System.out.print("This GradStudent is below the average");
}
Aucun commentaire:
Enregistrer un commentaire