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

This Java program has two parts to it, which is why I put the points to 750. I\'

ID: 3557591 • Letter: T

Question

This Java program has two parts to it, which is why I put the points to 750. I've already done one part of it, but its not correct which is why I want someone to correct it. THE MOST IMPORTANT IS THE ADD METHOD, the part I have not completed.

It is a simple add method with only 5 or 6 lines of code.

The following are hints given:

It should have an if statement. This add method determines what number greater than or less than the other number, than it adds the sign. I think this should be a private method.

The code should pattern after b1=b2+b3, ex: b1= b2add(b3) (not b1=add(b2,b3).

It should add arrays and array lists.

(It has been said that this add method doesn't technically add at least until the end but focuses on the signs.)

The second one I need correcting is this: I'm supposed to find a constructor and toString method that runs the demo. But it keeps messing up.

Here is the Demo:

   import java.util.Scanner;

  

   public class BigIntDemo

   {

   public static void main(String[] args)

   {

   BigInt b1 = new BigInt("1000000");

   BigInt b2 = new BigInt("11");

   //BigInt b1 = new BigInt("+0");

   //BigInt b1 = new BigInt("-0");

   //BigInt b1 = new BigInt("5stt7");// error

   //BigInt b1 = new BigInt("+");// error

   //BigInt b1 = new BigInt("-");// error

   //BigInt b1 = new BigInt("500");

   //BigInt b1 = new BigInt("44444444445555555555666666666677777777770000000000");

   //System.out.println("this prints");

   System.out.println("b1 is " + b1); }   

}

Here is mine:

import java.util.Scanner;

public class BigInt {

   String b1;

   Scanner keyboard = new Scanner(System.in);

   int num = keyboard.nextInt();

   String value,updatedvalue="";

   public BigInt(String b1) {

       value=b1;

       if(b1.charAt(0) == '+' || b1.charAt(0) == '-') {

           if(b1.length()>1){value=b1.substring(1);}

           else {System.out.println("this contains only sign: "+b1); return;}}

       int arr[]=new int[value.length()];

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

           if(Character.isDigit(value.charAt(i))){

               arr[i] = Character.digit(value.charAt(i), 10);

           }

           else {System.out.println("this contains non numeric values: "+b1);return;}

       }

       if(arr.length>0){

       }

       for(int i=arr.length-1;i>-1;i--){

           updatedvalue+=arr[i];

       }

   }{

   if(updatedvalue!=null)System.out.println("this prints: "+updatedvalue);

  

   }}

Explanation / Answer

The add method:

void add(int x1[],int x2[])

   {
       int x[]=new int[x1.length];
       for(int i=0;i<x1.length;i++)
       {
       if(x1[i]>x2[i])
           System.out.println(x1+" is greater");
       else
          System.out.println(x2+" is greater");
       x[i]=x1[i]+x2[i];
       System.out.println("The sum of is: "+x[i]);
       }
   }

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