CS 50 Homework 5 (Section 2 Prof. Brown)
Due by class time Tuesday, February 26
- 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
- Programming Exercise P5.8 (page 220). Name your program
"Grade". Files to submit: Grade.java
- 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:
- public CombinationLock(String combo)
Constructs a lock with the given combination. combo is a
string of three uppercase letters A-Z.
- public void setDial(String position)
Sets the dial to the specified position. position is a string
consisting of a single uppercase letter.
- public void unlock()
Attempts to open the lock.
- public boolean isOpen()
Returns true if the lock is currently unlocked, or
else false.
- public void lock()
Closes the lock.
Implement a test program called "TestLock" that demonstrates all of the
features of your class. Files to submit: CombinationLock.java,
TestLock.java
- Programming Exercise P6.7 (page 264). Name your program
"Fibonacci". Files to submit: Fibonacci.java
- Programming Exercise P6.13 (page 267). Name your program
"Primes". Files to submit: Primes.java
- 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.