Switch Case

1,226 views

Published on

Published in: Education
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
1,226
On SlideShare
0
From Embeds
0
Number of Embeds
1,052
Actions
Shares
0
Downloads
3
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Switch Case

  1. 1. Task 1In the first of today’s lessons your willneed to complete your GUI work andupload it.Once you have done this you will beworking through the Greenfoottutorials.
  2. 2. Learning outcomesBy 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. 3. The Selection ConstructsWhen we want to perform a check in Javathere are a few ways of doing it. The 2 thatwe need to know about are;• IF statements• Switch Case
  4. 4. The Selection ConstructsImagine we are creating a form that allowsusers to input their date of birth like thisone. What would our IF statement say if I wanted to output the NAME of the month and not the NUMBER of the month?
  5. 5. IF Statementint month = 7;if (month == 1) { 37 lines ofSystem.out.println("January");} code!else if (month == 2) {System.out.println("February");}... // and so on
  6. 6. Switch Caseint month = 8;String monthString;switch (month) {case 1: monthString = "January"; break;case 2: monthString = "February"; break; 18 lines ofcase 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. 7. Your TaskUsing the Forum on Topic 7, you willneed to write a Switch Case for aprogram that will output a messageshowing the year a student is in. Forexample;“You are inYear 10!”
  8. 8. Exam QuestionOn Jogle you will see a 4 mark examquestion on Switch Cases. You will needto complete this and try and get all 4marks.

×