# Answer to Question #16386 in Java | JSP | JSF for cord

Question #16386

in java write a program that does the following. 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 get method that returns the int value

the methods isEven(), isOdd(), and isPrime() that return true if the value of the 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 method 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.

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

the methods isEven(), isOdd(), and isPrime() that return true if the value of the 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 method 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.

Expert's answer

class MyInteger {

int value;

MyInteger(int newValue)

{

value = newValue;

}

public int getValue()

{

return value;

}

public static boolean isEven(int

n) {

return (n % 2 == 0);

}

public static boolean

isOdd(int n) {

return !isEven(n);

}

public static

boolean isPrime(int n) {

for (int f = 2; f < n / 2; f++)

{

if (n % f == 0) {

return

false;

}

}

return true;

}

public static boolean isEven(MyInteger n) {

return n.isEven();

}

public static boolean isOdd(MyInteger n) {

return

n.isOdd();

}

public static boolean isPrime(MyInteger n)

{

return n.isPrime();

}

public boolean isEven()

{

return isEven(value);

}

public boolean isOdd()

{

return isOdd(value);

}

public boolean isPrime()

{

return isPrime(value);

}

public boolean

equals(int n) {

return (value == n);

}

public

boolean equals(MyInteger n) {

return equals(n.getValue());

}

public static int parseInt(String s) {

return

Integer.parseInt(s);

}

public static int parseInt(char[] s)

{

return parseInt(new String(s));

}

}

int value;

MyInteger(int newValue)

{

value = newValue;

}

public int getValue()

{

return value;

}

public static boolean isEven(int

n) {

return (n % 2 == 0);

}

public static boolean

isOdd(int n) {

return !isEven(n);

}

public static

boolean isPrime(int n) {

for (int f = 2; f < n / 2; f++)

{

if (n % f == 0) {

return

false;

}

}

return true;

}

public static boolean isEven(MyInteger n) {

return n.isEven();

}

public static boolean isOdd(MyInteger n) {

return

n.isOdd();

}

public static boolean isPrime(MyInteger n)

{

return n.isPrime();

}

public boolean isEven()

{

return isEven(value);

}

public boolean isOdd()

{

return isOdd(value);

}

public boolean isPrime()

{

return isPrime(value);

}

public boolean

equals(int n) {

return (value == n);

}

public

boolean equals(MyInteger n) {

return equals(n.getValue());

}

public static int parseInt(String s) {

return

Integer.parseInt(s);

}

public static int parseInt(char[] s)

{

return parseInt(new String(s));

}

}

Need a fast expert's response?

Submit orderand get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

## Comments

## Leave a comment