-
Notifications
You must be signed in to change notification settings - Fork 10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ExtendedInteger done. #6
base: master
Are you sure you want to change the base?
Conversation
# Conflicts: # src/main/java/school/lemon/changerequest/java/extendedinteger/ExtendedInteger.java
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
waiting for other tasks. Also pay attention on comments below.
* @param value to check | ||
* @return true if value is even, false - otherwise | ||
*/ | ||
public static boolean isEven(int value) { | ||
//TODO: implement me | ||
if ((value & 1) == 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just return your expression, there is no need for if-else
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@IgorAfanasenko I don't see any changes checked in, have you already perform commit and pushed your changes ?
* @param value to check | ||
* @return true if value is odd, false - otherwise | ||
*/ | ||
public static boolean isOdd(int value) { | ||
//TODO: implement me | ||
if ((value & 1) == 1) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same as above
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
} | ||
resultSum += result; | ||
} | ||
resultSum *= first; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You algorithm is OK, but implementation details sucks.
Try to create more valuable variable names, for example:
What do you mean with your first
variable ? In fact, you need to check the sign of int value, if it's plus or minus and multiply result by 1 or -1 respectively. So, probably variable name sign
will suite here better.
Additionally you've got j
, k
, i
indexes, but you really need only one.
Also, there is no need for 2 variables for result
you can reuse one.
But, anyway, you code do pass all the tests.
//TODO: implement me | ||
return null; | ||
|
||
char[] newChar = value.toCharArray(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What if value == null
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
if (obj == this) | ||
return true; | ||
|
||
if (obj == null) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
null check should always be the first one, as there is nothing to do if obj==null
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
if (obj == null) | ||
return false; | ||
|
||
if (!(getClass() == obj.getClass())) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's always better to avoid negation.
this part could be rewritten as: getClass() != obj.getClass()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
|
||
if (!(getClass() == obj.getClass())) | ||
return false; | ||
else { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
there is no need for else statement here, cause you always use return
return false; | ||
else { | ||
ExtendedInteger tmp = (ExtendedInteger) obj; | ||
if (tmp.value == this.value) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you can just return result of this expression: return tmp.value == this.value
No description provided.