• Embed Doc
  • Readcast
  • Collections
  • 1
    CommentGo Back
Download
 
Exercise 1: Using
if
and
if/else
Constructs
The objective of this exercise is to create classes that use
if
and
if/else
constructs.
Task 1 – Writing a Class That Uses
if/else
Statements
In this task, you write a class called
DateTwo
that uses
if/else
statements todisplay the day of the week based on the value of a variable. Follow these steps to writeyour class:1. Go to the
opsdec
directory.2. Create a class called
DateTwo
with one variable that can only contain a valuefrom 1 to 7. Where:
The number 1 represents Monday (beginning of the week).
The number 7 represents Sunday (end of the week).3. In the
DateTwo
class, create a
displayDay
method that uses
if/else
constructs to inspect the value of the number of days and displays thecorresponding day of the week. The
displayDay
method should also displayan error message if an invalid number is used.4. Compile and execute your program using the provided
DateTwoTest
class file.
Task 2 – Writing Another Class That Uses
if/else
Statements
In this task, you write a class called
Clock
that uses
if/else
statementsto display the part of day depending on the time of day. Use the followingtable as a guideline.
Time of Day Part of Day
8:01 to 12:00 Morning12:01 to 17:00 Afternoon17:01 to 24:00 Evening0:01 to 8:00 Early MorningFollow these steps to write your class:5. Create a class called
Clock
with a variable called
currentTime
, that containsthe hour of day.
of 00

Leave a Comment

You must be to leave a comment.
Submit
Characters: ...
You must be to leave a comment.
Submit
Characters: ...