Write a Heptadeca class that encapsulates a Heptadeca numbervalue. A Heptadeca number is one with 17 digits: 0, 1, 2, 3, 4, 5,6, 7, 8, 9, A, B, C, D, E, F, G. The methods the class has are:public void read(), public void set(String), public void set(int),public void set(Heptadeca),public Heptadeca get(), public Heptadecaadd(Heptadeca), public Heptadeca subtract(Heptadeca), publicHeptadeca multiply(Heptadeca), public Heptadeca divide(Heptadeca),public Heptadeca add(int), public Heptadeca subtract(int), publicHeptadeca multiply(int), public Heptadeca divide(int), publicHeptadeca add(String), public Heptadeca subtract(String), publicHeptadeca multiply(String), public Heptadeca divide(String), publicboolean equals(Heptadeca), and public String toString(). Writeprivate methods to check for valid character input, remove the baseh character and set the sign. Your class must consider bothpositive and negative values. Your class should have at least 3constructors: a default constructor, an explicit constructor withan integer argument and an explicit constructor with a Stringargument. I will provide a main program as the demo. Recall thenature of numbers and their construction. 13710 is 1 * 102 + 3 *101 + 7 * 100 . In the same way 1A917 would be 1 * 172 + 10* 171 +9 * 170 . Given the decimal number 13710 the digits can bedetermined using the integer operators / and %. 137 % 10 gives the7, 137/10 gives 13. 13%10 gives 3 and 13/10 gives 1. 1%10 gives 1and 1/10 gives 0. The digits base 10 of 137 are 1, 3, 7. The number13710 converted to base 5 would be 137%5 that gives 2, 137/5 gives27. 27%5 gives 2, 27/5 gives 5. 5%5 gives 0, 5/5 gives 1. 1%5 gives1 and 1/5 gives 0. This gives the base 5 number 10225. 13710converted to base 17 would be 137%17 gives 1, 137/17 gives 8. 8%17gives 8 and 8/17 gives 0. The number 13710 is therefore 8117.
Here is the demo:
public classHeptadecaDemo
{
public static void main(String[] args)
{
Heptadeca Heptadeca1 = newHeptadeca (“123h”);
Heptadeca Heptadeca2 = newHeptadeca (“126h”);
Heptadeca Heptadeca9 = newHeptadeca (“14A9h”);
Heptadeca Heptadeca4, Heptadeca5,Heptadeca6, Heptadeca7;
Heptadeca hendeca8 = newHeptadeca(1999);
System.out.println (“Hendeca numberhendeca8: ” + hendeca8);
System.out.println (“First Hendecanumber: ” + Heptadeca1);
System.out.println (“Second Hendecanumber: ” + Heptadeca2);
if(Heptadeca1.equals(Heptadeca2))
System.out.println (“hendeca1 and hendeca2 are equal.”);
else
System.out.println (“hendeca1 and hendeca2 are NOT equal.”);
Heptadeca4 =Heptadeca1.add(Heptadeca2);
Heptadeca5 =Heptadeca1.subtract(Heptadeca2);
Heptadeca6 =Heptadeca1.multiply(Heptadeca2);
Heptadeca7 =Heptadeca1.divide(Heptadeca2);
System.out.println (Heptadeca1 + “+ ” + Heptadeca2 + ” is: ” + Heptadeca4);
System.out.println (Heptadeca1 + “- ” + Heptadeca2 + ” is: ” + Heptadeca5);
System.out.println (Heptadeca1 + “* ” + Heptadeca2 + ” is: ” + Heptadeca6);
System.out.println (Heptadeca1 + “/ ” + Heptadeca2 + ” is: ” + Heptadeca7);
System.out.println ();
int number = 6;
System.out.println (“using theinteger ” + number + ” as the argument ” +
“to the math operators “);
Heptadeca4 =Heptadeca1.add(number);
Heptadeca5 =Heptadeca1.subtract(number);
Heptadeca6 =Heptadeca1.multiply(number);
Heptadeca7 =Heptadeca1.divide(number);
System.out.println (Heptadeca1 + “+ ” + number + ” is: ” + Heptadeca4);
System.out.println (Heptadeca1 + “- ” + number + ” is: ” + Heptadeca5);
System.out.println (Heptadeca1 + “* ” + number + ” is: ” + Heptadeca6);
System.out.println (Heptadeca1 + “/ ” + number + ” is: ” + Heptadeca7);
String value = “6h”;
System.out.println (“using theString ” + “”” + value + “”” + ” as the argument ” +
“to the math operators “);
Heptadeca4 =Heptadeca1.add(value);
Heptadeca5 =Heptadeca1.subtract(value);
Heptadeca6 =Heptadeca1.multiply(value);
Heptadeca7 =Heptadeca1.divide(value);
System.out.println (Heptadeca1 + “+ ” + value + ” is: ” + Heptadeca4);
System.out.println (Heptadeca1 + “- ” + value + ” is: ” + Heptadeca5);
System.out.println (Heptadeca1 + “* ” + value + ” is: ” + Heptadeca6);
System.out.println (Heptadeca1 + “/ ” + value + ” is: ” + Heptadeca7);
}
}
Here is the output:
Heptadeca number heptadeca8: 6FAh
First Heptadeca number: 123h
Second Heptadeca number: 126h
heptadeca1 and heptadeca2 are NOT equal.
123h + 126h is: 249h
123h – 126h is: -3h
123h * 126h is: 14E21h
123h / 126h is: 0
using the integer 6 as the argument to the math operators
123h + 6 is: 129h
123h – 6 is: 11Eh
123h * 6 is: 6D1h
123h / 6 is: 33h
using the String “6h” as the argument to the math operators
123h + 6h is: 129h
123h – 6h is: 11Eh
123h * 6h is: 6D1h
123h / 6h is: 33h
THANKS
Expert Answer
Answer to Write a Heptadeca class that encapsulates a Heptadeca number value. A Heptadeca number is one with 17 digits: 0, 1, 2, 3…