Question: I need help with making a test program for the following code. I would like to have user to input two integers that will be
I need help with making a test program for the following code. I would like to have user to input two integers that will be tested for the following java program:
public class HugeInteger
{
private int[] intArray;
private int numDigits; // stores the number of digits in intArray
static String ss;
public HugeInteger(String s)
{
intArray = new int[40];
numDigits = 0;
// call parse(s)
parse(s);
}
public HugeInteger( )
{
this.intArray = new int[40];
this.numDigits = 0;
}
public void parse(String s)
{
// Add each digit to the arrays
// update numDigits
ss=s;
for(int i=0; i { this.intArray[i]=s.charAt(i)-'0'; System.out.print(intArray[i]+""); this.numDigits++; System.out.println(intArray[i]+" "+numDigits); } } public static HugeInteger add(HugeInteger hugeInt1, HugeInteger hugeInt2) { // Create hugeInt3 // Loop // Add digits from hugeInt1 and hugeInt2, // Store in corresponding hugeInt3 // End // // return hugeInt3 HugeInteger hugeInt3 = new HugeInteger(); for(int i=0; i { hugeInt3.intArray[i]=hugeInt1.intArray[i]+hugeInt2.intArray[i]; } String data=hugeInt3.intArray.toString(); for(int j=0; j System.out.println(hugeInt3.intArray[j]); return hugeInt3; } public static HugeInteger subtract(HugeInteger hugeInt1, HugeInteger hugeInt2) { // Create hugeInt3 // Loop // Subtract hugeInt2 digit from hugeInt1, // Store in corresponding hugeInt3 // End // // return hugeInt3 HugeInteger hugeInt3 = new HugeInteger(); for(int i=0; i {if(hugeInt1.intArray[i] >= hugeInt2.intArray[i]) hugeInt3.intArray[i]=hugeInt1.intArray[i-hugeInt2.intArray[i]]; else hugeInt3.intArray[i]=hugeInt2.intArray[i]-hugeInt1.intArray[i]; } String data=hugeInt3.intArray.toString(); for(int j=0; j System.out.println(hugeInt3.intArray[j]); return hugeInt3; } public static boolean isEqualTo(HugeInteger hugeInt1, HugeInteger hugeInt2) { // return true if the value represented by // elements of hugeInt1.intArray is equal to // value represented by elements of hughInt2.intArray for(int i=0; i System.out.println(hugeInt2.intArray[i]); int count=0; for(int i=0; i { int a1=hugeInt1.intArray[i]; int a2=hugeInt2.intArray[i]; System.out.println(a1+ ""+2); if(a1!=a2) { System.out.println(hugeInt2.intArray[i]); count++; } } System.out.println("count"+count); if(count>0) return false; else return true; } public static boolean isNotEqualTo(HugeInteger hugeInt1, HugeInteger hugeInt2) { // return true if the value represented by // elements of hugeInt1.intArray is not equal to // value represented by elements of hughInt2.intArray for(int i=0; i System.out.println(hugeInt2.intArray[i]); int count=0; for(int i=0; i { int a1=hugeInt1.intArray[i]; int a2=hugeInt2.intArray[i]; System.out.println(a1+" "+a2); if(a1 != a2) { System.out.println(hugeInt2.intArray[i]); count++; } } System.out.println("count"+count); if(count>0) return true; else return false; } public static boolean isGreaterThan(HugeInteger hugeInt1, HugeInteger hugeInt2) { // return true if the value represented by // elements of hugeInt1.intArray is greater than // value represented by elements of hughInt2.intArray int sum1=0; int sum2=0; for(int i=0;i sum1+=hugeInt1.intArray[i]; sum2+=hugeInt1.intArray[i]; } if(sum1>sum2) return true; else return false; } public static boolean isLessThan(HugeInteger hugeInt1, HugeInteger hugeInt2) { // return true if the value represented by // elements of hugeInt1.intArray is less than // value represented by elements of hughInt2.intArray int sum1=0, sum2=0; for(int i=0;i sum1+=hugeInt1.intArray[i]; sum2+=hugeInt1.intArray[i]; } if(sum1 return true; else return false; } public static boolean isGreaterThanOrEqualTo(HugeInteger hugeInt1, HugeInteger hugeInt2) { // return true if the value represented by // elements of hugeInt1.intArray is greater than or equal to // value represented by elements of hughInt2.intArray int sum1=0, sum2=0; for(int i=0; i { sum1 += hugeInt1.intArray[i]; sum2 += hugeInt1.intArray[i]; } if(sum1>sum2) return true; else return false; } public boolean isZero(HugeInteger hugeInt1 ) { // return true if the value represented by // elements of hugeInt1.intArray is 0 int count=0; for(int i=0;i { if(hugeInt1.intArray[i]==0) count++; } if(count>0) return true; else return false; } public String toString( ) { // return string representation of this object return this.toString(); } }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
