Question Solved1 Answer Design a java 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 get method that returns the int value. Methods isEven(), isOdd(), and isPrime() that return true if the value is even, odd, or prime, respectively. Static methods isEven(int), isOdd(int), and isPrime(int) that return true if the specified value is even, odd, or prime, respectively. Static methods isEven(MyInteger), isOdd(MyInteger), and isPrime(MyInteger) that return true if the specified value is even, odd, or prime, respectively. Methods equals(int) and equals(MyInteger) that return true if the value in the 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 Implement the class. Write a client program that tests all methods in the class.

OTHFSS The Asker Β· Computer Science

Design a java 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 get method that returns the int value.
  • Methods isEven(), isOdd(), and isPrime() that return true if the value is even, odd, or prime, respectively.
  • Static methods isEven(int), isOdd(int), and isPrime(int) that return true if the specified value is even, odd, or prime, respectively.
  • Static methods isEven(MyInteger), isOdd(MyInteger), and isPrime(MyInteger) that return true if the specified value is even, odd, or prime, respectively.
  • Methods equals(int) and equals(MyInteger) that return true if the value in the 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

Implement the class. Write a client program that tests all methods in the class.

More
See Answer
Add Answer +20 Points
Community Answer
08UFCN The First Answerer
See all the answers with 1 Unlock
Get 4 Free Unlocks by registration

//Java codeimport java.util.Objects;public class MyInteger { /** * An int data field named value * that stores the int value represented by this object. */ private int value; /** * A constructor that creates a MyInteger * object for the specified int value. */ public MyInteger(int value) { this.value = value; } /** * * @return the int value. */ public int getValue() { return value; } public boolean isEven() { return value%2==0; } public boolean isOdd() { return !isEven(); } public boolean isPrime() { for (int i = 2; i <value/2 ; i++) { if(value%i==0) return false; } return true; } //static methods public static boolean isEven(int value) { return value%2==0; } public static boolean isOdd(int value) { return value%2!=0; } public static boolean isPrime(int value) { for (int i = 2; i <value/2 ; i++) { if(value%i==0) return false; } return true; } public static boolean isEven(MyInteger integer) { return isEven(integer.value); } public static boolean isOdd(MyInteger integer) { return isOdd(integer.value); } public static boolean isPrime(MyInteger integer) { return isPrime(integer.value); } public boolean equals(MyInteger o) { return value == o.value; } public boolean equals(int value) { return this.value == value; } public static int parseInt(char[] chars) { int sum =0; int zeroAsciiValue = (int)'0'; for (char ch:chars) { int temp = (int)ch; su ... See the full answer