Back to the faculty page for James Tam  

Return to the course web page


CPSC 233: Full Assignment 5

Due at 4 PM. For assignment due dates see the main grid on the course webpage.

New Concepts to be applied for the assignment

Unlike the other assignments you will make extensive use of the pre-created Java libraries developed by Sun/Oracle for graphical components (e.g., java.awtjavax.swing), event handling (e.g., java.awt.event) and the four classes for file input and output.

You need to write two programs for this assignment: a simple shopping program and a program that error checks user input using recursion.

Program 1: Implement a simple shopping program.

Note: it is not sufficient to just implement a working program and expect full credit. Even if your program is fully working and the design is not as specified in this document (E.g. your program implements static methods other than the main method or only a single class is used) then your marks will suffer greatly. (Your raw grade point is quartered if you do these two things i.e. an 'A' becomes a 'D' grade). There are other crucial design requirements but I used two extreme examples to make a point. You are to learn and practice good Object-Oriented principles in CPSC 233 and you are expected to be able to apply these principles in higher level courses. Note: the prohibition on the use of static methods does not necessarily apply to static class constants (e.g. public static final double PI from class Math is an example of good style, the appropriate use of class constants.) These restrictions apply on to the code that you write and not prewritten code that you may or must for some assignments as they may represent an exception to these rules.

There is no starting code for this part of the assignment.

Program 1: Functionality of the login dialog

When the program is first run a login dialog will be presented to the user (use a JPasswordField to store the input). The password to login to the program will be stored in an 'encrypted' format in a file called "password.txt". The contents of this file consists of the string "password" after the Caesar cipher has shifted each character backward one place in the alphabet ('s' becomes 'r', 'p' becomes 'o' and 'a' wraps around to 'z'). The encrypted version thus becomes "ozrrvnqc". Your program must be able to use any arbitrary password file. However you can assume that the file will only consist of lower case alphabetic characters. [The following tutorial example] which 'scrambles' character information may be helpful when you implement your encryption feature.

Your program must read the encrypted password and convert it to the original form ("ozrrvnqc" read from file becomes "password"). It will then compare the unencrypted string vs. the current value entered in the password field when either: (1) the user hits the login button or (2) the cursor focus is in the password field (as shown in Figure 1A) and the user hits enter. If there is no match then the program should display a suitable error message as well as the current number of attempts and the maximum number allowed. If three unsuccessful attempts have been made then a suitable error message should be provided (e.g., Figure 1B for an example) and the program will end. Note that the program will need to 'pause' so the user actually has time to see the error message before it shuts down. (Two methods of pausing a program have been demonstrated in the 'GUI' lecture notes). [Link to video showing 3 unsuccessful logins]

