View the step-by-step solution to:

# pentadeca class. i did little but i cant get the answer i want. can you check my algorithm, and tell me why it is not working. my algorithm:

pentadeca class. i did little but i cant get the answer i want. can you check my algorithm, and tell me why it is not working.

my algorithm:

package ppppp;

private String pvalue;

private int intValue;

pvalue = "0";

intValue = 0;

}

private boolean check(String val){

for(int i = 0;i<val.length();i++){

switch(val.charAt(i)){

case '-':

if(i != 0)return false;

case '0':

case '1':

case '2':

case '3':

case '4':

case '5':

case '6':

case '7':

case '8':

case '9':

case 'A':

case 'B':

case 'C':

case 'D':

case 'E':break;

default:return false;

}

}

return true;

}

private int toIntVal(char val){

switch(val){

case '-':return -1;

case '0':return 0;

case '1':return 1;

case '2':return 2;

case '3':return 3;

case '4':return 4;

case '5':return 5;

case '6':return 6;

case '7':return 7;

case '8':return 8;

case '9':return 9;

case 'A':return 10;

case 'B':return 11;

case 'C':return 12;

case 'D':return 13;

case 'E':return 14;

}

return -2;

}

private int pToInt(String val){

int value = 0;

int cval = 0;

int st = 0;

int ind = val.length()-1;

for(int i = 0;i<ind;i++){

cval = toIntVal(val.charAt(i));

if(cval == -1){

st = 1;

continue;

}

value = value + (int)Math.pow(15,i)*cval;

}

if(st == 1){

value = value * (-1);

}

return value;

}

this();

if(check(val)){

intValue = pToInt(val);

pvalue = val;

}

}

private String iToPval(int val){

String s = "";

if(val < 0){

s = "-"+s;

}

int pv=0;

while(val != 0){

pv = val%15;

if(pv <= 9){

s = pv + s;

}else{

switch(pv){

case 10:s = "A"+s;break;

case 11:s = "B"+s;break;

case 12:s = "C"+s;break;

case 13:s = "D"+s;break;

case 14:s = "E"+s;break;

}

}

val = val/15;

}

return s;

}

intValue = val;

pvalue = iToPval(val);

}

}

public void set(String val){

if(check(val)){

intValue = pToInt(val);

pvalue = val;

}

}

public void set(int val){

intValue = val;

pvalue = iToPval(val);

}

intValue = p.toInt();

pvalue = p.toString();

}

return this;

}

public int toInt(){

return intValue;

}

}

}

}

}

}

}

}

}

}

}

}

}

if(intValue == p.toInt()){

return true;

}

return false;

}

public String toString(){

return pvalue;

}

}

//public static void main(String[] args) {

// System.out.println(p.toInt());

// System.out.println(p);

my demo

package ppppp;

{

public static void main(String[] args)

{

else

System.out.println (Pentadeca1 + " + " + Pentadeca2 + " is: " +

System.out.println (Pentadeca1 + " - " + Pentadeca2 + " is: " +

System.out.println (Pentadeca1 + " * " + Pentadeca2 + " is: " +

System.out.println (Pentadeca1 + " / " + Pentadeca2 + " is: " +

System.out.println ();

int number = 6;

System.out.println ("using the integer " + number + " as the argument "

+

"to the math operators ");

System.out.println (Pentadeca1 + " + " + number + " is: " + Pentadeca4);

System.out.println (Pentadeca1 + " - " + number + " is: " + Pentadeca5);

System.out.println (Pentadeca1 + " * " + number + " is: " + Pentadeca6);

System.out.println (Pentadeca1 + " / " + number + " is: " + Pentadeca7);

String value = "6p";

System.out.println ("using the String " + """ + value + """ + " as the argument " + "to the math operators ");

System.out.println (Pentadeca1 + " + " + value + " is: " + Pentadeca4);

System.out.println (Pentadeca1 + " - " + value + " is: " + Pentadeca5);

System.out.println (Pentadeca1 + " * " + value + " is: " + Pentadeca6);

System.out.println (Pentadeca1 + " / " + value + " is: " + Pentadeca7);

}

}

//123p + 126p is: 249p

//123p - 126p is: -3p

//123p * 126p is: 14E43p

//123p / 126p is: 0

//using the integer 6 as the argument to the math operators

//123p + 6 is: 129p

//123p - 6 is: 11Cp

//123p * 6 is: 6D3p

//123p / 6 is: 2Dp

//using the String "6p" as the argument to the math operators

//123p + 6p is: 129p

//123p - 6p is: 11Cp

//123p * 6p is: 6D3p

//123p / 6p is: 2Dp

### Why Join Course Hero?

Course Hero has all the homework and study help you need to succeed! We’ve got course-specific notes, study guides, and practice tests along with expert tutors.

### -

Educational Resources
• ### -

Study Documents

Find the best study resources around, tagged to your specific courses. Share your own to gain free Course Hero access.

Browse Documents