Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Design, by creating a UML diagram, a class named MyInteger. The class contains: An int data field named value that stores the int value represented

Design, by creating a UML diagram, a class named MyInteger. The class contains:

An int data field named value that stores the int value represented by this object.

A constructor that creates a MyInteger object with the passed int value.

A get method that returns the int value.

The instance methods isEven(), isOdd(), and isPrime() that return true if the value in this object is even, odd, or prime, respectively.

The static methods isEven(int), isOdd(int), and isPrime(int) that return true if the specified value is even, odd, or prime, respectively.

The static methods isEven(MyInteger), isOdd(MyInteger), and isPrime(MyInteger) that return true if the specified value is even, odd, or prime, respectively.

The instance methods equals(int) and equals(MyInteger) that return true if the value in this object is equal to the specified value.

A static method parseInt(char[]) that converts an array of numeric characters to an int value.

A static method parseInt(String) that converts a string into an int value.

Here is MyInteger Class:

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

If there is a better code based on what I just posted and the question, then i'd appreciate it.

At this point, I have trouble to create following intructions in the TestMyInteger.java

The instructions are as follows:

Once your UML diagram is complete implement the class naming the Java file MyInteger.java. 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.

In the end, I would likke a code that prints out like this based on the assignment.

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 Sring data of 3539

Testing parseInt(char[]): 3539

Testing parseInt(String)Passing: 3539

Overall the output of whenn the MyIntegerTester.java is completed should like something like that above. I would also like screenshots if possible of the current programs being run

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

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Spatial Database Systems Design Implementation And Project Management

Authors: Albert K.W. Yeung, G. Brent Hall

1st Edition

1402053932, 978-1402053931

More Books

Students also viewed these Databases questions

Question

Differentiate between HR metrics and HR analytics.

Answered: 1 week ago