Write a class MyInteger that wraps one int value, and a public class MyIntegerApp. The lab is about the difference between instance and static methods:
| instance (about this object) | static (about the argument) |
|---|---|
isEven(), isOdd(), isPrime() |
isEven(int), isOdd(int), isPrime(int) |
equals(int), equals(MyInteger) |
isEven(MyInteger), isPrime(MyInteger) |
getValue() |
parseInt(char[]), parseInt(String) |
parseInt converts digits to a number itself (do not call Integer.parseInt). The instance methods must reuse the static ones.
main reads numbers as text until the end of the input, converts each with MyInteger.parseInt, and describes it: even or odd; prime; twin prime (the number and the number + 2 are both prime); same as the previous number; and "the answer" when it equals 42. For the input
7 8 8 42 1 11 29
the program prints
7: odd, prime
8: even
8: even, same as the previous number
42: even, the answer
1: odd
11: odd, prime, twin prime with 13
29: odd, prime, twin prime with 31