Objectives

This assessment item is designed to test your understanding in Java TCP networking, Java Object Serialization/Deserialization, threading, file reading and writing using a client/server application development.

Assessment task

CQU aquatic centre offers swim facility to current students and their families. Entry to the swimming centre is accessible through any of the three automatic doors by keying in a registered student number followed by a 4-digit pin code preferably set to the year of birth. Each entry is charged a flat fee and the time should be persisted to a log file with two fields (student number space separated with entry date and time). Because of the flat fee structure, the entry details can be shared among family members. The system should accommodate both existing users with authentication and provide registration for new users. Administrator role is not relevant and will be discussed in the second assignment. The application should be implemented as a client/server model using java TCP sockets. The client program handles all the data entry and menu selections (1. Current Student 2. New Student 3. Exit). Current student should only be prompted for a student number and a pin code. New student registrations should be prompted to provide relevant details (Student number and a Pin Code). Appropriate error messages (Student exists, Un- Registered Student, Invalid Pin, Welcome or Student Created) should be received from the server after processing and displayed on the client. Student number is alphanumeric but cannot be empty. The client should create an instance of relevant type before sending to the server program for processing and storage. Every 3 minutes the contents from the data structures stored on the server need to be persisted to the text files. The server program should have the capability to concurrently handle multiple client connections (Thread-per-connection). Existing records are to be read and loaded from the provided text files ("studententry.txt" and logentry.txt). When these text files do not exist, the system should handle this event and create new files.

Coding and Design

You can use the following class descriptions as a guideline for your design.

(At minimum two java files should be used)

Student: This class should implement serializable (Refer to figure 1).

LogEntry: This class should implement serializable and comparable interface to use an inbuilt java Collections.sort() method. (Refer to figure 1).

Example) SimpleDateFormat formatter = new SimpleDateFormat("dd/MM/yyyy-HH:mm:ss");

WriteToFile: This class persist all the contents from the data structures to the text files.

TCPClient: This class handles the data entry with suitable menus and interacts with the user. This program creates an instance of (Student /LogEntry / String) on user selection before sending it to the server. Socket, ObjectInputStream and ObjectOutputStreamfor for TCP Connection should be used. The program should allow the client to enter the details for multiple entries.

TCPServer: This server loads existing records from the text files ("studententry.txt" and logentries.txt) to appropriate data structures preferably an ArrayList. A timer function should be used to regularly schedule the contents of the ArrayList to be written to the two text files every 3 minutes. The logentries.txt should contain entries sorted by the student number. The server program should be running indefinitely ready to communicate with all future clients.

Figure 1 (Design): see image.

Your program should check user inputs for potential error and allow user to re-enter details where appropriate. The source code should be formatted properly following good programming practice (appropriate variable names, indentation, comments, etc.)

Sample Screenshots

The following screenshots show example outputs of the above program. You should only use these as references. Your program outputs can be similar but not necessarily the same.

Structure of studententry.txt and logentry.txt (two fields space separated) with Client/Server program interaction.

Studententry.txt: see image.

Logentry.txt: see image.

Client1: see image.

Client2: see image.

Output of TCPServer: see image.

Report

Include an end user instruction and test manual. Run the program and take screenshot of program outputs for all tests with annotations. The test should demonstrate that your TCPServer can accept connections from more than one TCPClient. Provide screenshots of your "studententry.txt" and logentry.txt.

Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.