added another useless thing thats worse than a primitive

This commit is contained in:
nora 2020-11-17 11:13:04 +01:00
parent d66e3bd0c2
commit db2a0573e3

30
src/SignedInteger.java Normal file
View 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);
}
}
}