|
|
|
|
Points: 95 + 5 (bonus) Due: 11/13/2000. What to turn in: Turn in a disk with all the answers to this assignment. Note that all files are to be put in their respective folders. That is, all files for lab x are to put in the folder A:\LABx, where x is the lab # and all files for assignment y are to be put in the folder A:\ASSIGNy, where y is the assignment #. For java applications, turn in the *.java and *.class files. For a question that involves an answer in simple text, turn in a *.txt file. For java applets, turn in the *.java, *.class, and *.html files.
[Java Data Structures: Hashtable] 1. (a) [15 points] Do this question using a Java application. Create a hashtable with the following:
Now write a method that takes a hashtable (see the method signature below) and prints
where N is the # of entries found in the hashtable. Test your code using the hashtable you created above. (Make sure that your program works for any hashtable, not just one that contains 3 entries! Namely, don't hard code the size of the hashtable in your method.) Hint: the method elements() from Hashtable returns all the elements in a hashtable. The return type is Enumeration. Check it out! The method signature should look like (note that the method is a static method, this is so that it can be called from the main()) : public static void printPersonPhones (Hashtable ht) { ... } (b) [5 points] If a person is allowed to have multiple phones, how would you create the hashtable? Discuss at least two possibilities of handling this requirement. (Write your answer to this in the beginning comment block of part (c) of this question. (c) [5 points] Use a Vector to handle the situation in part (b). Check out the class Vector in the java.util package. You are to put a couple of telephone numbers for some or all of the names given in part(a). [Processing HTML form, servlet] 2. [30 points] Do this question using an HTML form and a servlet. Write a program to have a client send the login ID and password to the server and have the server validate the ID and password against a list of IDs/passwords that the server maintains. (To receive full credits, all that you need to do is to hard code the IDs and passwords in the servlet. For bonus credits, implement the list on a database (see below).) Respond appropriately to the user depending on the outcome of the validation from the server. The client needs to have a GUI front-end. Use loop back address (i.e., http://localhost:8080/examples/servlet/... ) for testing purposes. You need to make sure that the servlet and HTML document are put in the appropriate directories, as discussed in class. Also, use the following table for validating the IDs and passwords.
To avoid name conflicts, you are to name your HTML and servlet with the naming convention of: LFddddLogin.html and LFddddLoginServlet.class (e.g., LB1234Login.html, LB1234LoginServlet.class) where L = Lastname initial, F = Firstname initial, dddd = last 4 digits of SS# For bonus credit [5 pts]: Connect to an Access database with the data store name LoginDB. (You don't need to turn in your *.mdb file as I will have one that is ready to test your program. You can copy this database from me if you wish. It is also in T:\ACS368\Summer00\LoginDB.mdb.) The table name is IdPassword, the column names are ID (a numeric field) and Password (a text field). [General Java + DB topic] 3. [5 points] For the following question, refer to the JDBC section of your textbook (starting at page 1073). (a) Nowadays, applications are commonly partitioned into ____ tiers. (b) What are the tiers? Briefly describe the purpose of each of them. (c) What are benefits of using this multi-tiered approach to application design? [Applet, Event handling] 4. [25 points] In this question, you are to modify the ToDoList example (source: ToDoList.java) and add the follwing functionality:
Hint: Since a list allows you to maintain only a collection of strings, you need a separate data structure to store the To-Do item and its description. An example is the Hashtable data structure that you have seen in class (and also in Question 1). Each time you need to add an item, add it to the hashtable as well as the list. You can check if a key is already present before you perform the addition. Note that there is the class java.awt.List and there is the interface java.util.List (confusing naming scheme!) in Java. Thus, you need to fully qualify the List component with java.awt.List when you want to create a List object. (e.g., list1 = new java.awt.List(); and not just list1 = new List();) Otherwise, the compiler will give an error on ambiguous List reference! (We did not have to worry about this in the original ToDoList example because we did not use the java.util package. You need this package if you are going to use Hashtable.) If you use the source: ToDoList.java, you should be OK since I have already made the changes for you. The behaviors of your applet should mimic the one given in ToDoWithDesc. Note that if you try to add the same To-Do item, it won't let you. The Java console displays the message that says it is already in the list. 5. [10 points] In this question, you are to compare and contrast an interface (discussed in class) with an abstract class (new!). List at least 3 similarities and 3 differences. Some discussion points include: abstract methods, mandatory implementation, class vs. interface keywords, regular (i.e., non-abstract) methods allowed or not, etc. |