Java Reference
In-Depth Information
year if it is divisible by 400 (for example, 2000). Write a program that asks
the user for a year and computes whether that year is a leap year.
Implement a class Year with a predicate method boolean
isLeapYear() .
΢
Exercise P5.10. Write a program that asks the user to enter a month (1 =
January, 2 = February, and so on) and then prints the number of days of the
month. For February, print ȓ28 daysȓ.
Enter a month (1-12):
5
31 days
Implement a class Month with a method int getDays() .
΢΢΢ Exercise P5.11. Write a program that reads in two floating-point
numbers and tests (a) whether they are the same when rounded to two
decimal places and (b) whether they differ by less than 0.01. Here are
two sample runs.
Enter two floating-point numbers:
2.0
1.99998
They are the same when rounded to two decimal
places.
They differ by less than 0.01.
Enter two floating-point numbers:
0.999
0.991
They are different when rounded to two decimal
places.
They differ by less than 0.01.
΢
Exercise P5.12 Enhance the BankAccount class of Chapter 3 by
ȗ
Rejecting negative amounts in the deposit and withdraw
methods
ȗ
Rejecting withdrawals that would result in a negative balance
΢
Exercise P5.13. Write a program that reads in the hourly wage of an
employee. Then ask how many hours the employee worked in the past
Search WWH ::




Custom Search