Java Reference
In-Depth Information
c. Random. nextInt(int n)
d. String.substring(int m, int n)
΢΢΢ Exercise R8.18. When a method is called with parameters that violate its
precondition(s), it can terminate (by throwing an exception or an
assertion error), or it can return to its caller. Give two examples of
library methods (standard or the library methods used in this topic) that
return some result to their callers when called with invalid parameters,
and give two examples of library methods that terminate.
΢΢ Exercise R8.19. Consider a CashRegister class with methods
ȗ public void enterPayment(int coinCount, Coin
coinType)
ȗ public double getTotalPayment()
Give a reasonable postcondition of the enterPayment method. What
preconditions would you need so that the CashRegister class can
ensure that postcondition?
΢΢ Exercise R8.20. Consider the following method that is intended to swap
the values of two floating-point numbers:
public static void falseSwap(double a, double
b)
{
double temp = a;
a = b;
b = temp;
}
public static void main(String[] args)
{
double x = 3;
double y = 4;
falseSwap(x, y);
System.out.println(x + " " + y);
}
Why doesn't the method swap the contents of x and y ?
Search WWH ::




Custom Search