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

Create a class titled MyInteger. The class will contain: An int data field title

ID: 3674151 • Letter: C

Question

Create a class titled MyInteger. The class will contain:

An int data field titled value that stores the int value for each instance of this class.

A constructor that creates an instance object for the int value specified.

A getter method that returns the int value.

A setter method that changes the int value.

A method titled isEven() that returns true if the int value is even.

A method titled isOdd() that returns true if the int value is odd.

Write a main method in a class titled TestMyInteger to test your code.

Explanation / Answer

MyInteger n1 = new MyInteger(5);

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

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

String s = "3539";

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

MyInteger n2 = new MyInteger(24);

System.out.println("n2 is odd? " + n2.isOdd());

}

}

class MyInteger {

int value;

public MyInteger(int value) {

this.value = value;

public Integer getValue() {

return value;

}

public boolean isEven() {

if (value % 2 == 0) {

return true;

}

return false;

}

public boolean isOdd() {

if (value % 2 != 0) {

return true;

}

return false;

}

public static boolean isEven(MyInt myInt) {

return myInt.isEven(myInt.getValue());

}

public static boolean isOdd(MyInt myInt) {

return myInt.isOdd(myInt.getValue());

}

public static int parseInt() {

}

}

public class NewMyInteger {
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote