bug in enthuware.ocpjp.v8.2.1826?

Moderator: admin

Post Reply
codemonkey
Posts: 2
Joined: Fri Jul 08, 2016 4:11 am
Contact:

bug in enthuware.ocpjp.v8.2.1826?

Post by codemonkey » 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:

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;
	}
}
Sorry if I post this question in any incorrect way and do moderate it.

admin
Site Admin
Posts: 8619
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: bug in enthuware.ocpjp.v8.2.1826?

Post by admin » Fri Jul 08, 2016 9:05 pm

The given answer is correct. Please try exactly the same code as given in the question.
If you like our products and services, please help us by posting your review here.

codemonkey
Posts: 2
Joined: Fri Jul 08, 2016 4:11 am
Contact:

Re: bug in enthuware.ocpjp.v8.2.1826?

Post by codemonkey » Sat Jul 09, 2016 2:27 am

Admin, you are right. I found my mistake. Typed

Code: Select all

grade = Optional.of("FAIL");
instead of

Code: Select all

grade.of("FAIL"); 
wich changed an output. I apologize.

Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests