CS101 - Lab 4

In this lab you will put to work with all the Java elements we have covered so far: conditionals, loops, nested loops, arrays, and Strings.

Programming style: Pay attention to issues of programming style:

I will take points off if you do not follow the programming style guidelines above. Read carefully the handout on programming style handed out in class.

Work individually, and call me if you need help. You are encouraged to discuss ideas and techniques broadly with other class members, but not specifics. Discussions should be limited to questions that can be asked and answered without using any written medium (e.g. pencil and paper or email). You should at no point look at the screen of your colleagues.


  1. The annoying problem (by popular request)

    Write a Java program that asks the user if he/she likes Java programming. If the user answers yes, then it displays a congratulating message (use your imagination), and terminates.

    Now, if the user answers no, then the fun starts. The program should ask Are you sure you don't like Java programming?. If the user answers no, then it should display Hope you'll get to like it soon.. Otherwise, if the user answers yes, it should ask Are you really sure you don't like Java programming?, and repeat. If the user keeps saying yes, then the program keeps asking Are you really really sure you don't like Java programming?, then Are you really really really sure you don't like Java programming?. And so on, every time printing one more really.

    This should stop when it reaches the point when it prints really 5 times. At that point, if the user still answers yes, it should print Too bad, and terminate.

    Do you like Java programming? [y/n]: n
    Are you sure you don't like Java programming? [y/n]: y
    Are you really sure you don't like Java programming? [y/n]: y
    Are you really really sure you don't like Java programming? [y/n]: n
    Hope you'll get to olike it soon..
    
    Do you like Java programming? [y/n]: n
    Are you sure you don't like Java programming? [y/n]: y
    Are you really sure you don't like Java programming? [y/n]: y
    Are you really really sure you don't like Java programming? [y/n]: y
    Are you really really really sure you don't like Java programming? [y/n]: y
    Are you really really really really sure you don't like Java programming? [y/n]: y
    Are you really really really really really sure you don't like Java programming? [y/n]: y
    Too bad..
    

  2. The voting machine

    Imagine that by 2008 you have become a succesful Bowdoin CS graduate. One the many job offers you have is to work for Dumbbell Corporation, in charge of programming the voting machine that is suppposed to count votes in the next US presidential election. For the sake of this problem, despite the voting machine controversy, let's imagine you take the job.



    What to turn in:

    E-mail me the two java programs, both in the same email. Also, hand in a hard copy of the two Java programs, and the short essay.

    Due date: Technically Monday March 6th. Practically, Wednesday March 1st (i.e. in place of exam preparation).