About Question enthuware.ocpjp.v8.2.1866 :

Help and support on OCA OCP Java Programmer Certification Questions
1Z0-808, 1Z0-809, 1Z0-815, 1Z0-816, 1Z0-817

Moderator: admin

Post Reply
rolandlensink
Posts: 7
Joined: Thu Mar 16, 2017 7:44 am
Contact:

About Question enthuware.ocpjp.v8.2.1866 :

Post 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!

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

Re: About Question enthuware.ocpjp.v8.2.1866 :

Post 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".

yassine
Posts: 8
Joined: Thu Dec 07, 2017 4:43 am
Contact:

Re: About Question enthuware.ocpjp.v8.2.1866 :

Post 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 !!!

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

Re: About Question enthuware.ocpjp.v8.2.1866 :

Post 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.

rafo_gev
Posts: 1
Joined: Thu Jan 24, 2019 5:37 am
Contact:

Re: About Question enthuware.ocpjp.v8.2.1866 :

Post 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!
Last edited by admin on Fri Mar 01, 2019 9:30 am, edited 1 time in total.
Reason: Please put code within [code] [/code]

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

Re: About Question enthuware.ocpjp.v8.2.1866 :

Post 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.

Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 7 guests