An open API service indexing awesome lists of open source software.

https://github.com/rohan-bhautoo/gym-software

The Gym-Software is a network application, based in Java, which utilises multi-threaded programming and is connected to a database.
https://github.com/rohan-bhautoo/gym-software

java multithreading network-application server-client-application socket-programming

Last synced: 3 months ago
JSON representation

The Gym-Software is a network application, based in Java, which utilises multi-threaded programming and is connected to a database.

Awesome Lists containing this project

README

        




Gym Software



Version
Java
MariaDB
JDK

## Description
> The Gym Software is a network application, based in Java, which utilises multi-threaded programming and is connected to a database. The software implementation will enable staff members to add, update, delete and view the bookings of each client.
>
> With the use of multi-threading, the Gym Software will be accessible to mutiple clients to connect at the same time and interact with the database.



## Prerequisite

### Java Development Kit (JDK)
> JDK version 11 is used for this project as it includes the JavaFX library. Download it [here](https://www.oracle.com/java/technologies/javase/jdk11-archive-downloads.html).
>
> For Windows:
```sh
set JAVA_HOME="C:\[Path to folder]\Java\jdk-11.0.14
```
> Enter the Environment Variables in System Properties.
>
> Add **%JAVA_HOME%\bin** into Path.
```sh
%JAVA_HOME%\bin
```



### MariaDB
> MariaDB Server is one of the most popular open source relational databases. It’s made by the original developers of MySQL and guaranteed to stay open source. It is part of most cloud offerings and the default in most Linux distributions. Download it [here](https://mariadb.org/download/).
>
> The five tables below will be used to store information in the database.


Trainer
Client
Specialism
Booking
TrainerSpecialism



| TrainerID (PK) |
| :------------- |
| Name |
| Sex |
| Phone |


| ClientID (PK) |
| :------------ |
| ClientName |
| Weight |


| SpecialismID (PK) |
| :---------------- |
| Focus |
| Duration |
| Cost |


| BookingID (PK) |
| :---------------- |
| BookingDate |
| StartTime |
| ClientID (FK) |
| SpecialismID (FK) |
| TrainerID (FK) |


| SpecialismID (FK) |
| :---------------- |
| TrainerID (FK) |

### JDBC Driver
> A JDBC driver is a software component enabling a Java application to interact with a database.
>
> To connect with individual databases, JDBC (the Java Database Connectivity API) requires drivers for each database. The JDBC driver gives out the connection to the database and implements the protocol for transferring the query and result between client and database. Download the JDBC Driver [here](https://www.mysql.com/products/connector/).

## Software Design
> A Server-Client setup refers to socket programming in Java where a client sends messages to the server and the server shows them using a socket connection.
>
> A socket in Java is one endpoint of a two-way communication link between two programs running on the network. A socket is bound to a port number so that the TCP layer can identify the application that data is destined to be sent to.



### Server
> The server will instantiate its object and wait for the client request. Once the client sends the request, the server will communicate back with the response.
>
> The ServerSocket is binded to the port number 8080, which is passed as an argument to the constructor of the class ServerSocket.
```java
final int PORT = 8080;
try (ServerSocket serverSocket = new ServerSocket(PORT)) {
while (true) {
Socket socket = serverSocket.accept();
new Thread(new ServerRunnable(socket)).start();
}
}
```

> The getOutputStream() method is used to send the output through the socket.
```java
OutputStream outputStream = socket.getOutputStream();
```

> The getInputStream() method is used to receive messages, through the socket, from the Client side.
```java
InputStream inputStream = socket.getInputStream();
```

> Database connection is set in the [ServerRunnable.java](/Gym%20Software/src/ServerRunnable.java).
```java
private Connection connection = Database.connectDb();
```

### Client
> In order to establish a connection to the server, a socket is required.
```java
String hostName = "localhost";
int port = 8080;
Socket socket = new Socket(hostName, port);
```
> where the first argument is the IP addres of Server (127.0.0.1/localhost) and the second argument is the TCP port which will be the same on the server-side.

### Testing
> Testing shows that the software has meet its requirements and it is printing the expected output.

#### Validation Testing
> Before sending data to the server, the client side must validate the user input. In the gym software, regex expressions are used to validate all user inputs from console.

##### IDs
```java
^[B][0-9]{3}+$
```

> The ^ symbol means the start of the string which is the user input and $ sign is end of string. In the regex above, the string must always start with a capital B and continue with only 3 numeric values.
>
> Examples:
>
> Good format: B001, B123, B999
>
> Bad format: C001, B0001, JC21, BB01
>
> The same format is used to validate the trainerID, SpecialismID and ClientID.

##### Date
```java
\d{4}\\-(0?[1-9]|1[012])\\-(0?[1-9]|[12][0-9]|3[[01])*
```
> The “\\d{4}” ensures that the user input for year is YYYY. The “(0?[1-9]|1[012])” part checks if user months input is between 01 to 12. And the last part allows only numbers between 01 to 31 to be accepted.

##### Time
```java
([01]?[0-9]|2[0-3]):[0-5][0-9]
```
> It ensures that the time is between 00:00 to 23:59. Even 9:0 is accepted but it will be reconverted to 09:00 in the table booking.

## Usage
> After installing MariaDB, import the table from [SQL](/Gym%20Software/src/SQL/GymTable.sql) folder, to the database, using the following command.
```sh
mysql -u root -p
```

```sh
source C:\[Path to folder]\SQL\GymTable.sql
```
> The [Server.java](/Gym%20Software/src/Server.java) will have to be executed first, then the [Client.java](/Gym%20Software/src/Client.java).
```sh
javac *.java
```
```sh
java Server
```
```sh
java Client
```

### Commands
> Use the following commands in order to use the software.

#### Add Booking
```sh
ADD
```

#### List All Bookings
```sh
LISTALL
```

#### List Personal Trainer
```sh
LISTPT
```

#### List Client Bookings
```sh
LISTCLIENT
```

#### List Booking Date
```sh
LISTDAY
```

#### Update Booking
```sh
UPDATE UPDATE
```

#### Delete Booking
```sh
DELETE
```

## Author

👤 **Rohan Bhautoo**

* Github: [@rohan-bhautoo](https://github.com/rohan-bhautoo)
* LinkedIn: [@rohan-bhautoo](https://linkedin.com/in/rohan-bhautoo)

## Show your support

Give a ⭐️ if this project helped you!