Categories

See More
Popular Forum

MBA (4887) B.Tech (1769) Engineering (1486) Class 12 (1030) Study Abroad (1004) Computer Science and Engineering (988) Business Management Studies (865) BBA (846) Diploma (746) CAT (651) B.Com (648) B.Sc (643) JEE Mains (618) Mechanical Engineering (574) Exam (525) India (462) Career (452) All Time Q&A (439) Mass Communication (427) BCA (417) Science (384) Computers & IT (Non-Engg) (383) Medicine & Health Sciences (381) Hotel Management (373) Civil Engineering (353) MCA (349) Tuteehub Top Questions (348) Distance (340) Colleges in India (334)
See More

Uses of selection in programming (if, switch etc)

Course Queries Syllabus Queries

Max. 2000 characters
Replies

usr_profile.png

User

( 4 months ago )

 


I am an experienced programmer that has just started teaching. I am struggling to see how to introduce selection to my programming classes. None of the examples that I have seen so far are good.

I am struggling to find examples other than the ones below. (These are more advanced than I need.)

  • Termination condition for recursion (We don't do recursion until upper years of school, exams do not need it).

  • Input validation (Again the exams say don't worry about checking input (I think this is a mistake, as it leads to cowboy programmers)).

Both of these are only in the syllabus from UK year 12. I am teaching from UK year 7.

Can you help with good examples, and exercises that my younger pupils can use?


year 7 is age 11-12 year 12 is age 16-17

usr_profile.png

User

( 4 months ago )

There are endless examples that illustrate selection. As you know, most useful programs have at least one selection statement. I've found that some students struggle with the concept, so I start small and pick examples that resonate with students, for example:

    if (hungry)
        System.out.println("Eat a sandwich.");

    if (age > 17)
        System.out.println("You can vote.");
    else
        System.out.println("You cannot vote.");

For a switch statement, I like to show some type of menu:

    switch(choice) {
    case 0:
        System.out.println("Balance Inquiry.");
        break;
    case 1:
        System.out.println("Transfer");
        break;
    case 2:
        System.out.println("Withdrawal");
        break;  
    case 3:
        System.out.println("Deposit");
        break;          
    default:
        System.out.println("Quit");
        break;          
    }

what's your interest


forum_ban8_5d8c5fd7cf6f7.gif