CS 50 Homework 5 (Section 1 — Prof. Marshall)

Due by class time Tuesday, February 26
  1. Programming Exercise P5.7 (page 220). Name your program "Continue". Hint: make sure to compare strings using the equals method, not the == operator. For example, to test if the strings s1 and s2 are equal, you would write:
    if (s1.equals(s2)) { ...
    Files to submit: Continue.java

  2. Programming Exercise P5.8 (page 220). Name your program "Grade". Files to submit: Grade.java

  3. Implement a CombinationLock class. A combination lock has a dial with 26 positions labeled A through Z. The dial needs to be set three times. If it is set to the correct combination, the lock can be opened. When the lock is closed again, the full combination must be entered in order to open it again. If the user sets the dial more than three times, the last three settings determine whether the lock can be opened. Your class definition should support the following operations: Implement a test program called "TestLock" that demonstrates all of the features of your class. Files to submit: CombinationLock.java, TestLock.java

  4. Programming Exercise P6.7 (page 264). Name your program "Fibonacci". Files to submit: Fibonacci.java

  5. Programming Exercise P6.13 (page 267). Name your program "Primes". Files to submit: Primes.java

  6. Programming Exercise P6.15 (page 267). Name your applet program and HTML file "Checkerboard". Files to submit: Checkerboard.java, Checkerboard.html


Turning in Your Homework

To turn in your homework, put the specified files into a single folder named Your Name HW 5 and drop this folder into the drop box. If you are an off-campus student, you may copy your folder to a CLEAN floppy disk (one containing no other files or folders), and hand this in at the beginning of class, instead of using the drop box.