The container for the login dialog need not be a JFrame, indeed in such a case something like a JDialog is probably more appropriate. (If you use the latter control then you may need to end the program with the call to the 'exit()' method via System.exit(<int>). Clicking on the close window of the login dialog (or the main shopping window (shown in Figure 2) will also end the program although without an error message).

Figure 1A: Login dialog when incorrect credentials entered
 
Figure 1B: Max attempts reached

If the password has been correctly entered then the login window is banished and the main shopping screen comes up. You have some flexibility in the exact content and layout, an example is shown in Figure 2.

Figure 2: Main shopping screen

Program 1: Functionality of the main shopping screen

At a minimum this window should consist of the following: a JFrame container, a JTextField and JTextArea for the name and address input areas (respectively), JLabels to specify what is to be entered into the input fields, two JButtons to handle most of the user interaction. The full version of the program will employ the GridBagLayout (and the GridBagConstraints) for the main shopping window (it's optional for the login dialog). Regardless of whether a layout 'manager class' is used the layout should be organized and logical so the user can quickly understand the interface at a glance. If you desire, you can use other sub-containers with other layout manager classes. ImageIcons will be used to adorn the buttons (your choice of image but it should complement the text descriptions).  Finally you should include another image somewhere in the container with an appropriate company logo ("TAMCO Enterprises Inc." in the example) contained with a Java GUI Component (a JLabel is a good choice). There should be an appropriate descriptive title in the window. If you use external data - something that you didn't create yourself - unless it's largely in the public domain (e.g., clipart that is made universally available for free) make sure that you cite the source. The program should be written so that the data files (password file and images) will reside in the same directory as your program (so your marker doesn't have to waste time determining the structure assumed...those few minutes adds up over the course of marking all the assignments in a tutorial). If there are problems then your grade will be affected.

  1. Save button: When pressed this button will take the current information in the name and address and save it to a plain text file (unencrypted) called 'order.txt' which should be saved in the same directory as your program. The name information should sit by itself on the first line of the file while the second line (and successive lines - if appropriate) will consist of the address. Each line of the address from the JTextArea will reside on a separate line in the file containing the order information (the example shown in Figure 2 will create a order file with 4 lines: 1 for the name and 3 for the address). If you are still unsure then you should look at the sample order file 'order.txt'. It's the result of saving the order shown in Figure 2. The program does not have to read this information from the file. If the file already exists then the previous contents can be overwritten. During the save process the title bar of the main window should provide an appropriate status message (and the program should temporarily pause itself to provide the user with enough time to read it). Again you can refer to the approaches for pausing a program which were taught in 'GUIs' lecture.

  2. Clear button: When pressed the two input fields (name and address should be cleared of text).

As previously indicated clicking on the close window control will just shut the application down. Because the address field can consist of multiple lines (i.e., the user can hit enter to separate lines) hitting enter in the name field should have no effect (unlike the password field).

[Link to video showing a correct login & the shopping program in operation]

Program 2:

Modify the [starting program] so that it employs a simple recursive implementation to error check user input. (No credit will be awarded if the error checking uses iteration/looping rather than recursion). To simplify your solution Part 2 of the assignment *can* be completed by the use of a static method. Write the body of the promptForAge() method that will recursively prompt the user to enter an age so long as the value entered is outside the valid range of 1 - 144. After getting a valid age the program will display in main the value entered by the user. This means that the final value returned by this method must be within the valid range. [Example execution]

Marking:

  • If you have questions about your marking then the first person to talk to is your marker and that will be the person who teaches the tutorial in which you are officially registered. [Tutorial information] If you still have questions after this first step then feel free to contact your course instructor, just let me know that you talked to your TA first. Please do not come to the course instructor without taking the time to consult your TA first.
  • TAs will download this sheet and each student will get detailed feedback on this sheet (to be uploaded in the D2L Dropbox) about how their grade point was derived: [Marking spreadsheet].
  • Marking feedback. You will get a detailed marking sheet for each assignment that contains your TA's feedback. This marking sheet is uploaded in your D2L Dropbox. If you don't know how to access files that have been uploaded into D2L then follow this link [viewing uploaded files in the D2L Dropbox] 

Important points to keep in mind for all assignments:

  1. Due time: All assignments are due at 4 PM on the due dates listed on the course web page.  Late assignments or components of assignments will not be accepted for marking without approval for an extension beforehand. Alternate submission mechanisms (non exhaustive list of examples: email, uploads to cloud-based systems such as Google drive, time-stamps, TA memories) cannot be used as alternatives if you have forgotten to submit work or otherwise have not properly submitted into D2L. Only files submitted into D2L by the due date is what will be marked, everything else will be awarded no credit.
  2. Extensions may be granted for reasonable cases by the course instructor with the receipt of the appropriate documentation (e.g., a sworn declaration with a commissioner of oaths). Typical examples of reasonable cases for an extension include: illness or a death in the family. Example cases where extensions will not be granted include situations that are typical of student life: having multiple due dates, work commitments etc. You should mitigate the occurrence of technical problems by submitting your work early and often and early in D2L as well as performing regular backups. Do not expect to get an extension if something like this has occurred. If you request an extension from me let me know the name of your tutorial instructor and the tutorial number because the markers won't accept late submissions without directly getting an email from me.
  3. Method of submission: You are to submit your assignment using D2L [help link]. Make sure that you [check the contents of your submitted files] (e.g., is the file okay or was it corrupted, is it the correct version etc.). It's your responsibility to do this! (Make sure that you submit your assignment with enough time before it comes due for you to do a check).
  4. What to submit: Java programs should be submitted in the form of .java source code. Do not submit .class files.
  5. Identifying information: All assignments should include contact information (full name, student ID number and tutorial section) at the very top of your program in the class where the 'main()' method resides (starting execution point). (Note other documentation is also required for most of the full assignments).
  6. Collaboration: Assignments must reflect individual work; group work is not allowed in this class nor can you copy the work of others. Students should not see each other's graded programs (don't post it, don't email it out, don't show it in a screen share). For more detailed information as to what constitutes academic misconduct (i.e., cheating) for this course please read the following [link].
  7. Execution: programs must run on the computer science network (if applicable during that particular semester) running the latest version of Java (this is what applies for the distance learning version of the course). If there libraries or classes external to what's included in Java then you must include clear and complete instructions for your marker as to exactly what needs to be done to compile and run your submission otherwise you may be awarded no credit. Also you should be wary of using external libraries rather than writing the code yourself because you may not be awarded credit for particular features if you didn't write the code yourself. If you write you code in the lab and work remotely using a remote login program such as Putty or SSH then you should be okay (assuming you don't login to a non-Linux computer). If you choose to install Java on your own computer then it is your responsibility to ensure that your program will run properly here. It's up to you if you wish use the graphical program builder to write/run your programs but if you do you submit your program in the form of text ".java" file or files.
  8. Use of pre-created  libraries: unless otherwise told you are to write the code yourself and not use any pre-created classes. For this assignment the usual acceptable functions include code in the Scanner class and methods for displaying output such as: printf()print()println(). Check the specific assignment requirements for other classes that you may be allowed to use.
  9. Late submissions Make sure you give yourself enough time to complete the submission process so you don't get cut off by D2L's deadline (when you get a zero). Unlike the mini-assignments you may be able to submit your work late and be awarded some credit.

Submission received:

On time

Hours late : >0 and <=24

Hours late: >24 and <=48

Hours late: >48 and <=72

Hours late: >72 and <=96

Hours late: >96

Penalty:

None

-1 GPA

-2 GPA

-3 GPA

-4 GPA

Submission not graded.

Submitting your work:

  • The document must be electronically submitted using D2L.
  • It's recommended that you submit your work early and often to avoid problems such as forgetting the due date or problems with your computer (hardware failures, malicious programs etc.). Reminder: you will not be granted special considerations such as extensions in these cases!

D2L configuration for this course

  • Multiple submissions are allowed for this assignment (all versions are kept in D2L): You can (and really should) submit work as many times as you wish before the due date. Due dates are strict, only what is in D2L by the deadline is what will be marked. Other methods of verifying that your work was completed on time (e.g. checking timestamps, emailed files etc.) will NOT be accepted. However only the latest version of all the files is what will be marked, everything else will be ignored (because it is not fair to your marker to sort through multiple versions of your files).
  • Do not use compression utilities (such as zip) or archiving utilities (such as tar) otherwise your submission may not be marked. The space savings in D2L is not worth the extra time required by the marker to process each submission.
  • Make sure that you [check the contents of your submitted files] (e.g., is the file okay or was it corrupted, is it the correct version etc.). It's your responsibility to do this! (Make sure that your submit your assignment with enough time before it comes due for you to do a check).