Java Reference
In-Depth Information
Define a class DigitExtractor :
public class DigitExtractor
{
/**
Constructs a digit extractor that gets the digits
of an integer in reverse order.
@param anInteger the integer to break up into digits
*/
public DigitExtractor(int anInteger) { . .
. }
/**
Returns the next digit to be extracted.
@return the next digit
*/
public int nextDigit() { . . . }
}
In your main class DigitPrinter , call
System.out.println(myExtractor.nextDigit()) five
times.
΢΢Exercise P4.13. Implement a class QuadraticEquation whose
constructor receives the coefficients a , b , c of the quadratic equation ax 2 +
bx + c = 0. Supply methods getSolution1 and getSolution2 that
get the solutions, using the quadratic formula. Write a test class
QuadraticEquationTester that constructs a
QuadraticEquation object, and prints the two solutions.
177
178
΢΢΢Exercise P4.14. Write a program that reads two times in military format
(0900, 1730) and prints the number of hours and minutes between the
two times. Here is a sample run. User input is in color.
Please enter the first time: 0900
Please enter the second time: 1730
8 hours 30 minutes
Extra credit if you can deal with the case where the first time is later than
the second time:
Please enter the first time: 1730
Search WWH ::




Custom Search