Question: Java question. Design a class named MyInteger. The class contains: An int data field named 'value' that stores the int value represented by this object.

Java question.

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.

Methods isEven(), isOdd(), and isPrime() that return true if the value is even, odd, or prime, respectively.

Static methods is Even(MyInteger), is Odd(MyInteger), and isPrime(MyInteger) that return true if the

specified value is even, odd, or prime, respectively.

Static methods isEven (MyInteger), isOdd (MyInteger), and 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 doubleInteger (int) that doubles the specified value. The method returns an integer value.

A static method sumIntegers (int[ ] ) that adds up all the values with an array and returns integer value of the sum of integers.

Question 1 Implement your class and test with the following code using your implementation. (7points)

public class ProjectTest { public static void main(String[] args) {

MyInteger n1 = new MyInteger(5); System.out.println("n1 is even? " + n1.isEven()); System.out.println("n1 is prime? " + n1.isPrime()); System.out.println("15 is prime? " + MyInteger.isPrime(15));

int[] numbers = {3, 5, 3, 9}; System.out.println("The sum of the arrays is " + MyInteger.sumIntegers(numbers));

int num = 83; System.out.println("Double " + num + " is eaqual to " + MyInteger.doubleInteger(num));

MyInteger n2 = new MyInteger(24); System.out.println("n2 is odd? " + n2.isOdd()); System.out.println("45 is odd? " + MyInteger.isOdd(45)); System.out.println("n1 is equal to n2? " + n1.equals(n2)); System.out.println("n1 is equal to 5? " + n1.equals(5));

} }

class MyInteger { // Implement your class here  

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!