Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

*JAVA* Design a class named MyInteger. The class contains: An intdata field named valuethat stores the intvalue represented by this object. A constructor that creates

*JAVA* Design a class named MyInteger. The class contains:

An intdata field named valuethat stores the intvalue represented by this object.

A constructor that creates a MyIntegerobject for the specified intvalue.

A getmethod that returns the intvalue

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

Static methods isEven(int), isOdd(int), and isPrime(int)that return trueif the specified value is even, odd, or prime, respectively.

Static methods isEven(MyInteger), isOdd(MyInteger), and isPrime(MyInteger)that return trueif the specified value is even, odd, or prime, respectively.

Methods equals(int)and equals(MyInteger)that return trueif 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 intvalue.

A static method parseInt(String)that converts a string into an intvalue.

Draw the UML diagram for the class. Implement the class. Write a client program that tests all methods in the class.

Coding: (main testing part provided)

publicclassExercise10_03 {

publicstaticvoidmain(String[] args) {

MyInteger n1 = newMyInteger(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));

char[] chars = {'3', '5', '3', '9'};

System.out.println(MyInteger.parseInt(chars));

String s = "3539";

System.out.println(MyInteger.parseInt(s));

MyInteger n2 = newMyInteger(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));

}

}

classMyInteger {

// Implement your class here

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

How do members envision the ideal team?

Answered: 1 week ago

Question

Has the team been empowered to prioritize the issues?

Answered: 1 week ago

Question

Have issues been prioritized?

Answered: 1 week ago