Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

can you add a method to this code that checks if each integer input by user is zero or not so that the output includes

can you add a method to this code that checks if each integer input by user is zero or not so that the output includes a line like so:image text in transcribed

import java.io.*;

import java.lang.*;

import java.util.Arrays;

class HugeInteger{

private int ArrayDifference[]=new int[40];

private int AddRes[]=new int[40];

private int SubRes[]=new int[40];

private boolean greaterThan;

private boolean lessThan;

private boolean equalTo;

public HugeInteger(){

}

public HugeInteger(int[] arrayDiff) {

ArrayDifference = arrayDiff;

}

public HugeInteger(boolean isLess, boolean isGreater, boolean isEqual) {

this.lessThan = isLess;

this.greaterThan = isGreater;

this.equalTo = isEqual;

}

public HugeInteger(int[] addRes, int[] subRes) {

AddRes = addRes;

SubRes = subRes;

}

public boolean isLess() {

return lessThan;

}

public boolean isGreater() {

return greaterThan;

}

public boolean isEqual() {

return equalTo;

}

public int[] getArrayDiff() {

return ArrayDifference;

}

public int[] getAddRes() {

return AddRes;

}

public int[] getSubRes() {

return SubRes;

}

public void setLess(boolean isLess) {

this.lessThan = isLess;

}

public void setGreater(boolean isGreater) {

this.greaterThan = isGreater;

}

public void setEqual(boolean isEqual) {

this.equalTo = isEqual;

}

public void setArrayDiff(int[] arrayDiff) {

ArrayDifference = arrayDiff;

}

public void setAddRes(int[] addRes) {

AddRes = addRes;

}

public void setSubRes(int[] subRes) {

SubRes = subRes;

}

public boolean EqualTo(int a[],int b[]){

equalTo=Arrays.equals(a,b);

return equalTo;

}

public boolean NotEqualTo(int a[],int b[]){

return (!Arrays.equals(a,b));

}

public boolean GreaterThan(int a[],int b[]){

for(int i=0;i

ArrayDifference[i]=a[i]-b[i];

}

for(int i=0;i

if(ArrayDifference[i]>0){

greaterThan=true;

return true;

}else if(ArrayDifference[i]==0){

continue;

}

else{

lessThan=true;

return false;

}

}

return false;

}

public boolean LessThan(int a[],int b[]){

for(int i=0;i

ArrayDifference[i]=a[i]-b[i];

}

for(int i=0;i

if(ArrayDifference[i]

lessThan=true;

return true;

}else if(ArrayDifference[i]==0){

continue;

}

else{

greaterThan=true;

return false;

}

}

return false;

}

public boolean GreaterThanOrEqualTo(int a[],int b[]){

if(greaterThan || equalTo)

return true;

else

return false;

}

public boolean LessThanOrEqualTo(int a[],int b[]){

if(lessThan || equalTo)

return true;

else

return false;

}

public String Add(int a[],int b[]){

int carry=0;

String str="";

for(int i=39;i>=0;i--){

AddRes[i]=(a[i]+b[i]+carry)%10;

carry=(a[i]+b[i])/10;

}

for(int i=0;i

str+=AddRes[i]+"";

return str;

}

public String Sub(int a[],int b[]){

String str="";

if(greaterThan){

int borrow=0;

str="";

for(int i=39;i>=0;i--){

if(a[i]

borrow=10;

a[i-1]--;

}

else {

borrow=0;

}

SubRes[i]=a[i]-b[i]+borrow;

}

}else{

int borrow=0;

str="-";

for(int i=39;i>=0;i--){

if(b[i]

borrow=10;

b[i-1]--;

}

else {

borrow=0;

}

SubRes[i]=b[i]-a[i]+borrow;

}

}

for(int i=0;i

str+=SubRes[i]+"";

return str;

}

}

import java.io.BufferedReader;

import java.io.InputStreamReader;

public class IntegerTest {

public static void main(String[] args) throws Exception

{

BufferedReader br=new BufferedReader(new InputStreamReader(System.in));

System.out.println("Enter first HugeInteger");

String Int1=br.readLine();

System.out.println("Enter second HugeInteger");

String Int2=br.readLine();

int HugeInt1[]=new int[40];

int HugeInt2[]=new int[40];

for(int i=0;i

HugeInt1[39-i]=Integer.parseInt((Int1.charAt(Int1.length()-1-i))+"");

}

for(int i=0;i

HugeInt2[39-i]=Integer.parseInt((Int2.charAt(Int2.length()-1-i))+"");

}

System.out.println();

for(int i=0;i

System.out.print(HugeInt1[i]);

System.out.println();

for(int i=0;i

System.out.print(HugeInt2[i]);

HugeInteger test=new HugeInteger();

System.out.println();

System.out.print("is Not Equal to : "+test.NotEqualTo(HugeInt1,HugeInt2));

System.out.println();

System.out.print("is Equal To : "+test.EqualTo(HugeInt1,HugeInt2));

System.out.println();

System.out.print("First HugeInteger is Greater Than second HugeInteger: "+test.GreaterThan(HugeInt1,HugeInt2));

System.out.println();

System.out.print("First HugeInteger is Less Than second HugeInteger : "+test.LessThan(HugeInt1,HugeInt2));

System.out.println();

System.out.print("First HugInteger is Greater Than Or Equal To second HugeInteger : "+test.GreaterThanOrEqualTo(HugeInt1,HugeInt2));

System.out.println();

System.out.print("First Huge Integer is Less Than Or Equal To second HugeInteger3 : "+test.LessThanOrEqualTo(HugeInt1,HugeInt2));

System.out.println();

System.out.println("Addition");

System.out.print(test.Add(HugeInt1,HugeInt2));

System.out.println();

System.out.println("Subtraction");

System.out.print(test.Sub(HugeInt1,HugeInt2));

System.out.println();

}

}

Enter first HugeInteger: 5678664476768979745343215657657657657657 Enter second HugeInteger: 68979745343215657657657657657 HugeInteger i: 5678664476768979745343215657657657657657 HugeInteger 2: 68979745343215657657657657657 Add result: 5678664476837959490686431315315315315314 Subtract result: 5678664476700000000000080080000000000000 Huge Integer 1 is zero: folse HugeInteger 2 is zero: false

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Students also viewed these Databases questions

Question

What was the positive value of Max Weber's model of "bureaucracy?"

Answered: 1 week ago

Question

Analyze the impact of labor unions on health care.

Answered: 1 week ago

Question

Assess three motivational theories as they apply to health care.

Answered: 1 week ago

Question

Discuss the history of U.S. labor unions.

Answered: 1 week ago