I know this is
alot but I am stuck, the code below is what I have come up with so far from are instructor example, any Ideas, or correction would be greatly appreceiated.
Requirements:
In a single source file named App.java, define a public class named App that can be run as either a multithreaded Windows server or as a Windows client to process a telephone directory. Two other non-public classes must also be defined. One, named Person, will encapsulate the data and processing of a person. The other, named ServerThread, will define the processing of a server
thread for each client.
The server (via its threads) will handle client requests to add, find, and delete Person objects maintained within a HashMap using the person's name as the key. It must store the HashMap to disk when it is shutdown and reload the HashMap from disk when it is restarted.
The client will provide a GUI front-end for adding, finding, and deleting Person objects.
Define a serializable Person class outside of the App class. It must only encapsulate name (
String) and phone number (String). Code a single constructor to instantiate an object using values received for both instance variables. Provide simple "set" and "get" methods (setName(), getName(), etc.) to store and retrieve the value of each instance variable. Do NOT be concerned with editing the values of the instance variables.
Define the App class for a Windows program that will immediately ask the user to specify the processing mode (client or server). The technique for determining the processing mode is up to you (Choice, Checkbox, Buttons, etc.). Based upon the mode, processing is as follows:
Server processing
Using a FileDialog, ask the user for the name and location of the telephone directory file. If the specified file has a length other than zero, read it as a HashMap. Otherwise, instantiate a new HashMap for the telephone directory.
Loop to accept client logins. When one occurs, construct a new ServerThread with references to its Socket and the HashMap. Then, call the thread's start() method to begin its processing.
When the Window is closed, destroy all threads and write the HashMap to disk.
ServerThread processing
During construction, establish an ObjectInputStream and an ObjectOutputStream for the socket.
The run() method must handle client requests to add a Person to, find a Person in, or delete a Person from the HashMap. Develop your own scheme for transaction codes but be sure to:
Send a String object to the client indicating the success or failure of an add or delete transaction. For example, "person added", "person already exists", "person deleted", or "person not found".
Send a Person object to the client for a find transaction. If the person was not found within the HashMap, send a Person object having null values for name and phone number. Otherwise, send the found Person object.
Synchronize code to prevent two threads from working with the HashMap at the same time.
Provide a destroy() method to kill the thread.
Client processing
Provide a GUI with text fields for entering and displaying the person's name and phone number. Use buttons to trigger Add, Find, and Delete operations, and a text field or text area for displaying messages. The Delete button should only be enabled after a Find operation has succeeded. The choice of layout, colors, and fonts are up to you.
When Add is selected, verify that all data is present. If it is, construct a Person object, send it to the server as part of an add transaction, and read and display the server's reply. If not all data is present, send nothing to the server but display an error message.
When Find is selected, verify that the person's name is present. If it is, send the person's name to the server as part of a find transaction, read and display the server's reply, and enable the Delete button if the transaction was successful (note that after a successful find transaction, the person's name and phone number should appear on the screen). If the person's name is missing, send nothing to the server but display an error message.
When Delete is selected, verify that the person's name is present. If it is, send the person's name to the server as part of a delete transaction, read and display the server's reply, and disable the Delete button. If the person's name is missing, send nothing to the server but display an error message.