Page 1 of 1
About Question enthuware.ocpjp.v8.2.1866 :
Posted: Wed Sep 06, 2017 4:43 am
by rolandlensink
Question:
//assume appropriate import statements
class TestClass{
public double process(double payment, int rate) {
double defaultrate = 0.10; //1
if(rate>10) defaultrate = rate; //2
class Implement{
public int apply(double data){
Function<Integer, Integer> f = x->x+(int)(x*defaultrate); //3
return f.apply((int)data); //4
}
}
Implement i = new Implement();
return i.apply(payment);
}
}
When you remove line at //2, it's already ok and not necessary to change defaultrate into rate!
Re: About Question enthuware.ocpjp.v8.2.1866 :
Posted: Wed Sep 06, 2017 4:58 am
by admin
That is correct and that is why option 2 is correct. Note that the problem statement says, "when applied independent of each other".
Re: About Question enthuware.ocpjp.v8.2.1866 :
Posted: Sat Apr 07, 2018 4:26 am
by yassine
this will change how the programme works, for instance, before modifications, the rate to be used to process the data was : either "rate" when when it is >10 and 0.1 otherwise. after modifications we will always use the "rate" even if it is lower than 10 !!!
Re: About Question enthuware.ocpjp.v8.2.1866 :
Posted: Sat Apr 07, 2018 4:39 am
by admin
That's alright because the question only expects you to make the code compile. It doesn't make any assumption about the business purpose of the code.
Re: About Question enthuware.ocpjp.v8.2.1866 :
Posted: Fri Mar 01, 2019 4:14 am
by rafo_gev
admin wrote: ↑Sat Apr 07, 2018 4:39 am
That's alright because the question only expects you to make the code compile. It doesn't make any assumption about the business purpose of the code.
Hello there!
I tried to compile this code (with options 2 and 3):
Remove code at //2.
Replace lines at //3 and //4 with:
BiFunction<Integer, Double, Integer> f = (m, n)->m+(int)(n*m);
return f.apply((int)data, defaultrate);
And the code compiled successfully:
Here is full code in the file TestClass.java
Code: Select all
package test;
import java.util.function.BiFunction;
public class TestClass{
public double process(double payment, int rate)
{
double defaultrate = 0.10; //1
class Implement{
public int apply(double data){
BiFunction<Integer, Double, Integer> f = (m, n)->m+(int)(n*m);
return f.apply((int)data, defaultrate);
}
}
Implement i = new Implement();
return i.apply(payment);
}
}
I think there is mistake in this question.
Thank you!
Re: About Question enthuware.ocpjp.v8.2.1866 :
Posted: Fri Mar 01, 2019 9:32 am
by admin
There is no mistake. The problem statement says that each option is independent. So, you need to make the changes that are given in option 3 only and not 2 and 3 together.