Question: based on the following java code i need to Create another Java file, a program named MyIntegerTester.java that tests all methods in the MyInteger class
based on the following java code i need to Create another Java file, a program named MyIntegerTester.java that tests all methods in the MyInteger class by creating a MyInteger object with a value, then calling all the methods and checking that they do what they are supposed to do. You can "wire in" the test data, no need to prompt the user for anything. One technique is to write both classes at the same time. As much as possible you implement and test one method at a time. This minimized the amount of new code you have to look at when debugging a method. Only the tester file will have main() method in it which should look like: so ultimately looking for the MyIntegerTester.java
Tests use MyInteger n1 object constructed with MyIneger(5)
Testing equals(int), n1 and 6: false
Testing equals(MyInteger), n1 and n2 = 7: false
Testing isEven(), n1 which is 5, is even? false
Testing isOdd(), n1 which is 5, is odd? true
Testing static isPrime(), n1 which is 5, is prime? true
Testing instance isPrime(), 5 is prime? true
Next two tests use char[] and String data of 3539
Testing parseInt(char[]): 3539
Testing parseInt(String)Passing: 3539
java coDE:
public class MyInteger{ private int value; public MyInteger(int v){ value=v; } public int get(){ return value; } public boolean isEven() { if (value%2==0) return true; else return false; } public boolean isOdd() { if (value%2 !=0) return true; else return false; } public boolean isPrime(){ int count=0; for(int i=1;i<=value;i++){ if(value %i==0) count++; } if(count==2) return true; else return false; } public static boolean isEven(int v){ if (v%2==0) return true; else return false; } public static boolean isOdd(int v){ if (v%2 !=0) return true; else return false; } public static boolean isPrime(int v){ int count=0; for(int i=1;i<=v;i++){ if(v %i==0) count++; } if(count==2) return true; else return false; } public static boolean isEven(MyInteger obj){ if (obj.value%2==0) return true; else return false; } public static boolean isOdd(MyInteger obj){ if (obj.value%2 !=0) return true; else return false; } public static boolean isPrime(MyInteger obj){ int count=0; for(int i=1;i<=obj.value;i++){ if(obj.value %i==0) count++; } if(count==2) return true; else return false; } public boolean equal(int v){ if (value==v) return true; else return false; } public boolean equal(MyInteger obj){ if (value==obj.value) return true; else return false; } public static int parseInt(char []str){ int num=0; for(int i=0;i
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
