The main purpose of this application is to perform mathematical calculations and return the data back to the user.
The program consists of 2 parts - the server and the client:
math-app-server 👉🏻 click here to see the source code on GitHub
math-app-client 👉🏻 click here to see the source code on GitHub
CLICK HERE to see the website!
To write this project I used Java Networking Programming tools (java.net) and it's designed to handle several math clients, meaning, it is a multi-threaded system.
For this purpose, I used Java's Thread Object and implemented the singleton pattern as only 1 server should exist per application.
In addition, throughout the program I used additional design patterns such as Factory pattern and Mediator pattern.
Plus, on the client server, I added a thread that listens to all input from the server, logs INFO messages and documents data to a local log file.
I wrote this program inspired by a good friend of mine who is very close to my heart.
He is a former lecturer at John Bryce College, he helped me a lot and was by my side in my first steps in the programming field, he is the ultimate mentor, and I will always be grateful to him.
Okay, so... shall we dive into more details?
I will be covering here the main purpose of each class, extra details about each method can be found in the source code.
This class is the starting point of the math-app-server, this class contain a method with a reference to MathServer class that will be generated an instance of a ServerSocket
Designed to handle multiple math clients, implements the singleton pattern as only 1 server should exist per application.
This class instantiates different threads who handle different clients.
Designed to provide services for a single math-app-client.
This class is the one the communicates de facto with math-app-client.
- has a method named eventLoop() – that will be call the MathOperationFactory in runtime.
Implementing the factory pattern, responsible for identifying math operations that received from the math-app-client and creating the right object accordingly.
MathOperation class is an abstract class.
The main method in this class is named perform(), this method parses commands received from the math-app-client.
This class will be extended by all the command types that exist in this system (see more details below).
Each one of those sub-classes will be performing and using the methods in this abstract class, and must implement the actual calculation parsenCalc(String n1, String n2) method.
The Addition class extends MathOperation abstract class, the main method in use here is the one that performs the calculation de facto - parseAndCalc(String n1, String n2).
The Subtraction class extends MathOperation abstract class, the main method in use here is the one that performs the calculation de facto - parseAndCalc(String n1, String n2).
The Multiplication class extends MathOperation abstract class, the main method in use here is the one that performs the calculation de facto - parseAndCalc(String n1, String n2).
The Division class extends MathOperation abstract class, the main method in use here is the one that performs the calculation de facto - parseAndCalc(String n1, String n2).
I also added class that contain constant values and 2 custom exception classes.
I will be covering here the main purpose of each class, extra details about each method can be found in the source code.
This class is the starting point of the math -app-client, this class contains a method with a reference to MathOperationClient class that will generate a Socket.
MathOperationClient class, designed to enable sending requests from the client to the server.
This class is the one the communicates de facto with math-app-server, an object of the class should be instantiated in order to connect to the server.
This class is designed to perform as a log file manager.
I added a thread that listens to all input from the server, logs INFO messages and documents data to a local log file.
This class implements the Mediator pattern, synchronizes the IO operations between logging threads and MathOperationClient.
I also added class that contain constant values:
Thanks for reading,
Chelly 👩🏻💻