Welcome to SWYK check 1!

This is your first chance to show what y'all know!

Set up

Before continuing, verify each of the following:

  1. You have a partner, whose name you have memorized.
  2. The partners are sitting side by side with their laptops, and can both easily see both screens.
  3. The director has a browser open to this page: http://stephendavies.org/cpsc240/swyk1.html
  4. The typist has two windows logged into the cpsc server.
  5. The typist has created a new, empty directory for this SWYK check.
  6. The typist has cd'd into that directory in both windows.

Then, the typist should perform the following commands to download the test harness for this SWYK check:

(You may get some strange-looking messages when you do this, but that's okay as long as you can type "ls" and see the two files you just downloaded.)

Then the typist should set up the following aliases in your right-most window:

For this SWYK check, the typist can type compile in the right-most window to compile your code, and runtests to run the tests against it.


The actual problem

For this problem, you are to write a class called BikeLock (spelled exactly that way, capitalized exactly that way) to represent locks like Stephen's simple 4-digit spinny-wheel-style bike lock:


How they work

Here's how this style of bike locks works:

  1. A lock of this type is always either locked or unlocked.
  2. By default, when purchased, it starts out locked.
  3. There's a secret (integer) combination known only to the bike lock, the manufacturer, and God.
  4. At any point in time, the spinny wheels will be on some four-digit (integer) combination.
  5. The owner (or a thief) can spin the wheels at will to any other integer.
  6. If the spinny wheels match the combo, the lock can be unlocked. If they don't, it can't.
  7. The lock can always be locked, regardless of what the spinny wheels are set to.

Note: throughout this SWYK check, you do not have to worry about checking or enforcing that the combinations and/or spinny wheels' values are four digits long. Just treat them as integers and do not worry about how many digits they take up.


The requirements

Instance variables

Your BikeLock class should have the following instance variables:

You can name these inst vars whatever you want.

Methods

Your BikeLock class must have the following methods:

  1. A constructor that takes the secret combination (a single integer) as an argument. This constructor should always instantiate locked bike locks. The spinny wheels should be set to their factory setting: 9999.
  2. Another constructor, which takes the secret combination (a single integer) and a boolean as arguments. The second argument indicates whether or not the bike lock should initially be locked. (true means "yes, locked.") The spinny wheels should be set to their factory setting: 9999.
  3. An .isLocked() method that returns a boolean, indicating whether the bike lock is currently locked. (true means "yes, locked.")
  4. A .spinWheelsTo() method that takes an integer and sets the spinny wheels to that number. (It returns nothing.)
  5. A .lock() method that will lock the bike lock. This always works. It returns nothing.
  6. An .unlock() method that will attempt to unlock the bike lock. This does not always work. If the spinny wheels currently match the secret combination, this will succeed, unlock the bike lock, and return the value true to the client. Otherwise, it will fail and return the value false.

Pro-gamer tip

All of the above methods must be present for your code to even compile. It might thus be a good idea to write empty method stubs for them to start out, just so your code compiles. For example:

    boolean unlock() {
        return true;   // just for now; will actually implement this later
    }

Compiling your code

Don't forget to compile your code (using the "compile" alias defined above) every time you write (save) a change in vim! Otherwise your changes will not be reflected in what's executed when you runtests.

Running your code

Executing the "runtests" alias will trigger the entire test suite. To get full credit for the SWYK check, you must pass all the test cases. When you do, you're done! Until then, continue to study your error messages and your code, and make the bike lock work properly.

Running your own main()

Yes, it is absolutely permissible (and a good idea, actually) to create your own main() method in the BikeLock class, and use it to experiment with your own client code. Recall that it must look like this:

class BikeLock {

    ...possibly other stuff...

    public static void main(String args[]) {
        ...Your client code that fiddles around with BikeLock objects...
    }

    ...possibly other stuff...

and that to run it, you would type:

$ java BikeLock

Turning it in

When you have completed your class and gotten all the test cases to pass, do the following:

  1. Wave me over so I can look at y'all's screen and then give y'all a high-five.
  2. Download your BikeLock.java code to your laptop (using Filezilla or any other method you choose) and then send it as an email attachment to both (1) cpsc240submissions@gmail.com and (2) the partner whose laptop is not being used for this assignment. The subject line of this email should be "SWYK check 1 turn-in".

If you can't get all the test cases before time's up, still perform step #2, above.