Question
10.3) (The MyInteger class) Design a class named MyInteger. The class contains: * An int data field named value that stores the int value represented
10.3) (The MyInteger class) Design 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 for the specified int value. A getter method that returns the int value. * The 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 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. Draw the UML diagram for the class and then implement the class. Write a client program that tests all methods in the class. Given that the definition of a prime number is a positive integer be sure to instruct the use to only enter positive integers.
SAMPLE RUN #1
--- Prompts For Keyboard/Console/Standard Input ---
Enter a positive integer to create a MyInteger object or to move on to next part of program: Enter a positive integer to test static isXXX(int) methods or to move on to next part of program: Enter a positive integer to test static isXXX(MyInteger) methods or to move on to next part of program: Enter a the first of two positive integers to create obj2 and test obj2.equals(int) or to move on to next part of program: Enter a the second of two positive integers to test obj2.equals(int): Enter a the first of two positive integers to create obj2 and test obj2.equals(MyInteger obj3) or to move on to next part of program: Enter a the second of two positive integers to create obj3 and test obj2.equals(MyInteger obj3): Enter a positive integer that will be placed into a char[] array to demonstrate the MyInteger.parseInt(char[]): Enter a positive integer that will be placed into a String to demonstrate the MyInteger.parseInt(String):
Inputs
--- Keyboard/Console/Standard Input stdin ---
1 2 3 7 8 1 2 19 23 24 1 2 5 22 19 22 22 33 33 33 34 11 11 1 1 1 2 125 256 333 444 987
Outputs
--- Monitor/Console/Standard Output ---
Enter a positive integer to create a MyInteger object or to move on to next part of program:MyInteger obj0 = new MyInteger(1); obj0.getValue() = 1 obj0.isEven() = false obj0.isOdd() = true obj0.isPrime() = false Enter a positive integer to create a MyInteger object or to move on to next part of program:MyInteger obj0 = new MyInteger(2); obj0.getValue() = 2 obj0.isEven() = true obj0.isOdd() = false obj0.isPrime() = true Enter a positive integer to create a MyInteger object or to move on to next part of program:MyInteger obj0 = new MyInteger(3); obj0.getValue() = 3 obj0.isEven() = false obj0.isOdd() = true obj0.isPrime() = true Enter a positive integer to create a MyInteger object or to move on to next part of program:MyInteger obj0 = new MyInteger(7); obj0.getValue() = 7 obj0.isEven() = false obj0.isOdd() = true obj0.isPrime() = true Enter a positive integer to create a MyInteger object or to move on to next part of program:MyInteger obj0 = new MyInteger(8); obj0.getValue() = 8 obj0.isEven() = true obj0.isOdd() = false obj0.isPrime() = false Enter a positive integer to create a MyInteger object or to move on to next part of program:Enter a positive integer to test static isXXX(int) methods or to move on to next part of program:MyInteger.isEven(1) = false MyInteger.isOdd(1) = true MyInteger.isPrime(1) = false Enter a positive integer to test static isXXX(int) methods or to move on to next part of program:MyInteger.isEven(2) = true MyInteger.isOdd(2) = false MyInteger.isPrime(2) = true Enter a positive integer to test static isXXX(int) methods or to move on to next part of program:MyInteger.isEven(19) = false MyInteger.isOdd(19) = true MyInteger.isPrime(19) = true Enter a positive integer to test static isXXX(int) methods or to move on to next part of program:MyInteger.isEven(23) = false MyInteger.isOdd(23) = true MyInteger.isPrime(23) = true Enter a positive integer to test static isXXX(int) methods or to move on to next part of program:MyInteger.isEven(24) = true MyInteger.isOdd(24) = false MyInteger.isPrime(24) = false Enter a positive integer to test static isXXX(int) methods or to move on to next part of program:Enter a positive integer to test static isXXX(MyInteger) methods or to move on to next part of program:MyInteger obj1 = new MyInteger(1); obj1.getValue() = 1 MyInteger.isEven(obj1) = false MyInteger.isOdd(obj1) = true MyInteger.isPrime(obj1) = false Enter a positive integer to test static isXXX(MyInteger) methods or to move on to next part of program:MyInteger obj1 = new MyInteger(2); obj1.getValue() = 2 MyInteger.isEven(obj1) = true MyInteger.isOdd(obj1) = false MyInteger.isPrime(obj1) = true Enter a positive integer to test static isXXX(MyInteger) methods or to move on to next part of program:MyInteger obj1 = new MyInteger(5); obj1.getValue() = 5 MyInteger.isEven(obj1) = false MyInteger.isOdd(obj1) = true MyInteger.isPrime(obj1) = true Enter a positive integer to test static isXXX(MyInteger) methods or to move on to next part of program:MyInteger obj1 = new MyInteger(22); obj1.getValue() = 22 MyInteger.isEven(obj1) = true MyInteger.isOdd(obj1) = false MyInteger.isPrime(obj1) = false Enter a positive integer to test static isXXX(MyInteger) methods or to move on to next part of program:MyInteger obj1 = new MyInteger(19); obj1.getValue() = 19 MyInteger.isEven(obj1) = false MyInteger.isOdd(obj1) = true MyInteger.isPrime(obj1) = true Enter a positive integer to test static isXXX(MyInteger) methods or to move on to next part of program:Enter a the first of two positive integers to create obj2 and test obj2.equals(int) or to move on to next part of program:MyInteger obj2 = new MyInteger(22); obj2.getValue() = 22 Enter a the second of two positive integers to test obj2.equals(int):obj2.equals(22) = true Enter a the first of two positive integers to create obj2 and test obj2.equals(int) or to move on to next part of program:MyInteger obj2 = new MyInteger(33); obj2.getValue() = 33 Enter a the second of two positive integers to test obj2.equals(int):obj2.equals(33) = true Enter a the first of two positive integers to create obj2 and test obj2.equals(int) or to move on to next part of program:MyInteger obj2 = new MyInteger(33); obj2.getValue() = 33 Enter a the second of two positive integers to test obj2.equals(int):obj2.equals(34) = false Enter a the first of two positive integers to create obj2 and test obj2.equals(int) or to move on to next part of program:Enter a the first of two positive integers to create obj2 and test obj2.equals(MyInteger obj3) orto move on to next part of program:MyInteger obj2 = new MyInteger(11); obj2.getValue() = 11 Enter a the second of two positive integers to create obj3 and test obj2.equals(MyInteger obj3):MyInteger obj3 = new MyInteger(11); obj3.getValue() = 11 obj2.equals(obj3) = true Enter a the first of two positive integers to create obj2 and test obj2.equals(MyInteger obj3) or to move on to next part of program:MyInteger obj2 = new MyInteger(1); obj2.getValue() = 1 Enter a the second of two positive integers to create obj3 and test obj2.equals(MyInteger obj3):MyInteger obj3 = new MyInteger(1); obj3.getValue() = 1 obj2.equals(obj3) = true Enter a the first of two positive integers to create obj2 and test obj2.equals(MyInteger obj3) or to move on to next part of program:MyInteger obj2 = new MyInteger(1); obj2.getValue() = 1 Enter a the second of two positive integers to create obj3 and test obj2.equals(MyInteger obj3):MyInteger obj3 = new MyInteger(2); obj3.getValue() = 2 obj2.equals(obj3) = false Enter a the first of two positive integers to create obj2 and test obj2.equals(MyInteger obj3) or to move on to next part of program:Enter a positive integer that will be placed into a char[] array to demonstrate the MyInteger.parseInt(char[]):MyInteger obj4 = new MyInteger(MyInteger.parseInt(char []); obj4.getValue() = 125 obj4.isEven() = false obj4.isOdd() = true obj4.isPrime() = false Enter a positive integer that will be placed into a char[] array to demonstrate the MyInteger.parseInt(char[]):MyInteger obj4 = new MyInteger(MyInteger.parseInt(char []); obj4.getValue() = 256 obj4.isEven() = true obj4.isOdd() = false obj4.isPrime() = false Enter a positive integer that will be placed into a char[] array to demonstrate the MyInteger.parseInt(char[]):Enter a positive integer that will be placed into a String to demonstrate the MyInteger.parseInt(String):MyInteger obj5 = new MyInteger(MyInteger.parseInt(String); obj5.getValue() = 333 obj5.isEven() = false obj5.isOdd() = true obj5.isPrime() = false Enter a positive integer that will be placed into a String to demonstrate the MyInteger.parseInt(String):MyInteger obj5 = new MyInteger(MyInteger.parseInt(String); obj5.getValue() = 444 obj5.isEven() = true obj5.isOdd() = false obj5.isPrime() = false Enter a positive integer that will be placed into a String to demonstrate the MyInteger.parseInt(String):MyInteger obj5 = new MyInteger(MyInteger.parseInt(String); obj5.getValue() = 987 obj5.isEven() = false obj5.isOdd() = true obj5.isPrime() = false Enter a positive integer that will be placed into a String to demonstrate the MyInteger.parseInt(String):
What The Console Looks Like In An Interactive Session:
(Note: this combines standard input with standard output)
>java MyInteger Enter a positive integer to create a MyInteger object or to move on to next part of program:1 MyInteger obj0 = new MyInteger(1); obj0.getValue() = 1 obj0.isEven() = false obj0.isOdd() = true obj0.isPrime() = false Enter a positive integer to create a MyInteger object or to move on to next part of program:2 MyInteger obj0 = new MyInteger(2); obj0.getValue() = 2 obj0.isEven() = true obj0.isOdd() = false obj0.isPrime() = true Enter a positive integer to create a MyInteger object or to move on to next part of program:3 MyInteger obj0 = new MyInteger(3); obj0.getValue() = 3 obj0.isEven() = false obj0.isOdd() = true obj0.isPrime() = true Enter a positive integer to create a MyInteger object or to move on to next part of program:7 MyInteger obj0 = new MyInteger(7); obj0.getValue() = 7 obj0.isEven() = false obj0.isOdd() = true obj0.isPrime() = true Enter a positive integer to create a MyInteger object or to move on to next part of program:8 MyInteger obj0 = new MyInteger(8); obj0.getValue() = 8 obj0.isEven() = true obj0.isOdd() = false obj0.isPrime() = false Enter a positive integer to create a MyInteger object or to move on to next part of program: Enter a positive integer to test static isXXX(int) methods or to move on to next part of program:1 MyInteger.isEven(1) = false MyInteger.isOdd(1) = true MyInteger.isPrime(1) = false Enter a positive integer to test static isXXX(int) methods or to move on to next part of program:2 MyInteger.isEven(2) = true MyInteger.isOdd(2) = false MyInteger.isPrime(2) = true Enter a positive integer to test static isXXX(int) methods or to move on to next part of program:19 MyInteger.isEven(19) = false MyInteger.isOdd(19) = true MyInteger.isPrime(19) = true Enter a positive integer to test static isXXX(int) methods or to move on to next part of program:23 MyInteger.isEven(23) = false MyInteger.isOdd(23) = true MyInteger.isPrime(23) = true Enter a positive integer to test static isXXX(int) methods or to move on to next part of program:24 MyInteger.isEven(24) = true MyInteger.isOdd(24) = false MyInteger.isPrime(24) = false Enter a positive integer to test static isXXX(int) methods or to move on to next part of program: Enter a positive integer to test static isXXX(MyInteger) methods or to move on to next part of program:1 MyInteger obj1 = new MyInteger(1); obj1.getValue() = 1 MyInteger.isEven(obj1) = false MyInteger.isOdd(obj1) = true MyInteger.isPrime(obj1) = false Enter a positive integer to test static isXXX(MyInteger) methods or to move on to next part of program:2 MyInteger obj1 = new MyInteger(2); obj1.getValue() = 2 MyInteger.isEven(obj1) = true MyInteger.isOdd(obj1) = false MyInteger.isPrime(obj1) = true Enter a positive integer to test static isXXX(MyInteger) methods or to move on to next part of program:5 MyInteger obj1 = new MyInteger(5); obj1.getValue() = 5 MyInteger.isEven(obj1) = false MyInteger.isOdd(obj1) = true MyInteger.isPrime(obj1) = true Enter a positive integer to test static isXXX(MyInteger) methods or to move on to next part of program:22 MyInteger obj1 = new MyInteger(22); obj1.getValue() = 22 MyInteger.isEven(obj1) = true MyInteger.isOdd(obj1) = false MyInteger.isPrime(obj1) = false Enter a positive integer to test static isXXX(MyInteger) methods or to move on to next part of program:19 MyInteger obj1 = new MyInteger(19); obj1.getValue() = 19 MyInteger.isEven(obj1) = false MyInteger.isOdd(obj1) = true MyInteger.isPrime(obj1) = true Enter a positive integer to test static isXXX(MyInteger) methods or to move on to next part of program: Enter a the first of two positive integers to create obj2 and test obj2.equals(int) or to move on to next part of program:22 MyInteger obj2 = new MyInteger(22); obj2.getValue() = 22 Enter a the second of two positive integers to test obj2.equals(int):22 obj2.equals(22) = true Enter a the first of two positive integers to create obj2 and test obj2.equals(int) or to move on to next part of program:33 MyInteger obj2 = new MyInteger(33); obj2.getValue() = 33 Enter a the second of two positive integers to test obj2.equals(int):33 obj2.equals(33) = true Enter a the first of two positive integers to create obj2 and test obj2.equals(int) or to move on to next part of program:33 MyInteger obj2 = new MyInteger(33); obj2.getValue() = 33 Enter a the second of two positive integers to test obj2.equals(int):34 obj2.equals(34) = false Enter a the first of two positive integers to create obj2 and test obj2.equals(int) or to move on to next part of program: Enter a the first of two positive integers to create obj2 and test obj2.equals(MyInteger obj3) or to move on to next part of program:11 MyInteger obj2 = new MyInteger(11); obj2.getValue() = 11 Enter a the second of two positive integers to create obj3 and test obj2.equals(MyInteger obj3):11 MyInteger obj3 = new MyInteger(11); obj3.getValue() = 11 obj2.equals(obj3) = true Enter a the first of two positive integers to create obj2 and test obj2.equals(MyInteger obj3) or to move on to next part of program:1 MyInteger obj2 = new MyInteger(1); obj2.getValue() = 1 Enter a the second of two positive integers to create obj3 and test obj2.equals(MyInteger obj3):1 MyInteger obj3 = new MyInteger(1); obj3.getValue() = 1 obj2.equals(obj3) = true Enter a the first of two positive integers to create obj2 and test obj2.equals(MyInteger obj3) or to move on to next part of program:1 MyInteger obj2 = new MyInteger(1); obj2.getValue() = 1 Enter a the second of two positive integers to create obj3 and test obj2.equals(MyInteger obj3):2 MyInteger obj3 = new MyInteger(2); obj3.getValue() = 2 obj2.equals(obj3) = false Enter a the first of two positive integers to create obj2 and test obj2.equals(MyInteger obj3) or to move on to next part of program: Enter a positive integer that will be placed into a char[] array to demonstrate the MyInteger.parseInt(char[]):125 MyInteger obj4 = new MyInteger(MyInteger.parseInt(char []); obj4.getValue() = 125 obj4.isEven() = false obj4.isOdd() = true obj4.isPrime() = false Enter a positive integer that will be placed into a char[] array to demonstrate the MyInteger.parseInt(char[]):256 MyInteger obj4 = new MyInteger(MyInteger.parseInt(char []); obj4.getValue() = 256 obj4.isEven() = true obj4.isOdd() = false obj4.isPrime() = false Enter a positive integer that will be placed into a char[] array to demonstrate the MyInteger.parseInt(char[]): Enter a positive integer that will be placed into a String to demonstrate the MyInteger.parseInt(String):333 MyInteger obj5 = new MyInteger(MyInteger.parseInt(String); obj5.getValue() = 333 obj5.isEven() = false obj5.isOdd() = true obj5.isPrime() = false Enter a positive integer that will be placed into a String to demonstrate the MyInteger.parseInt(String):444 MyInteger obj5 = new MyInteger(MyInteger.parseInt(String); obj5.getValue() = 444 obj5.isEven() = true obj5.isOdd() = false obj5.isPrime() = false Enter a positive integer that will be placed into a String to demonstrate the MyInteger.parseInt(String):987 MyInteger obj5 = new MyInteger(MyInteger.parseInt(String); obj5.getValue() = 987 obj5.isEven() = false obj5.isOdd() = true obj5.isPrime() = false Enter a positive integer that will be placed into a String to demonstrate the MyInteger.parseInt(String):
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started