The MyInteger class Design a class named MyInteger The class

(The MyInteger class) 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 isEven(int), isOdd(int), and isPrime(int) that return true if the specified value is even, odd, or prime, respectively.

Static methods isEven(MyInteger), isOdd(MyInteger), and isPrime(MyInteger) that return true if the specified value 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 parseInt(int) that converts a string to an int value.

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

Solution

import java.util.*;
import java.lang.*;
import java.io.*;

class MyInteger {
   int myInteger;
  
   public MyInteger(int x) {
       this.myInteger = x;
   }
  
   public int getMyInteger(){
       return(this.myInteger);
   }
  
   public boolean isEven() {
       return(((this.myInteger % 2) == 0));
   }
  
   public boolean isOdd() {
       return (((this.myInteger % 2) == 1));
   }
  
   public boolean isPrime() {
       int j = 2;
       int result = 0;
       int number = this.myInteger;
       while (j <= number / 2) {
           if (number % j == 0) {
               result = 1;
           }
           j++;
       }
       if (result == 1) return(false);
       else return (true);
   }
  
   public static boolean isEven(int x) {
       return(((x % 2) == 0));
   }
  
   public static boolean isOdd(int x) {
       return (((x % 2) == 1));
   }
  
   public static boolean isPrime(int x) {
       int j = 2;
       int result = 0;
       int number = x;
       while (j <= number / 2) {
           if (number % j == 0) {
               result = 1;
           }
           j++;
       }
       if (result == 1) return(false);
       else return (true);  
   }
}

(The MyInteger class) Design a class named MyInteger. The class contains: An int data field named value that stores the int value represented by this object. A
(The MyInteger class) Design a class named MyInteger. The class contains: An int data field named value that stores the int value represented by this object. A

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site