bug in enthuware.ocpjp.v8.2.1826?
Posted: Fri Jul 08, 2016 4:38 am
				
				Hello,
I've compiled and run the code given in the question and got a result other then in the answer. Can you please tell me what I did wrong?
Answer applied by enthuware is:
UNKNOWN
PASS
Real result:
FAIL
PASS
My code:
Sorry if I post this question in any incorrect way and do moderate it.
			I've compiled and run the code given in the question and got a result other then in the answer. Can you please tell me what I did wrong?
Answer applied by enthuware is:
UNKNOWN
PASS
Real result:
FAIL
PASS
My code:
Code: Select all
package tests;
import java.util.Optional;
public class Test2 {
	public static void main(String[] args) {
		Optional<String> g1 = getGrade(50);
		Optional<String> g2 = getGrade(55);
		System.out.println(g1.orElse("UNKNOWN"));
		if (g2.isPresent()) {
			g2.ifPresent(x -> System.out.println(x));
		} else {
			System.out.println(g2.orElse("EMPTY"));
		}
	}
	static Optional<String> getGrade(int marks) {
		Optional<String> grade = Optional.empty();
		if (marks > 50) {
			grade = Optional.of("PASS");
		} else {
			grade = Optional.of("FAIL");
		}
		return grade;
	}
}