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

THESE ARE THE INSTRUCTIONS, but what I need is the private int convert(String va

ID: 3560251 • Letter: T

Question

THESE ARE THE INSTRUCTIONS, but what I need is the private int convert(String val) and String toString in an easy way

private int convert(String val)
   {
       val = val.toUpperCase();
       val = val.replaceAll("T", "").trim();
       int result = 0;
       for (int i = 0; i < val.length(); i++)
       {
           char ch = val.charAt(i);
           if (ch >= '0' && ch <= '9')
               result = result * 14 + ch - '0';
           else if (ch >= 'A' && ch <= 'D')
               result = result * 14 + ch - 'A' + 10;
       }
       if (val.startsWith("-"))
           result = -result;
       return result;
   }

and

public String toString()
   {
       int v = Math.abs(value);
       String s = "";
       do
       {
           int dig = v % 14;
           v = v / 14;
           if (dig < 10)
           {
               s = "" + dig + s;
           }
           else
           {
               char ch = (char)('A' + dig - 10);
               s = "" + ch + s;
           }

       } while (v > 0);
       if (value < 0)
           s = "-" + s;
       s += "t";
       return s;

Write a tetradeca class that encapsulates a Tetradeca number value. A tretradeca number is one with base 14. THE USE OF ARRAYS IS NOT PERMITTED. The methods the class has are: public void read(), public void set(String), public void set(int), public void set(Tetradeca), public Tetradeca get(), public Tetradeca add(Tetradeca), public Tetradeca add(int), public Tetradeca subtract(int), public Tetradeca multiply(iny), public Tetradeca divide(int), public Tetradeca add(String), public Tetradeca subtract(String), public Tetradeca multiply (String), public Tetradeca divide(String), public boolean equals(Tetradeca), and public String toString(). Write private methods to check for valid character input, remove the base t character and set the sign. Your class must consider both positive and negative values. Your class should have at least 3 constructors: a default constructor, an explicit constructor with an integer argument and an explicit constructor with a String argument.

Explanation / Answer

private int convert(String val)
   {
       val = val.toUpperCase();
       val = val.replaceAll("T", "").trim();
       int result = 0;
       for (int i = 0; i < val.length(); i++)
       {
           char ch = val.charAt(i);
           if (ch >= '0' && ch <= '9')
               result = result * 14 + ch - '0';
           else if (ch >= 'A' && ch <= 'D')
               result = result * 14 + ch - 'A' + 10;
       }
       if (val.startsWith("-"))
           result = -result;
       return result;
   }

and

public String toString()
   {
       int v = Math.abs(value);
       String s = "";
       do
       {
           int dig = v % 14;
           v = v / 14;
           if (dig < 10)
           {
               s = "" + dig + s;
           }
           else
           {
               char ch = (char)('A' + dig - 10);
               s = "" + ch + s;
           }

       } while (v > 0);
       if (value < 0)
           s = "-" + s;
       s += "t";
       return s;