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!
About Question enthuware.ocpjp.v8.2.1866 :
Moderator: admin
-
- Posts: 7
- Joined: Thu Mar 16, 2017 7:44 am
- Contact:
-
- Site Admin
- Posts: 10388
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocpjp.v8.2.1866 :
That is correct and that is why option 2 is correct. Note that the problem statement says, "when applied independent of each other".
-
- Posts: 8
- Joined: Thu Dec 07, 2017 4:43 am
- Contact:
Re: About Question enthuware.ocpjp.v8.2.1866 :
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 !!!
-
- Site Admin
- Posts: 10388
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocpjp.v8.2.1866 :
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.
-
- Posts: 1
- Joined: Thu Jan 24, 2019 5:37 am
- Contact:
Re: About Question enthuware.ocpjp.v8.2.1866 :
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);
}
}
Thank you!
Last edited by admin on Fri Mar 01, 2019 9:30 am, edited 1 time in total.
Reason: Please put code within [code] [/code]
Reason: Please put code within [code] [/code]
-
- Site Admin
- Posts: 10388
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocpjp.v8.2.1866 :
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.
Who is online
Users browsing this forum: No registered users and 7 guests