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
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