|Homework #1||CMSC 131|
|Due Friday Feb 11, 6:00 pm||Object-Oriented Programming I|
|Type of homework: Open||Spring 2005|
This homework will allow you to practice variables, strings, input/output facilities, conditionals, loops, and the Eclipse IDE.
For this assignment you will write an application for a copier machine. The program will allow users to input a copier access code and a specified number of copies to make. If the code is valid and the number of copies does not exceed a specified limit, then the copies will be authorized. More details about the program are provided in the Specifications section. You may want to take a look at the Sample Run section before you read the detailed description.
In addition to your program, you will keep a log of how much time you are spending on various parts of the homework, as described in the Time Log section below.
This homework will be graded as follows:
This homework is considered an open homework. Please visit the course web page for information regarding the policy associated with homeworks of this course.
Copier Access Codes
In the real world, we would like to write a program that can handle a large number of access codes, however, for simplicity, we will assume only three codes can be processed by your program. The codes and the maximum number of copies associated with each one are:
Copier Access Code
Maximum Number of Copies
In the description that follows when we refer to a valid access code we mean one of the three numbers in the above table.
The processing associated with your program can be divided into two subparts: identifying whether we have a valid access code and verifying whether the number of copies is valid (if any valid code was provided).
Identifying a Valid Access Code
Your program will start by prompting the user for an access code. Your program must display the message "Input copier access code" in order to read the number. If the user enters a valid access code, your program will proceed to the Validating the Number of Copies component of your program, below. If the user provides an invalid code, your program will notify the user about the invalid code by displaying the message "Invalid access code". After recognizing an invalid code, your program must ask the user whether he/she wants to try another code by displaying the message "Do you want to try another code?". The program will keep repeating the previously described process as long as the user does not provide a valid code and wants to try another code. If the user decides not to try another code, your program will terminate and no further processing will take place.
Validating the Number of Copies
When your program reaches this point, you know that it has identified one of the three valid codes. Next, your program will read the number of copies to make, ask the user for confirmation that the amount is correct, and then verify whether the number does not exceed the corresponding maximum.
Your program will read the number of copies using the message "Enter number of copies to make:". After reading this amount your program will ask the user to confirm the number by using the message "Is <numberOfCopies> the correct number of copies?". The field <numberOfCopies> corresponds to the value entered by the user. If the user acknowledges the number is correct, your program will convert the input string into a variable of type int and then proceed to the final stage of verifying that the number does not exceed the corresponding maximum. (This is described below.) Otherwise, your program will continue asking the user for a number until one is confirmed. Note: At this point, the program does not provide an option to quit. The user must eventually provide a number and confirm it.
After your program has confirmed the number of copies, it will verify that the number does not exceed the maximum associated with the code. If the number is valid then the message "Copies have been authorized" will be generated. Otherwise, the message "Request denied" will be displayed. The program will end after the appropriate message is generated.
Note:For this project you can assume the user will not choose the "Cancel" option associated with JOptionPane methods.
In order to help you get started, we have defined a CopierAccess class with a main( ) method in a file named CopierAccess.java. In addition, we have provided a time log file for you to complete. Both of these files can be retrieved by checking out the project from the CVS repository. Remember that you must have set up your repository in order to check out and submit homeworks. Information on how to do this can be found in the Managing Homeworks section of the Eclipse tutorial. Follow the instructions given there to check out project p1. Then when you switch back to the Dr. Java, you will see the above files, and you will be able to start modifying them.
The following provides a sample run of the program you are expected to write. Keep in mind this is just an example and not the only scenario your program is expected to handle.
After starting the program and entering an invalid access code
After selecting OK
After selecting OK
After selecting Yes and entering valid copier code number
After selecting OK and entering number of copies
After selecting OK
After selecting No and entering 200
After selecting OK
After selecting Yes
After pressing OK programs ends
You must turn in a time log that you will maintain during the week as you work on this class. You will not be graded on the content of this log, only by its completion. It will help us to understand how the class is going and where there are trouble spots. It is important that you fill it out accurately as you work (and not after the fact). We do read these logs, and therefore we ask you to please complete it as accurately as possible. You will find a sample timelog on the class web page: Click here.
Submit your project using the submit project option associated with Eclipse. Remember to complete your time log before submitting your project.
Keep in mind that you are not required to implement the following problem. Please visit the course web page for information regarding challenge problems.
In this homework access codes must be entered using the format specified above. Modify your program so that it can recognize valid access codes regardless of the number (and position) of blank characters in the code. (You need not be concerned with other types of characters in the code.) For example, the following should be recognized as valid access codes:
45 01 01
4 50 2 0 2
4 3 03 03
Hint: The Character method isDigit (Character.isDigit) and the String method charAt (String.charAt) can be very helpful to solve this problem.