Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Design a class named MyInteger. The class contains: An int instance variable named value that stores the int value represented by the object. A constructor

Design a class named MyInteger. The class contains: An int instance variable named value that stores the int value represented by the object. A constructor that creates a MyInteger object for the specified int value. A get method that returns the int value. Static methods isEven(int), isOdd(int) and isPrime(int) that return true if the specified value is odd, even, or prime, respectively, and false otherwise. Methods isEven(), isOdd(), and isPrime() that return true if the value in this object is even, odd or prime, respectively, and false otherwise. Static methods isEven(MyInteger), isOdd(MyInteger) and isPrime(MyInteger) that return true if the value of the specified object is even, odd, or prime, respectively, and false otherwise. Method equals(int) that returns true if the value in this object is equal to the specified integer. Method equals(MyInteger) that return true if the value in this object is equal to the value in another object. Static method parseInt(char[]) that converts an array of numeric characters to an int value. Static method parseInt(String) that converts a string into an int value.

*I am using JGrasp so please make sure it is compatible *FULL QUESTION IN IMAGES BELOWimage text in transcribedimage text in transcribed

Exercise 3: Design a class named MyInteger. The class contains An int instance variable named value that stores the int value represented by the object. A constructor that creates a MyInteger object for the specified int value. A get method that returns the int value prime, respectively, and false otherwise. Methods isEven isodd0, and isPrime0 that return true if the value in this object is even, odd or prime respectively, and false otherwise Static methods isEven(MyInteger), isOdd(MyInteger and isPrime(MyInteger) that return true if the value of the specified object is even, odd, or prime, respectively, and false otherwise. Method equals (int) that returns true if the value in this object is equal to the specified integer. Method equals(MyInteger that return true if the value in this object is equal to the value in another object. Static method parselnt(charl] that converts an array ofnumeric characters to an int value Static method parselnt(String) that converts a string into an int value Note: if c is a character from 0 to 90, then (int)c-48 converts c to an integer value. You may assume that the user enters only digits Here's a demo class that tests the above methods and the output. Change the values and run the code at least three times for different input sets public class MyIntegerDemo public static void main (String args) My Integer n1 new My Integer (5) System out. println ("nl is nl. getValue out. println ("nl is even nl. isEven System System out. println ("nl is odd? n isodd System.out.println ("nl is prime 1 is Prime My Integer. is Prime (15) out.println ("15 is prime System char chars 3 '9' out. println (My Integer parse Int (chars) System String s 9786 System.out.println (My Integer parselnt (s)) My Integer n2 new My Integer (24) System out. println ("n2 is n 2. getvalue System out. println ("n2 is odd? n2. isodd System out. println ("45 is odd? My Integer s Odd (45) out. println ("nl is equal to n2? n equals (n2) System System.out.println ("nl is equal to 5? n equals (5) GRASP exec ea My Integer Demo Java n1 is 5 n 1 is even fals n 1 is odd true nl is prime true 15 is prime false 3539

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

Recommended Textbook for

Database Design For Mere Mortals

Authors: Michael J Hernandez

4th Edition

978-0136788041

More Books

Students also viewed these Databases questions

Question

Describe Table Structures in RDMSs.

Answered: 1 week ago