Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Following the instructions in the problem statedment, design and implement a jav

ID: 3767837 • Letter: F

Question

Following the instructions in the problem statedment, design and implement a java program for programming exercise 10.3, page 400(name it Myinteger.java).

(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 getter method that returns the int value.
The methods isEven(), isOdd(), and isPrime() that return true if the
value in this object is even, odd, or prime, respectively.
The static methods isEven(int), isOdd(int), and isPrime(int) that
return true if the specified value is even, odd, or prime, respectively.
The static methods isEven(MyInteger), isOdd(MyInteger), and
isPrime(MyInteger) that return true if the specified value is even, odd,
or prime, respectively.
The methods equals(int) and equals(MyInteger) that return true if
the value in this object is equal to the specified value.
A static method parseInt(char[]) that converts an array of numeric
characters to an int value.
A static method parseInt(String) that converts a string into an int
value.

Next, develop a test program in a seperate file( call it TestMyInteger.java) to create all methods of the class.Document your code, and organize and space the outputs properly. use escaoe characters and formatting objects when applicable.

Explanation / Answer

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

public class NewMyInteger {

    public static void main(String[] args) {
        MyInteger n11 = new MyInteger(5);
        System.out.println("n11 is the even? " + n11.isEven());
        System.out.println("n11 is the prime? " + n11.isPrime());
        System.out.println("15 is the prime no? " + MyInteger.isPrime(15));

        char[] char11= {'3', '5', '3', '9'};
        System.out.println(MyInteger.parseInt(char11));

        String s11 = "3539";
        System.out.println(MyInteger.parseInt(s11));

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

class MyInteger {

    int val;

    MyInteger(int newVal) {
        val = newVal;
    }

    public int getValue() {
        return val;
    }

    public static boolean isEven(int no) {
        return (no % 2 == 0);
    }

    public static boolean isOdd(int no) {
        return !isEven(no);
    }

    public static boolean isPrime(int no) {
        for (int f11 = 2; f11< no/2; f11++) {
            if (no % f11 == 0) {
                return false;
            }
        }
        return true;
    }

    public static boolean isEven(MyInteger no) {
        return no.isEven();
    }

    public static boolean isOdd(MyInteger no) {
        return no.isOdd();
    }

    public static boolean isPrime(MyInteger no) {
        return no.isPrime();
    }

    public boolean isEven() {
        return isEven(val);
    }

    public boolean isOdd() {
        return isOdd(val);
    }

    public boolean isPrime() {
        return isPrime(val);
    }

    public boolean equals(int no) {
        return (val == no);
    }

    public boolean equals(MyInteger no) {
        return equals(no.getValue());
    }

    public static int parseInt(String str) {
        return Integer.parseInt(str);
    }

    public static int parseInt(char[] str) {
        return parseInt(new String(str));
    }
}