Get Your If's Straight, Man!

Let's take this method in Java:

1
2
3
4
5
6
7
public Integer getValueToPay(Client c){
    if (c.Age >= 60) {
        return ticket.getValue(true);
    } else {
        return ticket.getValue(false);
    }
}

Considering that the object ticket belongs to the same class as this method and it has a method getValue(Boolean discount) , what is the minimum number of keywords that we need to use in the function body to express the exact same function?

  • Clarification: return , if , else are considered keywords.
1 2 3 4

This section requires Javascript.
You are seeing this because something didn't load right. We suggest you, (a) try refreshing the page, (b) enabling javascript if it is disabled on your browser and, finally, (c) loading the non-javascript version of this page . We're sorry about the hassle.

1 solution

Kristofer Sokk
Apr 21, 2016

We can express the function as

1
2
3
public Integer getValueToPay(Client c){
   return ticket.getValue(c.Age>=60);
}

plus a semicolon :)

Arjen Vreugdenhil - 5 years, 1 month ago

0 pending reports

×

Problem Loading...

Note Loading...

Set Loading...