Problem specification.
In a client-server system, the client application sends requests to a server application through a network connection. In such system, the user interface is implemented in the client and the database is stored in the server.
You are required to implement a client-server application to process banking transactions such as withdrawals and deposits. In modern banking systems, a costumer accesses a bank account using an access card at an ATM, at the counter or on the web.
• Implementation.
The following diagram illustrates the classes for the client-server banking
application.
Main class
Client class
Server class
Network class
Transactions class
Accounts class
Winter 2021 Page 1
▪ Network class.
The Network class provides the infrastructure to allow the client and the server to process the transactions. The client and the server need to be connected (using connect()) to the network prior to an exchange. The Network class also implements an input buffer (inComingPacket[]) and an output buffer (outGoingPacket[]) to respectively receive transactions from the client and to return updated transactions to the client. The capacity of these buffers are 10 elements, so the network indicates whether they are full or empty.
- ▪ Client class.
The Client class reads all the transactions from a file (transaction.txt) and saves them in an array (transaction[]). A transaction is implemented by the Transactions.class.
Using the send() method of Network class the client transfers the transactions to the network input buffer and it yields the cpu in case the network input buffer is full.
Also, using the receive() method of Network class the client retrieves the updated transactions from the network output buffer and yields the cpu in case the buffer is empty. Each updated transaction received is displayed immediately on the console. - ▪ Server class.
The Server class reads all the accounts from a file (account.txt) and saves them in an array (account[]). An account is implemented by the Accounts class. Using the transferrIn() method of Network class the server retrieves the transactions from the network input buffer and performs the operations (withdraw, deposit, query) on the specific accounts. It yields the cpu in case the buffer is empty.
Each updated transaction is transmitted to the network output buffer using the transferOut( ) method of Network class and the server yields the cpu in case the buffer is full.• Problems.
▪ You need to complete the Java program that is provided by implementing 4 threads so that the client, the server and the network all run concurrently. The client has 2 threads, one for sending the transactions and another for receiving the completed transactions.
In case the input and output network buffers are full or empty each client or server thread must yield the cpu using the Java method Thread.yield(). The network thread executes an infinite loop that ends when both client and server threads have disconnected. In case the client or sever threads are still connected the network thread must continuously yield the cpu.
Winter 2021 Page 2
- ▪ You must record the running times of both client threads and the server thread using the Java method System.currentTimeMillis().
- ▪ You need to provide output test cases with the appropriate running times for the client and the server threads. Perform 3 different runs of the program and explain why there is a difference in the running times.
• Sample output test cases.
▪ See attached text files.
• Evaluation.
You will be evaluated mostly on the implementation of the required methods, the
implementation of the threads, the measurements sharing of the cpu by the threads.
▪ Evaluation criteria
Implementation of the 4 threads Implementation of the main class Answer to a question during the demo
Implementation of the yield( ) method
Implementation of the measurements of the running times
Output test cases including running times
• Required documents.
of the running times and the voluntary
35% 15% 10%
10% 10% 20%
|
Criteria |
Marks |
- ▪ Source codes in Java.
- ▪ Output test cases.
- ▪ I have included DEBUG flags in the source code in order to help you trace the
program but once your program works properly you should put the DEBUG flags in comments.
• Submission.
▪ Create one zip file, containing the necessary files (.java, .txt and test cases). If the assignment is done individually, your file should be called pa1_studentID, where pa1 is the number of the assignment and studentID is your student ID number. If the work is done in a team of 2 people, the zip file should be called pa1_studentID1_studentID2 where studentID1 and studentID2 are the student ID numbers of each student.
Winter 2021 Page 3
▪ Upload your zip file on moodle under Programming Assignment 1 before the due date.
• IMPORTANT (Please read very carefully):
A demo will take place with the markers afterwards. Markers will inform you about the details of demo time and how to book a time slot for your demo. If working in a group, both members must be present during demo time. Different marks may be assigned to teammates based on this demo.
- ▪ If you fail to demo, a zero mark is assigned regardless of your submission.
- ▪ If you book a demo time, and do not show up, for whatever reason, you will be
allowed to reschedule a second demo but a penalty of 50% will be applied.
- ▪ Failing to demo at the second appointment will result in zero marks and no more
chances will be given under any conditions.
• Disclaimer.
▪ Note that this code has been tested on Windows. You may need to make changes if you would like to run on other OS. However, you are not permitted to change the implementation of the source code provided nor change the data types and sizes but you should only implement the features as required.
Winter 2021 Page 4
Account
• Detailed implementation of the classes NETWORK
SERVER
Out Buffer
In Buffer
CLIENT
▪ Client class
-send() -receive() -transferIn() -transferout()
Client
|
|
Client(String operation) +getNumberOfTransactions( ) : int +getClientOperation() : String +setNumberOfTransactions(int nbOfTrans) : void +setClientOperation(String operation) : void +readTransactions( ) : void +sendTransactions( ) : void +receiveTransactions(Transactions transact) : void +toString( ) : String |
Winter 2021
Page 5
▪
Transaction
▪ Transactions class
Transactions
|
|
Transactions( ) |
▪ Server class
Server
|
– numberOfTransactions : int /* total number of transactions received */
/* total number of accounts saved */ /* maximum number of accounts */ /* a transaction to process */ / * handle to access network methods */ /* account array */ |
|
Server( ) |
Winter 2021
Page 6
▪ Accounts class
Accounts
/* unique account number */ /* last name of account holder */ /* account balance */ |
|
+ getAccountNumber( ) : String + getAccountType( ) : String + getBalance( ) : double |
▪ Network class
Network
/* IP of client application */ /* IP of server application */ /* capacity of network buffers */ /* network input buffer */
int /* buffer index position */ |
|
Network(String context) + getClientIP( ) : String + getClientConnectionStatus( ) : String + getServerConnectionStatus( ) : String + getInBufferStatus( ) : string + getNetworkStatus( ) : String + getInputIndexClient( ) : int |
Winter 2021
Page 7
+ setPortID(int pid) : void
+ setClientConnectionStatus(String connectStatus) : void + setServerConnectionStatus(String connectStatus) : void + setNetworkStatus(String netStatus ) : void
+ setInBufferStatus(String inBufStatus) : void
+ setOutBufferStatus(String outBufStatus) : void
+ setInputIndexClient(int i1) : void
+ setInputIndexServer(int i2) : void
+ setOutputIndexClient(int o2) : void
+ setOutputIndexServer(int o1) : void
+ connect(String IP) : boolean
+ disconnect(String IP) : boolean
+ send(Transactions inPacket ) : boolean
+ receive(Transactions outPacket) : boolean
+ transferOut(Transactions outPacket ) : boolean
+ transferIn(Transactions inPacket) : boolean
+ toString( ) : String
+run() : void
Winter 2021 Page 8





