Design a class named MyInteger. The class contains
时间: 2024-04-30 09:21:29 浏览: 14
the following private data fields:
- an int data field named value that stores the int value represented by this object.
The class should have the following public methods:
- A constructor that creates a MyInteger object for the specified int value.
- A getter method that returns the int value.
- Methods isEven(), isOdd(), and isPrime() that return true if the value in this object 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.
Here is the skeleton code:
```java
public class MyInteger {
private int value;
public MyInteger(int value) {
// TODO: Implement this constructor
}
public int getValue() {
// TODO: Implement this method
}
public boolean isEven() {
// TODO: Implement this method
}
public boolean isOdd() {
// TODO: Implement this method
}
public boolean isPrime() {
// TODO: Implement this method
}
public static boolean isEven(int value) {
// TODO: Implement this method
}
public static boolean isOdd(int value) {
// TODO: Implement this method
}
public static boolean isPrime(int value) {
// TODO: Implement this method
}
public static boolean isEven(MyInteger myInteger) {
// TODO: Implement this method
}
public static boolean isOdd(MyInteger myInteger) {
// TODO: Implement this method
}
public static boolean isPrime(MyInteger myInteger) {
// TODO: Implement this method
}
}
```