quick one: how can i put an if in a return
posted 11 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
this gives me error cause the compiler is expecting a return out the curly brackets not inside
code is emotional
posted 11 years ago
-
1 -
-
Number of slices to send:Optional 'thank-you' note:
-
-
You need to provide a return statement for all termination points out of the method. In your example you have not provided a return statement for when the if condition is false, i.e. OffOven is not less than 3.
As a side note: Java coding convention has method names and variable names as camelCase. So your syntax should be:
As a side note: Java coding convention has method names and variable names as camelCase. So your syntax should be:
Tim Driven Development | Test until the fear goes away
posted 11 years ago
HI Tim thanks this is clear but still cannot grasp this other aspect
let's imagine instead of a getter I want to evolve a setter in the program like that, into a routine that if the value is lower than 6 want the setter to go back to the Scanner function and ask again " what is the lenght of the pencil" take again the value and repeat the test, somebody suggested me that the goto in Java should be substitued by the while but in the case i need to use setter and getters to protect important functions, how I can simulate this goto?
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Tim Cooke wrote:
HI Tim thanks this is clear but still cannot grasp this other aspect
let's imagine instead of a getter I want to evolve a setter in the program like that, into a routine that if the value is lower than 6 want the setter to go back to the Scanner function and ask again " what is the lenght of the pencil" take again the value and repeat the test, somebody suggested me that the goto in Java should be substitued by the while but in the case i need to use setter and getters to protect important functions, how I can simulate this goto?
code is emotional
posted 11 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
In a program where you want to do something "once or more" times then you'd use a do/while loop. So to ask the user for the pencil length repeatedly until length is greater than 6 you'd say:
Of course I am expecting an int to be entered and am making no attempt to handle any other type of input.
Of course I am expecting an int to be entered and am making no attempt to handle any other type of input.
Tim Driven Development | Test until the fear goes away
posted 11 years ago
Dear Tim, you are really kind BUT there is a big reason of disappointment from my side, I am hypothesizing that the function<6 is really serious so should be encapsulated, inside a private class in a way that nobody per mistake could change it. it is not this the function of getters and setters?
thank you again anyway
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Tim Cooke wrote:In a program where you want to do something "once or more" times then you'd use a do/while loop. So to ask the user for the pencil length repeatedly until length is greater than 6 you'd say:
Dear Tim, you are really kind BUT there is a big reason of disappointment from my side, I am hypothesizing that the function<6 is really serious so should be encapsulated, inside a private class in a way that nobody per mistake could change it. it is not this the function of getters and setters?
thank you again anyway
code is emotional
posted 11 years ago
-
1 -
-
Number of slices to send:Optional 'thank-you' note:
-
-
The Sun coding conventions guide, which seems to have disappeared, frowned on returns in if statements. They suggestYou need to be careful with the ?: operator because it has low precedence and associates to the right, so it is slightly awkward to use. Obviously I don't know whether 99999 is the correct value.
posted 11 years ago
-
1 -
-
Number of slices to send:Optional 'thank-you' note:
-
-
You could encapsulate that rule out easily enough in a couple of ways. If you only need that rule inside this particular class then you could extract it as a private method like so:
Of if you're going to need that rule to be available to other classes then you can extract it into it's own class like so:
Getters and setters are mutation and access methods that simple get or set the value of a class member. Your method that decides whether some int is less that 6 is not a setter or a getter, it's just a function.
Of if you're going to need that rule to be available to other classes then you can extract it into it's own class like so:
Getters and setters are mutation and access methods that simple get or set the value of a class member. Your method that decides whether some int is less that 6 is not a setter or a getter, it's just a function.
Tim Driven Development | Test until the fear goes away
posted 11 years ago
-
1 -
-
Number of slices to send:Optional 'thank-you' note:
-
-
If you want to put the validation inside the setter then the setter will have to throw an exception if an invalid value is passed ine.g.
You would then have to catch this exception in the loop where you call the setter.
You would then have to catch this exception in the loop where you call the setter.
Joanne
| Drove my Chevy to the levee but the levee was dry. A wrung this tiny ad and it was still dry. Paul Wheaton's 16th Kickstarter: Gardening playing cards for gardeners and homesteaders https://coderanch.com/t/889615/Paul-Wheaton-Kickstarter-Gardening-playing |












