Report
Report
The user requirement specification of this report is aimed at creating commission calculation
system for Sharaf DG Company, for the computation of the commission for sales
representatives depending on the sales of laptops. The system has been developed in based
on client-server model and has database for storing the charge rates. The project is divided
into four tasks:
The first task entails, developing a database and entering charge rates.
Hence, in task 2, the client-side program to interact with the server is emphasized.
This task goes through the server-side program that computes for commissions.
The utility functions for database operations are included in the Task 4..
2. Task 1 – Database
The first task is to establish a MySQL database in order to store charge rates concerning sales
representatives. There is a table in the database SharafDG known with the name ChargeRates;
this table stores charge codes and commission rates. The charge code will be an integer value,
while the charge rate constitutes a decimal value for percentage commission.
First of all, we need to create the database that will contain our ChargeRates table. You can do
this either with the graphical front-end application MySQL Workbench or directly on the
command line interface, MySQL CLI.
Now, let's create a table named ChargeRates with the fields ChargeCode and ChargeRate. We'll use an
appropriate data type for each field.
Column 1:
oName: ChargeCode
oData Type: INT
oAttributes: PRIMARY KEY
oEnsure this field is not nullable and is set as the primary key.
Column 2:
o Name: ChargeRate
o Data Type: DECIMAL(5, 2) (This allows for values like 10.00 or 5.00)
Now that the table is created, let's insert at least five records. The charge rates will be stored as
per the requirements:
To verify that the records have been inserted correctly, you can use the SELECT statement.
In MySQL, roles are often associated with user management. If you need to assign a specific
database server role to a user (such as read-only or administrative privileges), you can create and
assign roles in MySQL.
Coding:
USE SharafDG;
-- Create the table
);
(1, 10.00),
(2, 5.00),
(3, 0.00),
(4, 7.50),
(5, 3.00);
The client side program takes as input the Sales Representative ID and the number of laptops
sold. It connects to the server and passes the data for the computation of commission. On getting
the result from the server, the client shows the sales profit, the charge rate that has been applied
and the commissions gotten.
Code:
import java.io.*;
import java.net.*;
import java.util.Scanner;
@Override
public void run() {
try {
// Connect to the server
Socket socket = new Socket("localhost", 8080);
DataOutputStream out = new
DataOutputStream(socket.getOutputStream());
out.writeInt(repId);
out.writeInt(laptopsSold);
socket.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
This client program takes the input of the representative ID from the user as well as the number
of laptops sold by them. It creates a thread to deal with the communication with the server then
sends the data and shows the value of commission that get from the server.
The client side sends the Sales Representative ID and the number of laptops sold to the server
side program. It uses the current number of laptops sold to calculate sales profit; it then access
the proper charge rate and compute the commission before sending the returns to the client.
Code:
import java.io.*;
import java.net.*;
import java.sql.*;
// Calculate commission
double commission = salesProfit * chargeRate / 100;
socket.close();
} catch (IOException | SQLException e) {
e.printStackTrace();
}
}
private double getChargeRate(double salesProfit) throws SQLException
{
double rate = 0.0;
ResultSet rs = ps.executeQuery();
if (rs.next()) {
rate = rs.getDouble("ChargeRate");
System.out.println("Found charge rate: " + rate);
} else {
System.out.println("No charge rate found for ChargeCode:
" + chargeCode);
}
}
return rate;
}
}
The server waits for a connection request from the clients and processes the request based on the
type of client request made. This is because it determines the sales profit concerning the number
of laptops sold, extracts the charge rate from the database, and finally determines commission. It
produces such results and brings them to the client.
The utility class provides methods to manipulate a collection, such as adding elements, searching
for a specific element, and removing elements based on a given scenario.
The utility class DatabaseUtil provides a method to obtain a connection to the MySQL database,
centralizing database connection management and ensuring consistency.
Code:
SalesUtility
import java.util.*;
public SalesUtility() {
salesList = new ArrayList<>();
}
// Add element
public void addSale(String sale, int index) {
salesList.add(index, sale);
System.out.println("Sale added: " + sale);
}
// Search element
public void searchSale(String sale) {
if (salesList.contains(sale)) {
System.out.println("Sale found: " + sale);
} else {
System.out.println("Sale not found.");
}
}
}
Conclusion
In this report, the author presents an overview of the commission calculation system for Sharaf
DG. The system is comprised of two parts, the client and the server where the client is
responsible for the data collection, communication with the server and presentation of
commission results. The server program then calculates commissions according to the profit of
the sales and gets the correct charge rate from a MySQL database. The report also points out use
of a utility class stating that it can be used to reduce the number of times someone has to open
connections to a database.
8. References: