Java Reference
In-Depth Information
΢
Exercise P5.5. Write a program that translates a letter grade into a number
grade. Letter grades are A B C D F , possibly followed by + or Ċ . Their
numeric values are 4, 3, 2, 1, and 0. There is no F+ or F- . A + increases
the numeric value by 0.3, a -decreases it by 0.3. However, an A+ has the
value 4.0.
Enter a letter grade:
B-
Numeric value: 2.7.
Use a class Grade with a method getNumericGrade .
΢
Exercise P5.6 Write a program that translates a number into the closest
letter grade. For example, the number 2.8 (which might have been the
average of several grades) would be converted to B- . Break ties in favor of
the better grade; for example, 2.85 should be a B .
Use a class Grade with a method getLetterGrade .
΢
Exercise P5.7 Write a program that reads in three strings and prints the
lexicographically smallest and largest one:
Please enter three strings:
Tom
Dick
Harry
The inputs in sorted order are:
Dick
Harry
Tom
΢΢ Exercise P5.8 Change the implementation of the getTax method in the
TaxReturn class, by setting variables bracket1 and bracket2 ,
depending on the marital status. Then have a single formula that computes
the tax, depending on the income and the brackets. Verify that your results
are identical to that of the TaxReturn class in this chapter.
222
223
΢
Exercise P5.9. A year with 366 days is called a leap year. A year is a leap
year if it is divisible by 4 (for example, 1980). However, since the
introduction of the Gregorian calendar on October 15, 1582, a year is not a
leap year if it is divisible by 100 (for example, 1900); however, it is a leap
Search WWH ::




Custom Search