mirror of
https://github.com/Noratrieb/UselessClasses.git
synced 2026-01-14 16:45:09 +01:00
added another useless thing thats worse than a primitive
This commit is contained in:
parent
d66e3bd0c2
commit
db2a0573e3
1 changed files with 30 additions and 0 deletions
30
src/SignedInteger.java
Normal file
30
src/SignedInteger.java
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
public class SignedInteger {
|
||||
|
||||
int n;
|
||||
boolean isNegative;
|
||||
|
||||
public SignedInteger(int n){
|
||||
isNegative = n < 0;
|
||||
this.n = Math.abs(n);
|
||||
}
|
||||
|
||||
int getValue(){
|
||||
return isNegative ? -n : n;
|
||||
}
|
||||
|
||||
void setValue(int n){
|
||||
isNegative = n < 0;
|
||||
this.n = Math.abs(n);
|
||||
}
|
||||
|
||||
void addValue(int n){
|
||||
this.n += isNegative ? -n : n;
|
||||
if(this.n < 0){
|
||||
isNegative = !isNegative;
|
||||
this.n = Math.abs(this.n);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue