0% found this document useful (0 votes)
6K views1 page

WJ 1103A Module1 Exercise2

This document provides instructions for an exercise to practice using the switch construct in Java decision-making programs. Learners are asked to write a DateThree class with a variable containing a number from 1-7 representing the day of the week, and a displayDay method that uses a switch statement to display the corresponding day based on the number's value or an error if invalid. The DateThreeTest class is provided to compile and test the program.

Uploaded by

Rajani Ramsagar
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6K views1 page

WJ 1103A Module1 Exercise2

This document provides instructions for an exercise to practice using the switch construct in Java decision-making programs. Learners are asked to write a DateThree class with a variable containing a number from 1-7 representing the day of the week, and a displayDay method that uses a switch statement to display the corresponding day based on the number's value or an error if invalid. The DateThreeTest class is provided to compile and test the program.

Uploaded by

Rajani Ramsagar
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

Exercise 2: Using the switch Construct

The objective of this exercise is to practice using the switch construct in


decision-making programs.

Task 1 – Writing a Class That Uses a Switch


Statement
In this task, you write a class called DateThree that uses switch statements to
display the day of the week based on the value of a variable.

1. Go to the opsdec directory.

2. Create a class called DateThree with one variable containing a value from 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 DateThree class, create a displayDay method that uses a switch


construct to inspect the value for the number of days and displays the
corresponding day of the week. The displayDay method should also display
an error message if an invalid number is used.

4. Compile and execute your program using the provided DateThreeTest class
file.

You might also like