ITEC 120
HW4: Password Validator (100 points)

Academic Integrity

Be reminded that this homework assignment must be your own work.

Objectives

After successfully completing this assignment you will be able to use methods to break a larger problem up into smaller pieces. You'll also get some experience testing your code with a test driver.

Assignment

You've been given a password specification that defines a password as valid if it meets the following criteria:

Write a method called isValid which takes a String and answers if the string is a valid password.

Download these files to start

To develop this program, you will write methods in a service class, called Password, and you will write tests in a driver class called HW4Driver. These files have been created for you.

Download:

Password.java and HW4Driver.java

In the Password class, you will find the method header for the isValid method. Do not change this method header or the name of the class. Your program will be graded using a test driver which will be testing the isValid method of the Password class. If you change the name of the method signature or the method classname, the grading program will not be able to test your work.

In the HW2Driver you will find two pass fail tests which also output the return value of the isValid method. One of the tests is for a valid password, one for an invalid one. You will write many more tests to test your code. This code is being given to you to give you an example of one way to write a test, and make it easy for you to add more tests. Feel free to copy the second test and make more test cases. Notice that you will need to take care to adjust the if statement for each test so that "PASS" is printed for the correct result.

Make More Methods!

The best way to solve this problem is to break it into many smaller methods. The isValid method can call other methods that you write. You will put them in the Password class too, and, they can have private visibility. We call these kinds of methods helper methods.

None of your methods should be very long. This will help you read, write, and debug your code. It's very difficult to work on blocks of code that are hundreds of lines long. Working with a method that is only a few lines of code is much easier to do.

Use an iterative approach: get something to work, then add to it.

First, try compiling and running the two files you downloaded. Password.java doesn't compile, because isValid doesn't return anything. Make isValid into a stub method: get it to compile. It doesn't need to work correctly yet, just add a return value so that it can compile and run. Then run your driver and see what it does.

Writing test cases is a critical part of software development. Writing test cases first is a fine idea for many reasons. It will often help you think about the problem more clearly. When you write a test case, carefully choose inputs that will test specific things that your code is supposed to do. Your goal is to get your code bug free, so you want tests that check for things that could break.

Don't be overwhelmed by the problem. Pick a small part of it, and get it to work. For example, you could start with the length of the password. Write the code that checks to see if the password length is valid, without worrying about what characters are in the password. Get the length part to work before moving on to the next task.

 

Dos and Don'ts

You MAY use the String methods .charAt() and .length() for this assignment.

You MAY NOT use any other methods or Arrays.

This purpose of this assignment is for YOU to write any methods you need.

 

Submit Your Assignment

SUBMIT :

to the to the HW4 submission folder on D2L.