Skip to content

rohan-bhautoo/Gym-Software

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

24 Commits
 
 
 
 
 
 
 
 

Repository files navigation

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.

For Windows:

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.

%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.

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.

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.

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.

OutputStream outputStream = socket.getOutputStream();

The getInputStream() method is used to receive messages, through the socket, from the Client side.

InputStream inputStream = socket.getInputStream();

Database connection is set in the ServerRunnable.java.

private Connection connection = Database.connectDb();

Client

In order to establish a connection to the server, a socket is required.

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
^[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
\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
([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 folder, to the database, using the following command.

mysql -u root -p
source C:\[Path to folder]\SQL\GymTable.sql

The Server.java will have to be executed first, then the Client.java.

javac *.java
java Server
java Client

Commands

Use the following commands in order to use the software.

Add Booking

ADD <BookingID> <BookingDate> <StartTime> <ClientID> <SpecialismID> <TrainerID>

List All Bookings

LISTALL

List Personal Trainer

LISTPT <TrainerID>

List Client Bookings

LISTCLIENT <ClientID>

List Booking Date

LISTDAY <BookingDate>

Update Booking

UPDATE UPDATE <BookingDetail> <NewValue> <BookingID>

Delete Booking

DELETE <BookingID>

Author

👤 Rohan Bhautoo

Show your support

Give a ⭐️ if this project helped you!

About

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

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages