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

Write a Pentadeca class that encapsulates a Pentadeca number value. A Pentadeca

ID: 3573282 • Letter: W

Question

Write a Pentadeca class that encapsulates a Pentadeca number value. A Pentadeca number is one with base 15. 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(Pentadeca),public Pentadeca get(), public Pentadeca add(Pentadeca), public Pentadeca subtract(Pentadeca), public Pentadeca multiply(Pentadeca), public Pentadeca divide(Pentadeca), public Pentadeca add(int), public Pentadeca subtract(int), public Pentadeca multiply(int), public Pentadeca divide(int), ), public Pentadeca add(String), public Pentadeca subtract(String), public Pentadeca multiply(String), public Pentadeca divide(String), public boolean equals(Pentadeca), and public String toString(). Write private methods to check for valid character input, remove the base p 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.

Here is the skeleton of my code, it's incomplete obviously

import java.util.Scanner;
public class Pentadeca {

   public void read(){
   }

   public void set(String){

   }

   public void set(int){

   }
   public void set(Pentadeca){

   }
   public Pentadeca get(){

   }

   public Pentadeca add(Pentadeca){

   }

   public Pentadeca subtract(Pentadeca){

   }

   public Pentadeca multiply(Pentadeca){

   }
   public Pentadeca divide(Pentadeca){

   }

   public Pentadeca add(int){

   }
   public Pentadeca subtract(int){

   }
   public Pentadeca multiply(int){

   }
   public Pentadeca divide(int){

   }
   public Pentadeca add(String){

   }
   public Pentadeca subtract(String){

   }
   public Pentadeca multiply(String){

   }
   public Pentadeca divide(String){

   }
   public boolean equals(Pentadeca){

   }
   public String toString(){

   }
}

and the provided demo:

public class PentadecaDemo
{
   public static void main(String[] args)
   {
       Pentadeca Pentadeca1 = new Pentadeca ("123p");
       Pentadeca Pentadeca2 = new Pentadeca ("126p");
       Pentadeca Pentadeca4, Pentadeca5, Pentadeca6, Pentadeca7;
       Pentadeca Pentadeca8 = new Pentadeca(1999);
       System.out.println ("Pentadeca number Pentadeca8: " + Pentadeca8);
       System.out.println ("First Pentadeca number: " + Pentadeca1);
       System.out.println ("Second Pentadeca number: " + Pentadeca2);
       if (Pentadeca1.equals(Pentadeca2))
           System.out.println ("Pentadeca1 and Pentadeca2 are equal.");
       else
           System.out.println ("Pentadeca1 and Pentadeca2 are NOT equal.");
       Pentadeca4 = Pentadeca1.add(Pentadeca2);
       Pentadeca5 = Pentadeca1.subtract(Pentadeca2);
       Pentadeca6 = Pentadeca1.multiply(Pentadeca2);
       Pentadeca7 = Pentadeca1.divide(Pentadeca2);
       System.out.println (Pentadeca1 + " + " + Pentadeca2 + " is: " +
               Pentadeca4);
       System.out.println (Pentadeca1 + " - " + Pentadeca2 + " is: " +
               Pentadeca5);
       System.out.println (Pentadeca1 + " * " + Pentadeca2 + " is: " +
               Pentadeca6);
       System.out.println (Pentadeca1 + " / " + Pentadeca2 + " is: " +
               Pentadeca7);
       System.out.println ();
       int number = 6;
       System.out.println ("using the integer " + number + " as the argument "
               +
               "to the math operators ");
       Pentadeca4 = Pentadeca1.add(number);
       Pentadeca5 = Pentadeca1.subtract(number);
       Pentadeca6 = Pentadeca1.multiply(number);
       Pentadeca7 = Pentadeca1.divide(number);
       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 ");
       Pentadeca4 = Pentadeca1.add(value);
       Pentadeca5 = Pentadeca1.subtract(value);
       Pentadeca6 = Pentadeca1.multiply(value);
       Pentadeca7 = Pentadeca1.divide(value);
       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);
   }
}

My professor also mentioned this:

Recall the nature of numbers and their construction. 13710 is 1 * 102 + 3 * 101 + 7 * 100 . In the same way 1A915 would be 1 * 152 + 10* 151 + 9 * 150 . Given the decimal number 13710 the digits can be determined using the integer operators / and %. 137 % 10 gives the 7, 137/10 gives 13. 13%10 gives 3 and 13/10 gives 1. 1%10 gives 1 and 1/10 gives 0. The digits base 10 of 137 are 1, 3, 7. The number 13710 converted to base 5 would be 137%5 that gives 2, 137/5 gives 27. 27%5 gives 2, 27/5 gives 5. 5%5 gives 0, 5/5 gives 1. 1%5 gives 1 and 1/5 gives 0. This gives the base 5 number 10225. 13710 converted to base 15 would be 137%15 gives 2, 137/15 gives 9. 9%15 gives 9 and 9/15 gives 0. The number 13710 is therefore 9215

Explanation / Answer


Executable Code

import java.util.Scanner;
public class MyPentadeca
{
   
    //Declare the needed variables.
    private String pentadeca1;
    private Integer decimal1;
    private static final int BASENUM = 15;
   
    //Main().
    public static void main(String[] args)
    {
        MyPentadeca penta1 = new MyPentadeca(111);
        try
        {
            System.out.println(penta1.myadd(112));
            System.out.println(penta1.mysub(112));
        }
        catch (Exception e)
        {
            e.printStackTrace();
        };
    }
   
    //Constructor.
    public MyPentadeca(int integer1)
    {
        this.set(integer1);
    }
   
    //Constructor.
    public MyPentadeca(String string1) throws Exception
    {
        this.set(string1);
    }
   
    //Method read().
    public void read(){}
   
    //Method set().
    public void set(String string1) throws Exception
    {
        for (int i1 = 0; i1 < string1.length(); i1++)
        {
            if (Character.isDigit(string1.charAt(i1)) || (string1.charAt(i1) >= 65 && string1.charAt(i1) <= 69))
                continue;
            else
                throw new Exception("INVALID ARGUMENT");
        }
        this.pentadeca1 = string1;
        decimal1 = Integer.valueOf(pentadeca1, BASENUM);
    }
   
    //Method set().
    public void set(int integer1)
    {
        this.pentadeca1 = Integer.toString(integer1);
        decimal1 = Integer.valueOf(pentadeca1, BASENUM);
    }
   
    //Method set().
    public void set(MyPentadeca p1)
    {
        this.decimal1 = p1.mygetDecimal();
        this.pentadeca1 = Integer.toString(this.decimal1, BASENUM);
    }
   
    //Method get().
    public MyPentadeca get()
    {
        return this;
    }
   
    //Method mygetDecimal().
    public Integer mygetDecimal()
    {
        return this.decimal1;
    }
   
    //Method myadd().
    public MyPentadeca myadd(MyPentadeca p1) throws Exception
    {
        int mysum = this.decimal1 + p1.mygetDecimal();
        return new MyPentadeca(Integer.toString(mysum, BASENUM));
    }
   
    //Method mysub().
    public MyPentadeca mysub(MyPentadeca p1) throws Exception
    {
        int mydiff = this.decimal1 - p1.mygetDecimal();
        return new MyPentadeca(Integer.toString(mydiff, BASENUM));
    }
   
    //Method mymul().
    public MyPentadeca mymul(MyPentadeca p1) throws Exception
    {
        int mypro = this.decimal1 * p1.mygetDecimal();
        return new MyPentadeca(Integer.toString(mypro, BASENUM));
    }
   
    //Method mydiv().
    public MyPentadeca mydiv(MyPentadeca p1) throws Exception
    {
        int myquo = this.decimal1 / p1.mygetDecimal();
        return new MyPentadeca(Integer.toString(myquo, BASENUM));
    }
   
    //Method myadd().
    public MyPentadeca myadd(int i1) throws Exception
    {
        return this.myadd(new MyPentadeca(Integer.toString(i1, BASENUM)));
    }
   
    //Method mysub
    public MyPentadeca mysub(int i1) throws Exception
    {
        return this.mysub(new MyPentadeca(Integer.toString(i1, BASENUM)));
    }
   
    //Method mymul().
    public MyPentadeca mymul(int i1) throws Exception
    {
        return this.mymul(new MyPentadeca(Integer.toString(i1, BASENUM)));
    }
   
    //Method mydiv().
    public MyPentadeca mydiv(int i1) throws Exception
    {
        return this.mydiv(new MyPentadeca(Integer.toString(i1, BASENUM)));
    }
   
    //Method myadd().
    public MyPentadeca myadd(String s) throws Exception
    {
        return this.myadd(new MyPentadeca(s));
    }
   
    //Method mysub().
    public MyPentadeca mysub(String s) throws Exception
    {
        return this.mysub(new MyPentadeca(s));
    }
   
    //Method mymul().
    public MyPentadeca mymul(String s) throws Exception
    {
        return this.mymul(new MyPentadeca(s));
    }
   
    //Method mydiv().
    public MyPentadeca mydiv(String s) throws Exception
    {
        return this.mydiv(new MyPentadeca(s));
    }
   
    //Method equals().
    public boolean equals(MyPentadeca p1)
    {
        return this.decimal1 == p1.mygetDecimal();
    }
   
    //Method toString()
    public String toString()
    {
        return this.pentadeca1;
    }
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote