Homework13.pdf - 1.Implement the following two static...

This preview shows page 1 - 3 out of 4 pages.

1.Implement the following two static methods. Note that, although the two methods compute the same function, the first one clears the given NaturalNumber while the second one restores it.
2. Implement the static method declared as follows: /** * Reports the value of {@code n} as an {@code int}, when {@code n} is * small enough. *
* @param n * the given {@code NaturalNumber} * @return the value * @requires n <= Integer.MAX_VALUE * @ensures toInt = n */ private static int toInt(NaturalNumber n) { int m = n.divideBy10(); int number = m; if(!n.isZero()){ number = m + 10 * toInt(n); } n.multiplyBy10(m); return number; } 3.

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture