Java Reference
In-Depth Information
PROGRAMMING EXERCISES
1. The class Clock given in the chapter only allows the time to be incremented
by one second, one minute, or one hour. Rewrite the definition of the class
Clock by including additional members so that time can also be decremented by
one second, one minute, or one hour. Also write a program to test your class.
2. Write a program that converts a number entered in Roman numerals to
decimal. Your program should consist of a class , say, Roman . An object of
type Roman should do the following:
a. Store the number as a Roman numeral.
b. Convert and store the number into decimal.
c.
Print the number as a Roman numeral or decimal number as requested
by the user.
The decimal values of the Roman numerals are:
M
1000
D
500
C
100
L
50
X
10
V
5
8
I
1
d. Your class must contain the method romanToDecima l to convert a
Roman numeral into its equivalent decimal number
e. Test your program using the following Roman numerals: MCXIV ,
CCCLIX , and MDCLXVI .
3. Design and implement the class Day that implements the day of the week
in a program. The class Day should store the day, such as Sun for Sunday.
The program should be able to perform the following operations on an
object of type Day :
a. Set the day.
b. Print the day.
c. Return the day.
d. Return the next day.
e. Return the previous day.
f. Calculate and return the day by adding certain days to the current day.
For example, if the current day is Monday and we add four days, the day
to be returned is Friday. Similarly, if today is Tuesday and we add 13
days, the day to be returned is Monday.
g. Add the appropriate constructors.
h. Write the definitions of the methods to implement the operations for the
class Day , as defined in a through g.
i. Write a program to test various operations on the class Day .
 
Search WWH ::




Custom Search