设计名为MyInteger的类,它包括: 一个名为value的int型数据域,存储这个对象表示的int值。 一个为指定的

【题目】设计名为MyInteger的类,它包括:
一个名为value的int型数据域,存储这个对象表示的int值。
一个为指定的int值创建的MyInteger对象的构造方法。
一个返回int的get方法。
如果值分别为偶数,奇数或素数,那么isEven()、isOdd()、isPrime()方法都会返回true。
如果指定值分别为偶数,奇数或素数,那么isEven(int)、isOdd(int)、isPrime(int)方法都会返回true。
如果指定值分别为偶数,奇数或素数,那么isEven(MyInteger)、isOdd(MyInteger)、isPrime(MyInteger)方法都会返回true。
如果该对象的值与指定的值相等,那么equals(int)和equals(MyInteger)方法返回return。
静态方法parseInt(char[])将数字字符构成的数组转换为一个int值。
静态方法parseInt(String)将一个字符串转换为一个int值。
编写用户程序测试该类中的所有方法。
其他的都明白,就是这个地方:
“如果值分别为偶数,奇数或素数,那么isEven()、isOdd()、isPrime()方法都会返回true。
如果指定值分别为偶数,奇数或素数,那么isEven(int)、isOdd(int)、isPrime(int)方法都会返回true。
如果指定值分别为偶数,奇数或素数,那么isEven(MyInteger)、isOdd(MyInteger)、isPrime(MyInteger)方法都会返回true。
如果该对象的值与指定的值相等,那么equals(int)和equals(MyInteger)方法返回return。”
这三个的测试类怎么编写,求指教。

package myInteger;
import java.util.Scanner;
public class MyInteger{
private int value; //存储这个对象表示的int值
public MyInteger(int value) {
this.value = value;
} //为指定的int值创建MyInteger对象的构造方法
public int getValue() {
return value;
} //返回int值的获取方法
public boolean isEven() {
return isEven(value);
} //调用静态方法判断对象中的值是否为偶数
public boolean isOdd() {
return isOdd(value);
} //调用静态方法判断对象中的值是否为奇数
public boolean isPrime() {
return isPrime(value);
} //调用静态方法判断对象中的值是否为素数
public static boolean isEven(int value) {
if(value % 2 == 0)
return true;
else
return false;
} //判断指定值是否为偶数
public static boolean isOdd(int value) {
if(value % 2 != 0)
return true;
else
return false;
} //判断指定值是否为奇数
public static boolean isPrime(int value) {
for(int i = 2; i < value - 1; i++) {
if(value % i == 0)
return false;
}
return true;
} //判断指定值是否为素数
public static boolean isEven(MyInteger m) {
if(m.getValue() % 2 == 0)
return true;
else
return false;
} //判断指定值是否为偶数
public static boolean isOdd(MyInteger m) {
if(m.getValue() % 2 != 0)
return true;
else
return false;
} //判断指定值是否为奇数
public static boolean isPrime(MyInteger m) {
for(int i = 2; i < m.getValue() - 1; i++) {
if(m.getValue() % 2 == 0)
return false;
}
return true;
} //判断指定值是否为素数
public boolean equals(int value) {
if(this.value == value)
return true;
else
return false;
} //判断该对象的值是否与指定值相等
public boolean equals(MyInteger m) {
if(this.value == m.getValue())
return true;
else
return false;
} //判断该对象的值是否与指定值相等
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
MyInteger n1 = new MyInteger(input.nextInt()); //创建一个对象n1
System.out.println("n1是偶数吗?" + '\t' + n1.isEven()); //调用非静态方法判断n1是否为偶数
System.out.println("n1是素数吗?" + '\t' + n1.isPrime()); //调用非静态方法判断n1是否为素数
System.out.println("n1是素数吗?" + '\t' + MyInteger.isPrime(n1)); //调用静态方法判断n1是否为素数
MyInteger n2 = new MyInteger(input.nextInt()); //创建一个对象n2
System.out.println("n2是奇数吗?" + '\t' + n2.isOdd()); //调用非静态方法判断n2是否为奇数
System.out.println("45是奇数吗?" + '\t' + MyInteger.isOdd(45)); //调用静态方法判断n2是否为奇数
System.out.println("n1与n2相等吗?" + '\t' + n1.equals(n2)); //调用非静态方法判断n1与n2是否相等
System.out.println("n1等于5吗?" + '\t' + n1.equals(5)); //调用非静态方法判断n1是否等于5
input.close();
}
}
温馨提示:答案为网友推荐,仅供参考