ICT role in 21st century education and it's challenges.
Switch Case
1. Task 1
In the first of today’s lessons your will
need to complete your GUI work and
upload it.
Once you have done this you will be
working through the Greenfoot
tutorials.
2. Learning outcomes
By the end of today’s lesson;
• All of you will create basic Switch
Cases
• Most of you will ensure all the syntax
is correct for your Switch Cases
• Some of you will create a detailed
Switch Case which includes Strings
3. The Selection Constructs
When we want to perform a check in Java
there are a few ways of doing it. The 2 that
we need to know about are;
• IF statements
• Switch Case
4. The Selection Constructs
Imagine we are creating a form that allows
users to input their date of birth like this
one.
What would our IF
statement say if I wanted
to output the NAME of
the month and not the
NUMBER of the month?
5. IF Statement
int month = 7;
if (month == 1) {
37 lines of
System.out.println("January");
}
code!
else if (month == 2) {
System.out.println("February");
}
... // and so on
6. Switch Case
int month = 8;
String monthString;
switch (month) {
case 1: monthString = "January"; break;
case 2: monthString = "February"; break;
18 lines of
case 3: monthString = "March"; break;
case 4: monthString = "April"; break;
case 5: monthString = "May"; break;
case 6: monthString = "June"; break;
code!
case 7: monthString = "July"; break;
case 8: monthString = "August"; break;
case 9: monthString = "September"; break;
case 10: monthString = "October"; break;
case 11: monthString = "November"; break;
case 12: monthString = "December"; break; default:
monthString = "Invalid month"; break;
}
System.out.println(monthString);
7. Your Task
Using the Forum on Topic 7, you will
need to write a Switch Case for a
program that will output a message
showing the year a student is in. For
example;
“You are in
Year 10!”
8. Exam Question
On Jogle you will see a 4 mark exam
question on Switch Cases. You will need
to complete this and try and get all 4
marks.