Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

ublic class MyInteger t * fol.oned by ù space folloved ty the 2ase follo-ed by t

ID: 3708076 • Letter: U

Question

ublic class MyInteger t * fol.oned by ù space folloved ty the 2ase follo-ed by the c.asi.g rauns bracket. .characters lo.tside the rang character crespandig t ase-111 are exerple, + For exarpie. 1, a, 5,2), retu rn "31052 Chase 101" pubtic Strinn tostring eretu n the decLMaL Vstue correspanding to this nuse assre the deciral value is st wost inteer.MA VALLE (214740347) pubtic int getCeciralaluel eturn a:be corpleted return result; * 1 ?, wie f ?11.ng ubje41 is fe lhar value Qf -urarete f U.j est * -1 if ru lus of ca1.ing object is less than ?? lus of ?ùra.ete, abject sn the ran , 1 ts in base bercing h .,p3 ram chsUe.ging pubtic int conpareToPyInteper other public woid set8selit b greturn object represtina the calling abject in base b -set base ta b an populate sta wit vstues corresconing to deciral nunker pro lded. For exarple, , then bse shud becone 5 an dats suld becose 1,.0, data bsc data- ne int in; //ta be corpltes

Explanation / Answer

Please find the code of all incomplete methods below.

CODE

======================

public void setBase(int b) {
if(b < 2)
base = 2;
else if(b > 10)
base = 10;
else  
base = b;
}

public void setDataBasic(String d) {
setBase(2);
data = new int[100]{0};
  
for(int i=0; i<d.length(); i++) {
char ch = d.charAt(i);
if(ch >= '0' && ch <= ('0' + (base-1))) {
data[i] = ch - '0';
} else {
data[i] = '0';
}
}
}

public void setDataAdvanced(String d) {
setBase(2);
data = new int[100]{0};
int k=0;
  
for(int i=0; i<d.length(); i++) {
char ch = d.charAt(i);
if(ch >= '0' && ch <= ('0' + (base-1))) {
data[k++] = ch - '0';
}
}
}

public MyInteger(int decimal, int b) {
setBase(b);
data = new int[100]{0};
int k = 0;
  
while(decimal != 0) {
data[k ++] = decimal % b;
decimal /= b;
}
  
// now, reverse the Array
for(int i=0, j=k-1; i<k/2; i++, j--) {
int t = data[i];
data[i] = data[j];
data[j] = t;
}
}
  
public String toString() {
String res = "";
for(int i=0; i<data.length; i++) {
res += data[i];
}
res += " (base " + base + " )";
return res;
}

public int getDecimalValue() {
int res = 0;
  
for(int i=0; i<data.length; i++) {
res += data[i] * Math.pow(base, i);
}
return res;
}

public int compareTo(MyInteger other) {
if(getDecimalValue() > other.getDecimalValue())
return 1;
else if(getDecimalValue() == other.getDecimalValue())
return 0;
else  
return -1;