Reading: Weiss, Chapter 1

Weiss, Chapter 2, Sections 2.1, 2.2, 2.4.1

Weiss, Chapter 3, Sections 3.1 - 3.4

1. Weiss, Exercise 1.19

Write a program to determine all pairs of positive integers, (a,b), such that a < b < 1000 and (a2+b2+1)/(ab) is an integer.

2. Weiss, Exercise 1.22

In the following arithmetic puzzle, each of the ten different letters are assigned a different digit.

         MARK
       +ALLEN
        -----
        WEISS

Write a program that finds all possible solutions. One such solution is shown below:

         MARK     A=1 W=2 N=3 R=4 E=5       9147
       +ALLEN     L=6 K=7 I=8 M=9 S=0     +16653
        -----                              -----
        WEISS                              25800
3. Adapted from Weiss, Exercise 3.10

A combination lock has the following basic properties:

  • the combination (a sequence of three numbers) is hidden.
  • the lock can be opened by providing the combination.
  • the lock can be closed without requiring the combination.
  • the combination can be changed, but only by someone who knows the current combination.

Imagine designing a class to represent a combination lock.

  1. What data needs to be stored in a combination lock object?
  2. What instance variables are needed for this class?
  3. Write the constructor for this class.
  4. Write methods called open, close, and changeCombo to implement the operations described above.
  5. What access modifiers should be used on these methods?