You are on page 1of 44

SUBMISSION OF

CSC584 ENTERPRISE PROGRAMMING


INDIVIDUAL ASSIGNMENT 2 (15%)

NAME : NUR MAISARAH BINTI NOR AZHARLUDIN _______________

STUDENT ID : 2019294714_________________________________________

DATE OF SUBMISSION : 4/7/2021____________________________________________

SIGNATURE : ___________________________________________________

I CERTIFY THAT THIS ASSIGNMENT IS MY OWN ORIGINAL WORK AND MATERIALS HAVE
NOT BEEN COPIED FROM ANY OTHER WORK (PUBLISHED OR OTHERWISE) WITHOUT
ACKNOWLEDGEMENT IN THE TEXT. I AM FULLY AWARE OF THE PENALTY OF
PLAGIARISM.

Note: Submit soft copy of report (.pdf), source code of project folder (.zip) and database file (.sql)
via Google Classroom.
MVC (Model-View-Controller) is a design pattern that separates the business logic, presentation
logic and data. Controller acts as an interface between View and Model and intercepts all the
incoming requests. Model represents the state of the application i.e. data. It can also have
business logic. View represents the presentation i.e. UI (User Interface). Based on Assignment
1, complete each of the following requirements:

Question 1

Design the interface (i.e. web page) that displays the list of all data and allows the user to add,
update, and delete the data. Briefly explain and include the screenshots of the interface.

This is the webpage for List Customer. In this page, we can view, update and delete the respective
customer. We can also add customer or add report at this page by clicking the respective button.

The button Delete will make all the information of the respective customer is deleted permanently
including in the database but if the Customer ID is related to any report, the customer cannot be
deleted unless the report that is related to that Customer ID is deleted first.
This is the page that will be displayed after we click the button View at the respective customer.
All the customer’s information will be displayed. We can also go back to the list of customers page
by clicking the button Customer List.

This is the page that will be directed after we click the button Update from the List Customer page.
This is the update page for the customer. The customer information can be updated but the
Customer ID cannot be updated, it is for displayed only. If we click the submit button, the new
information of the customer can be updated and directly displayed the List Customer page. We
can also click the button List Customer if we want to go back to the List Customer page.
This is the webpage for Add Customer. In this page, a new data for a new customer is added and
it will appear at the list customer page. If we do not want to add a new customer, we can click the
List Customer button and we will be directed back to the list customer page. The customer ID is
auto generated by the system so we do not need to insert the ID.
This is the webpage for List Report. In this page, we can view, update and delete the respective
report. We can also add customer or add report at this page by clicking the respective button.

The button Delete will make all the information of the respective report is deleted permanently
including in the database.

This is the page that will be displayed after we click the button View at the respective report. All
the respective report’s information will be displayed. We can also go back to the list of repots page
by clicking the button List Report.
This is the page that will be directed after we click the button Update from the List Report page.
This is the update page for the respective report. The report information can be updated but the
Report ID cannot be updated, it is for displayed only. If we click the submit button, the new
information of the report can be updated and directly displayed the List Report page. We can also
click the button List Report if we want to go back to the List Report page.
This is the webpage for Add Report. In this page, a new data for a new report is added and it will
appear at the list report page. If we do not want to add a new customer, we can click the List
Report button and we will be directed back to the list report page. The report ID is auto generated
by the system, so we do not need to insert the ID. We also need to choose the customer for which
customer that make the report. The customer is the fk from the table so, the customer ID is
directed to the report table and displayed in the report form.
customerform.jsp

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"


pageEncoding="ISO-8859-1"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Customer Service | SUBWAY</title>
</head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="css/style.css">
<link rel="stylesheet" href="https://www.w3schools.com/w3css/4/w3.css">
<link rel="stylesheet"
href="https://fonts.googleapis.com/css?family=Lobster&effect=shadow-multiple">
<body>
<div class="main-block">
<form action="CustomerController" method="post">
<div class="banner">
<div class="w3-container w3-center w3-lobster">
<img src="subway-removebg-preview.png" alt="subway"
style="width:80%;max-width:320px">
<h1>CUSTOMER SERVICE</h1>
</div>
</div>
<fieldset>
<legend>
<h3>Customer Details</h3>
</legend>

<div class="row">
<div class="col-25">
<label for="name">Name*</label>
</div>
<div class="col-75">
<input type="text" id="name" name="name"
placeholder="Customer Name" required>
</div>
</div>
<div class="row">
<div class="col-25">
<label for="email">Email*</label>
</div>
<div class="col-75">
<input type="email" id="email" name="email"
placeholder="Customer Email" required>
</div>
</div>
<div class="row">
<div class="col-25">
<label for="phonenumber">Phone
Number*</label>
</div>
<div class="col-75">
<input type="text" id="phonenumber"
name="phonenumber" placeholder="Customer Phone Number" required>
</div>
</div>
<div class="row">
<div class="col-25">
<label for="state">State/Province*</label>
</div>
<div class="col-75">
<select id="state" name="state" required>
<option value="" style="display:
none;">--Please Select State--</option>
<option value="Johor">Johor</option>
<option value="Kedah">Kedah</option>
<option
value="Kelantan">Kelantan</option>
<option value="Melaka">Melaka</option>
<option value="Negeri Sembilan">Negeri
Sembilan</option>
<option value="Pahang">Pahang</option>
<option value="Perak">Perak</option>
<option value="Perlis">Perlis</option>
<option value="Pulau Pinang">Pulau
Pinang</option>
<option value="Sabah">Sabah</option>
<option
value="Sarawak">Sarawak</option>
<option
value="Selangor">Selangor</option>
<option
value="Terengganu">Terengganu</option>
<option value="Wilayah Persekutuan
KL">Wilayah Persekutuan Kuala Lumpur</option>
<option value="Wilayah Persekutuan
labuan">Wilayah Persekutuan Labuan</option>
<option value="Wilayah Persekutuan
Putrajaya">Wilayah Persekutuan Putrajaya</option>
</select>
</div>
</div>
<input type="submit" value="Submit"><input type="reset"
value="Reset">
</fieldset>

</form>
</div>
<a href="CustomerController?action=listCustomer" class="w3-btn w3-yellow w3-
border w3-round-large" style="float: right">List Customer</a>
</body>
</html>
reportform.jsp

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"


pageEncoding="ISO-8859-1"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<!DOCTYPE html>
<html>
<head>
<title>Customer Service | SUBWAY</title>
</head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="css/style.css">
<link rel="stylesheet" href="https://www.w3schools.com/w3css/4/w3.css">
<link rel="stylesheet"
href="https://fonts.googleapis.com/css?family=Lobster&effect=shadow-multiple">
<body>
<div class="main-block">
<form action="AddReportController" method="post">
<div class="banner">
<div class="w3-container w3-center w3-lobster">
<img src="subway-removebg-preview.png" alt="subway"
style="width:80%;max-width:320px">
<h1>CUSTOMER SERVICE</h1>
</div>
</div>
<fieldset>
<legend>
<h3>Problem/Feedback Details</h3>
</legend>
<div>
<div class="row">
<div class="col-25">
<label for="restaurantnum">Restaurant
Number from Receipt*</label>
</div>
<div class="col-75">
<input type="text" id="restaurantnum"
name="restaurantnum" placeholder="Restaurant Number..." required>
</div>
</div>
<div class="row">
<div class="col-25">
<label for="datevisit">Date of
Restaurant Visit*</label>
</div>
<div class="col-75">
<input type="date"
id="datevisit" name="datevisit" placeholder="Restaurant Visit..." required>
</div>
</div>
<div>
<div class="row">
<div class="col-25">
<label for="hour">Hour*</label>
</div>
<div class="col-75">
<select class="day" id="hour"
name="hour" required>
<option value=""
style="display: none;"></option>
<option
value="1">1</option>
<option
value="2">2</option>
<option
value="3">3</option>
<option
value="4">4</option>
<option
value="5">5</option>
<option
value="6">6</option>
<option
value="7">7</option>
<option
value="8">8</option>
<option
value="9">9</option>
<option
value="10">10</option>
<option
value="11">11</option>
<option
value="12">12</option>
</select>
</div>
</div>
<div class="row">
<div class="col-25">
<label for="minute">Approximate
Minute*</label>
</div>
<div class="col-75">
<select class="mounth"
id="minute" name="minute" required>
<option value=""
style="display: none;"></option>
<option
value="00">00</option>
<option
value="15">15</option>
<option
value="30">30</option>
<option
value="45">45</option>
</select>
</div>
</div>
<div class="row">
<div class="col-25">
<label for="minute">Time*</label>
</div>
<div class="col-75">
<input type="radio" name="time"
value="am" checked>AM
<input type="radio" name="time"
value="pm">PM
</div>
</div>
<div class="row">
<div class="col-25">
<label for="price">Final Total
Price: RM *</label>
</div>
<div class="col-75">
<input type="text" id="price"
name="price" placeholder="Total Price..." required>
</div>
</div>
<div class="row">
<div class="col-25">
<label
for="problem">Problem/Feedback*</label>
</div>
<div class="col-75">
<textarea name="problem"
rows="10" cols="47" placeholder="Your Problem/Feedback..."></textarea>
</div>
</div>
<div class="row">
<div class="col-25">
<label for="name">Customer* </label>
</div>
<div class="col-75">
<select id="cid" name="cid" required>
<c:forEach items="${cust}"
var="cus">
<option style="color:
black" value="<c:out value='${cus.cid}'/>"><c:out value='${cus.cid}'/>-<c:out
value='${cus.name}'/></option>
</c:forEach>
</select>
</div>
</div>
</div>
</div>
<br>
<input type="submit" value="Submit"><input type="reset"
value="Reset">
</fieldset>
</form>
</div>
<a href="ReportController?action=listReport" class="w3-btn w3-yellow w3-border
w3-round-large" style="float: right">List Report</a>
</body>
</html>
listCustomer.jsp

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"


pageEncoding="ISO-8859-1"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<!DOCTYPE html>
<html>
<head>
<title>Customer Service | SUBWAY</title>
</head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://www.w3schools.com/w3css/4/w3.css">
<link rel="stylesheet"
href="https://fonts.googleapis.com/css?family=Lobster&effect=shadow-multiple">
<body>
<div class="main-block">
<form>
<div class="banner">

<div class="w3-container w3-center w3-lobster">


<img src="subway-removebg-preview.png" alt="subway"
style="width:80%;max-width:320px">
<h1>CUSTOMER SERVICE</h1>
</div>
</div>
<fieldset>
<legend>
<h3>List Customer</h3>
</legend>
<a href="CustomerController?action=addCustomer" class="w3-
btn w3-green w3-border w3-round-large" style="float: right">ADD CUSTOMER</a>
<a href="AddReportController" class="w3-btn w3-yellow w3-
border w3-round-large" style="float: right">ADD REPORT</a><br><br>
<table class="w3-table-all w3-centered">
<tr class="w3-black">
<th>Customer ID</th>
<th>Customer Name</th>
<th>Email</th>
<th>Phone Number</th>
<th>State</th>
<th colspan="3">Actions</th>
</tr>
<c:forEach items="${cust}" var="cus">
<tr>
<td><c:out value="${cus.cid}" /></td>
<td><c:out value="${cus.name}" /></td>
<td><c:out value="${cus.email}" /></td>
<td><c:out value="${cus.phonenumber}"
/></td>
<td><c:out value="${cus.state}" /></td>
<td><a

href="CustomerController?action=viewCustomer&cid=<c:out value="${cus.cid}"/>"
class="w3-btn w3-green w3-round-
large">View</a></td>
<td><a

href="CustomerController?action=updateCustomer&cid=<c:out
value="${cus.cid}"/>"
class="w3-btn w3-yellow w3-
round-large">Update</a></td>
<td><a

href="CustomerController?action=deleteCustomer&cid=<c:out
value="${cus.cid}"/>"
class="w3-btn w3-red w3-round-
large">Delete</a></td>
</tr>
</c:forEach>
</table>
</fieldset>
</form>
</div>
</body>
</html>
listReport.jsp

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"


pageEncoding="ISO-8859-1"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<%@ page import="system.model.*,report.dao.*,java.sql.*,java.util.*" %>
<!DOCTYPE html>
<html>
<head>
<title>Customer Service | SUBWAY</title>
</head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://www.w3schools.com/w3css/4/w3.css">
<link rel="stylesheet"
href="https://fonts.googleapis.com/css?family=Lobster&effect=shadow-multiple">
<body>
<div class="main-block">
<form>
<div class="banner">
<div class="w3-container w3-center w3-lobster">
<img src="subway-removebg-preview.png" alt="subway"
style="width:80%;max-width:320px">
<h1>CUSTOMER SERVICE</h1>
</div>
</div>
<fieldset>
<legend>
<h3>List Report</h3>
</legend>
<a href="CustomerController?action=addCustomer" class="w3-
btn w3-green w3-border w3-round-large" style="float: right">ADD CUSTOMER</a>
<a href="AddReportController" class="w3-btn w3-yellow w3-
border w3-round-large" style="float: right">ADD REPORT</a><br>

<br>
<table class="w3-table-all w3-centered">
<tr class="w3-black">
<th>Report ID</th>
<th>Restaurant Number</th>
<th>Date Visit</th>
<th>Price</th>
<th>Customer ID</th>
<th colspan="3">Actions</th>
</tr>
<c:forEach items="${reps}" var="rep">
<tr>
<td><c:out value="${rep.rid}" /></td>
<td><c:out value="${rep.restaurantnum}"
/></td>
<td><c:out value="${rep.datevisit}"
/></td>
<td><c:out value="${rep.price}" /></td>
<td><c:out value="${rep.cid}" /></td>
<td><a
href="ReportController?action=viewReport&rid=<c:out value="${rep.rid}"/>" class="w3-
btn w3-green w3-round-large">View</a></td>
<td><a
href="ReportController?action=updateReport&rid=<c:out value="${rep.rid}"/>"
class="w3-btn w3-yellow w3-round-large">Update</a></td>
<td><a
href="ReportController?action=deleteReport&rid=<c:out value="${rep.rid}"/>"
class="w3-btn w3-red w3-round-large">Delete</a></td>
</tr>
</c:forEach>
</table>
</fieldset>
</form>
</div>
</body>
</html>
updateCustomer.jsp

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"


pageEncoding="ISO-8859-1"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<!DOCTYPE html>
<html>
<head>
<title>Customer Service | SUBWAY</title>
</head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="css/style.css">
<link rel="stylesheet" href="https://www.w3schools.com/w3css/4/w3.css">
<link rel="stylesheet"
href="https://fonts.googleapis.com/css?family=Lobster&effect=shadow-multiple">
<body>
<div class="main-block">
<form action="CustomerController" method="post">
<div class="banner">
<div class="w3-container w3-center w3-lobster">
<img src="subway-removebg-preview.png" alt="subway"
style="width:80%;max-width:320px">
<h1>CUSTOMER SERVICE</h1>
</div>
</div>
<fieldset>
<legend>
<h3>Update Customer Details</h3>
</legend>
<div class="row">
<div class="col-25">
<label for="cid">Customer ID</label>
</div>
<div class="col-75">
<input type="text" name="cid"
value="<c:out value="${cus.cid}"/>" readonly/>
</div>
</div>
<div class="row">
<div class="col-25">
<label for="name">Name*</label>
</div>
<div class="col-75">
<input type="text" id="name"
name="name" value="<c:out value="${cus.name}"/>">
</div>
</div>
<div class="row">
<div class="col-25">
<label for="email">Email*</label>
</div>
<div class="col-75">
<input type="email" id="email"
name="email" value="<c:out value="${cus.email}"/>">
</div>
</div>
<div class="row">
<div class="col-25">
<label for="phonenumber">Phone
Number*</label>
</div>
<div class="col-75">
<input type="text" id="phonenumber"
name="phonenumber" value="<c:out value="${cus.phonenumber}"/>">
</div>
</div>
<div class="row">
<div class="col-25">
<label
for="state">State/Province*</label>
</div>
<div class="col-75">
<select id="state" name="state"
value="<c:out value="${cus.state}"/>">
<option
value="Johor">Johor</option>
<option
value="Kedah">Kedah</option>
<option
value="Kelantan">Kelantan</option>
<option
value="Melaka">Melaka</option>
<option value="Negeri
Sembilan">Negeri Sembilan</option>
<option
value="Pahang">Pahang</option>
<option
value="Perak">Perak</option>
<option
value="Perlis">Perlis</option>
<option value="Pulau
Pinang">Pulau Pinang</option>
<option
value="Sabah">Sabah</option>
<option
value="Sarawak">Sarawak</option>
<option
value="Selangor">Selangor</option>
<option
value="Terengganu">Terengganu</option>
<option value="Wilayah
Persekutuan KL">Wilayah Persekutuan Kuala Lumpur</option>
<option value="Wilayah
Persekutuan labuan">Wilayah Persekutuan Labuan</option>
<option value="Wilayah
Persekutuan Putrajaya">Wilayah Persekutuan Putrajaya</option>
</select>
</div>
</div>
<input type="submit" value="Submit">
</fieldset>
</form>
</div>
<a href="CustomerController?action=listCustomer" class="w3-btn w3-green w3-
border w3-round-large" style="float: right">List Customer</a>
</body>
</html>
updateReport.jsp

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"


pageEncoding="ISO-8859-1"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<!DOCTYPE html>
<html>
<head>
<title>Customer Service | SUBWAY</title>
</head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="css/style.css">
<link rel="stylesheet" href="https://www.w3schools.com/w3css/4/w3.css">
<link rel="stylesheet"
href="https://fonts.googleapis.com/css?family=Lobster&effect=shadow-multiple">
<body>
<div class="main-block">
<form action="ReportController" method="post">
<div class="banner">
<div class="w3-container w3-center w3-lobster">
<img src="subway-removebg-preview.png" alt="subway"
style="width:80%;max-width:320px">
<h1>CUSTOMER SERVICE</h1>
</div>
</div>
<fieldset>
<legend>
<h3> Update Problem/Feedback Details</h3>
</legend>
<div>
<div class="row">
<div class="col-25">
<label for="rid">Report ID</label>
</div>
<div class="col-75">
<input type="text" name="rid"
value="<c:out value="${rep.rid}"/>" readonly/>
</div>
</div>
<div class="row">
<div class="col-25">
<label
for="restaurantnum">Restaurant Number from Receipt*</label>
</div>
<div class="col-75">
<input type="text"
id="restaurantnum" name="restaurantnum" value="<c:out
value="${rep.restaurantnum}"/>">
</div>
</div>
<div class="row">
<div class="col-25">
<label for="datevisit">Date of
Restaurant Visit*</label>
</div>
<div class="col-75">
<input type="date"
id="datevisit" name="datevisit" value="<c:out value="${rep.datevisit}"/>">
</div>
</div>
<div class="row">
<div class="col-25">
<label for="hour">Hour*</label>
</div>
<div class="col-75">
<select class="day" name="hour"
value="<c:out value="${rep.hour}"/>">
<option
value="1">1</option>
<option
value="2">2</option>
<option
value="3">3</option>
<option
value="4">4</option>
<option
value="5">5</option>
<option
value="6">6</option>
<option
value="7">7</option>
<option
value="8">8</option>
<option
value="9">9</option>
<option
value="10">10</option>
<option
value="11">11</option>
<option
value="12">12</option>
</select>
</div>
</div>
<div class="row">
<div class="col-25">
<label
for="minute">Minute*</label>
</div>
<div class="col-75">
<select class="mounth"
name="minute" required>
<option value="00"><c:out
value="${rep.minute}"/></option>
<option
value="15">15</option>
<option
value="30">30</option>
<option
value="45">45</option>
</select>
</div>
</div>
<div class="row">
<div class="col-25">
<label
for="time">Time*</label>
</div>
<div class="col-75">
<input type="radio"
name="time" value="<c:out value="${rep.datevisit}"/>" checked>AM
<input type="radio"
name="time" value="pm">PM
</div>
</div>

<div class="row">
<div class="col-25">
<label for="price">Final Total
Price:RM *</label>
</div>
<div class="col-75">
<input type="text" id="price"
name="price" value="<c:out value="${rep.price}"/>">
</div>
</div>
<div class="row">
<div class="col-25">
<label
for="problem">Problem/Feedback*</label>
</div>
<div class="col-75">
<textarea name="problem"
rows="10" cols="47"><c:out value="${rep.problem}"/></textarea>
</div>
</div>
</div>
<input type="submit" value="Submit">
</fieldset>
</form>
</div>
<a href="ReportController?action=listReport" class="w3-btn w3-green w3-border
w3-round-large" style="float: right">List Report</a>
</body>
</html>
viewCustomer.jsp

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"


pageEncoding="ISO-8859-1"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<!DOCTYPE html>
<html>
<head>
<title>Customer Service | SUBWAY</title>
</head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://www.w3schools.com/w3css/4/w3.css">
<link rel="stylesheet"
href="https://fonts.googleapis.com/css?family=Lobster&effect=shadow-multiple">
<body>
<div class="main-block">
<form>
<div class="banner">
<div class="w3-container w3-center w3-lobster">
<img src="subway-removebg-preview.png" alt="subway"
style="width:80%;max-width:320px">
<h1>CUSTOMER SERVICE</h1>
</div>
</div>

<fieldset>
<legend>
<h3>Customer Details</h3>
</legend>
<div class="w3-center">
<div>
<label for="cid">Customer ID</label>:<c:out
value="${cus.cid}"/><br>
</div>
<div>
<label for="name">Customer
Name</label>:<c:out value="${cus.name}"/><br>
</div>
<div>
<label for="email">Customer
Email</label>:<c:out value="${cus.email}"/><br>
</div>
<div>
<label for="phonenumber">Phone
Number</label>:<c:out value="${cus.phonenumber}"/><br>
</div>
<div>
<label for="state">State</label>:<c:out
value="${cus.state}"/><br>
</div>

</div>
</fieldset>
<a href="CustomerController?action=listCustomer"
class="w3-btn w3-green w3-border w3-round-large">Customer List</a>
</form>
</div>
</body>
</html>
viewReport.jsp

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"


pageEncoding="ISO-8859-1"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<!DOCTYPE html>
<html>
<head>
<title>Customer Service | SUBWAY</title>
</head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://www.w3schools.com/w3css/4/w3.css">
<link rel="stylesheet"
href="https://fonts.googleapis.com/css?family=Lobster&effect=shadow-multiple">
<body>
<div class="main-block">
<form action="">
<div class="banner">
<div class="w3-container w3-center w3-lobster">
<img src="subway-removebg-preview.png" alt="subway"
style="width:80%;max-width:320px">
<h1>CUSTOMER SERVICE</h1>
</div>
</div>

<fieldset>
<legend>
<h3>Problem/Feedback Details</h3>
</legend>
<div class="w3-center">
<div>
<div>
<label for="rid">Report
ID</label>:<c:out value="${rep.rid}"/><br>
</div>
<div>
<label for="restaurantnum">Restaurant
Number</label>:<c:out value="${rep.restaurantnum}"/><br>
</div>
<div>
<label for="datevisit">Date
Visit</label>:<c:out value="${rep.datevisit}"/><br>
</div>
<div>
<label for="hour">Hour</label>:<c:out
value="${rep.hour}"/><br>
</div>
<div>
<label
for="minute">Minute</label>:<c:out value="${rep.minute}"/><br>
</div>
<div>
<label for="time">Time</label>:<c:out
value="${rep.time}"/><br>
</div>
<div>
<label for="price">Total
Price</label>:RM<c:out value="${rep.price}"/><br>
</div>
<div>
<label
for="problem">Problem</label>:<c:out value="${rep.problem}"/><br>
</div>
<div>
<label
for="cid">Customer</label>:<c:out value="${rep.cid}"/><br>
</div>
</div>
</div>
</fieldset>
<a href="ReportController?action=listReport" class="w3-btn w3-
green w3-border w3-round-large">List Report</a>
</form>
</div>
</body>
</html>
Question 2

Write the Controller.

CustomerController.java

package customer.controller;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import customer.dao.CustomerDAO;
import system.model.customer;

@WebServlet("/CustomerController")
public class CustomerController extends HttpServlet {
private static final long serialVersionUID = 1L;
private CustomerDAO dao;
private static String LIST = "/listCustomer.jsp";
private static String UPDATE = "/updateCustomer.jsp";
private static String VIEW = "/viewCustomer.jsp";
private static String ADD = "/customerform.jsp";
String forward = "";

public CustomerController() {
super();
dao = new CustomerDAO();
// TODO Auto-generated constructor stub
}

protected void doGet(HttpServletRequest request, HttpServletResponse response)


throws ServletException, IOException {
// TODO Auto-generated method stub
String action = request.getParameter("action");

if(action.equalsIgnoreCase("updateCustomer")) {
forward = UPDATE;
int cid = Integer.parseInt(request.getParameter("cid"));
customer cus = dao.getCustomerById(cid);
request.setAttribute("cus", cus);

}
else if(action.equalsIgnoreCase("viewCustomer")) {
forward = VIEW;
int cid = Integer.parseInt(request.getParameter("cid"));
request.setAttribute("cus", dao.getCustomerById(cid));
}
else if(action.equalsIgnoreCase("deleteCustomer")) {

int cid = Integer.parseInt(request.getParameter("cid"));


dao.deleteCustomer(cid);
request.setAttribute("cust", dao.getAllCustomer());
RequestDispatcher view =
request.getRequestDispatcher("listCustomer.jsp");
view.forward(request, response);

}
else if(action.equalsIgnoreCase("listCustomer")) {
forward = LIST;
request.setAttribute("cust", CustomerDAO.getAllCustomer());

}
else {
forward = ADD;
}
RequestDispatcher view = request.getRequestDispatcher(forward);
view.forward(request, response);

protected void doPost(HttpServletRequest request, HttpServletResponse


response) throws ServletException, IOException {

customer cus = new customer();


cus.setName(request.getParameter("name"));
cus.setEmail(request.getParameter("email"));
cus.setPhonenumber(request.getParameter("phonenumber"));
cus.setState(request.getParameter("state"));

String cid = request.getParameter("cid");

if(cid == null || cid.isEmpty()) {


dao.addCustomer(cus);

}
else {
cus.setCid(Integer.parseInt(cid));
dao.updateCustomer(cus);

}
forward = LIST;

request.setAttribute("cust", CustomerDAO.getAllCustomer());
RequestDispatcher view = request.getRequestDispatcher(forward);
view.forward(request, response);
}
}
ReportController.java

package report.controller;

import java.io.IOException;
import java.text.DateFormat;
import java.text.SimpleDateFormat;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import customer.dao.CustomerDAO;
import report.dao.ReportDAO;
import system.model.report;

@WebServlet("/ReportController")
public class ReportController extends HttpServlet {
private static final long serialVersionUID = 1L;
DateFormat formatter;
private ReportDAO dao;
private CustomerDAO daoc;
private static String LIST = "/listReport.jsp";
private static String UPDATE = "/updateReport.jsp";
private static String VIEW = "/viewReport.jsp";
private static String ADD = "/reportform.jsp";
String forward = "";

public ReportController() {
super();
dao = new ReportDAO();
daoc = new CustomerDAO();
}

protected void doGet(HttpServletRequest request, HttpServletResponse response)


throws ServletException, IOException {
String action = request.getParameter("action");

if(action.equalsIgnoreCase("updateReport")) {

int rid = Integer.parseInt(request.getParameter("rid"));


report rep = dao.getReportById(rid);
request.setAttribute("rep", rep);
RequestDispatcher view =
request.getRequestDispatcher("/updateReport.jsp");
view.forward(request, response);

}
else if(action.equalsIgnoreCase("viewReport")) {

int rid = Integer.parseInt(request.getParameter("rid"));


request.setAttribute("rep", dao.getReportById(rid));
RequestDispatcher view =
request.getRequestDispatcher("/viewReport.jsp");
view.forward(request, response);

}
else if(action.equalsIgnoreCase("deleteReport")) {

int rid = Integer.parseInt(request.getParameter("rid"));


dao.deleteReport(rid);
request.setAttribute("reps", dao.getAllReport());
RequestDispatcher view =
request.getRequestDispatcher("/listReport.jsp");
view.forward(request, response);

}
else if(action.equalsIgnoreCase("listReport")) {

request.setAttribute("reps", ReportDAO.getAllReport());
RequestDispatcher view =
request.getRequestDispatcher("/listReport.jsp");
view.forward(request, response);

request.setAttribute("cust",CustomerDAO.getCustID());
RequestDispatcher view =
request.getRequestDispatcher("/reportform.jsp");
view.forward(request, response);

protected void doPost(HttpServletRequest request, HttpServletResponse


response) throws ServletException, IOException {

try {
formatter = new SimpleDateFormat("yyyy-MM-dd");

//get the date and convert to java date


java.util.Date
date1=formatter.parse(request.getParameter("datevisit"));
report rep = new report();

rep.setRestaurantnum(Integer.parseInt(request.getParameter("restaurantnum")));
rep.setDatevisit(date1);
rep.setHour(request.getParameter("hour"));
rep.setMinute(request.getParameter("minute"));
rep.setTime(request.getParameter("time"));
rep.setPrice(Double.parseDouble(request.getParameter("price")));
rep.setProblem(request.getParameter("problem"));
rep.setCid(Integer.parseInt(request.getParameter("cid")));

String rid = request.getParameter("rid");

if(rid == null || rid.isEmpty()) {


dao.add(rep);
}
else {
rep.setRid(Integer.parseInt(rid));
dao.updateReport(rep);
}
forward = LIST;

request.setAttribute("reps", ReportDAO.getAllReport());
RequestDispatcher view = request.getRequestDispatcher(forward);
view.forward(request, response);

}
catch(Exception e){
System.out.println(e);
}
}
}
AddReportController.java

package report.controller;

import java.io.IOException;
import java.text.DateFormat;
import java.text.SimpleDateFormat;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import customer.dao.CustomerDAO;
import report.dao.ReportDAO;
import system.model.report;

@WebServlet("/AddReportController")
public class AddReportController extends HttpServlet {
private static final long serialVersionUID = 1L;
DateFormat formatter;
private ReportDAO dao;
private CustomerDAO daoc;

public AddReportController() {
super();
dao = new ReportDAO();
daoc = new CustomerDAO();
}

protected void doGet(HttpServletRequest request, HttpServletResponse response)


throws ServletException, IOException {
System.out.println("Shot1");
request.setAttribute("cust",CustomerDAO.getCustID());
RequestDispatcher view =
request.getRequestDispatcher("/reportform.jsp");
view.forward(request, response);
}

protected void doPost(HttpServletRequest request, HttpServletResponse


response) throws ServletException, IOException {

try {
System.out.println("Shot2");
formatter = new SimpleDateFormat("yyyy-MM-dd");

//get the date and convert to java date


java.util.Date
date1=formatter.parse(request.getParameter("datevisit"));

report rep = new report();

rep.setRestaurantnum(Integer.parseInt(request.getParameter("restaurantnum")));
rep.setDatevisit(date1);
rep.setHour(request.getParameter("hour"));
System.out.println("Shot4");
rep.setMinute(request.getParameter("minute"));
rep.setTime(request.getParameter("time"));
System.out.println("Shot5");
rep.setPrice(Double.parseDouble(request.getParameter("price")));
rep.setProblem(request.getParameter("problem"));
System.out.println("Shot6");
rep.setCid(Integer.parseInt(request.getParameter("cid")));
System.out.println("Shot7");

String rid = request.getParameter("rid");

if(rid == null || rid.isEmpty()) {


dao.add(rep);
System.out.println("Shot12");
}
/*else {
rep.setRid(Integer.parseInt(rid));
dao.updateReport(rep);
}*/

request.setAttribute("reps", ReportDAO.getAllReport());
RequestDispatcher view =
request.getRequestDispatcher("/listReport.jsp");
view.forward(request, response);
System.out.println("shot14");

}
catch(Exception e){
System.out.println(e);
}
}

}
Question 3

Write the DAO to add, update, delete, and select the data.

CustomerDAO.java
package customer.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;

import db.connection.ConnectionManager;
import system.model.customer;

public class CustomerDAO {


static Connection con = null;
static PreparedStatement ps = null;
static Statement stmt = null;
int cid;
String name, email, phonenumber, state;

//add customer
public void addCustomer(customer bean) {
name = bean.getName();
email = bean.getEmail();
phonenumber = bean.getPhonenumber();
state = bean.getState();

try {
con = ConnectionManager.getConnection();
ps = con.prepareStatement("insert into customer
(name,email,phonenumber,state) values (?,?,?,?)");
ps.setString(1, name);
ps.setString(2, email);
ps.setString(3, phonenumber);
ps.setString(4, state);
ps.executeUpdate();
}

catch (Exception ex) {


ex.printStackTrace();
}
}

//view customer
public static customer getCustomerById(int cid) {
customer cus = new customer();
try {
con = ConnectionManager.getConnection(); //2. call the method
from ConnectionManager class to establish connection
//String query = "select * from person where id=?";
ps = con.prepareStatement("select * from customer where cid=?");
ps.setInt(1, cid);
ResultSet rs = ps.executeQuery(); //4. process the result

if(rs.next()) {
cus.setCid(rs.getInt("cid"));
cus.setName(rs.getString("name"));
cus.setEmail(rs.getString("email"));
cus.setPhonenumber(rs.getString("phonenumber"));
cus.setState(rs.getString("state"));

}
}
catch (Exception ex) {
ex.printStackTrace();
}
return cus;
}

//list customer
public static List<customer> getAllCustomer() {
List<customer> cust = new ArrayList<customer>();
try {
con = ConnectionManager.getConnection();
stmt = con.createStatement();
ResultSet rs = stmt.executeQuery("select * from customer order by
cid");

while (rs.next()) {
customer cus = new customer();
cus.setCid(rs.getInt("cid"));
cus.setName(rs.getString("name"));
cus.setEmail(rs.getString("email"));
cus.setPhonenumber(rs.getString("phonenumber"));
cus.setState(rs.getString("state"));
cust.add(cus);

}
} catch (SQLException e) {
e.printStackTrace();
}

return cust;
}

//delete customer
public void deleteCustomer(int cid) {
try {
con = ConnectionManager.getConnection(); //2. establish
connection
ps = con.prepareStatement("delete from customer where cid=?");
//3. create statement
ps.setInt(1, cid);
ps.executeUpdate();//3. execute statement

}
catch (Exception ex) {
ex.printStackTrace();
}
}

//update customer
public void updateCustomer(customer bean) {
cid = bean.getCid();
name = bean.getName();
email = bean.getEmail();
phonenumber = bean.getPhonenumber();
state = bean.getState();

try {
con = ConnectionManager.getConnection(); //2. establish
connection
String query = "UPDATE customer SET name= '" + name +
"', email= '" + email +
"', phonenumber= '" + phonenumber +
"', state= '" + state +
"' WHERE cid= '"+ cid +"' ";
stmt = con.createStatement(); //3. create statement
stmt.executeUpdate(query);

}
catch (Exception ex) {
ex.printStackTrace();
}
}

//get customerID, name


public static List<customer> getCustID() {
List<customer> cust = new ArrayList<customer>();

try {
con = ConnectionManager.getConnection(); //2. call the method
from ConnectionManager class to establish connection
stmt = con.createStatement();
ResultSet rs = stmt.executeQuery("select cid, name from
customer");

while(rs.next()) {

customer cus = new customer();

cus.setCid(rs.getInt("cid"));
cus.setName(rs.getString("name"));
cust.add(cus);
}
}
catch (SQLException e) {
e.printStackTrace();
}

return cust;
}
}
}
ReportDAO.java

package report.dao;

import java.sql.Connection;
import java.sql.*;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;

import customer.dao.CustomerDAO;

import java.util.Date;

import db.connection.ConnectionManager;
import system.model.customer;
import system.model.report;

public class ReportDAO {


static Connection con = null;
static PreparedStatement ps = null;
static Statement stmt = null;
int rid, restaurantnum, cid;
String hour, minute, time, problem;
Date datevisit;
double price;

//add Report
public void add(report bean) {
restaurantnum = bean.getRestaurantnum();
datevisit = bean.getDatevisit();
hour = bean.getHour();
minute = bean.getMinute();
time = bean.getTime();
price = bean.getPrice();
problem = bean.getProblem();
cid = bean.getCid();

//convert java date to sql date


java.sql.Date sdate = new java.sql.Date(datevisit.getTime());

try {
con = ConnectionManager.getConnection();
ps = con.prepareStatement("insert into report
(restaurantnum,datevisit,hour,minute,time,price,problem,cid) values
(?,?,?,?,?,?,?,?)");
ps.setInt(1, restaurantnum);
ps.setDate(2, sdate);
ps.setString(3, hour);
ps.setString(4, minute);
ps.setString(5, time);
ps.setDouble(6, price);
ps.setString(7, problem);
ps.setInt(8, cid);
ps.executeUpdate();
}
catch (Exception ex) {
ex.printStackTrace();
}
}

//view report
public static report getReportById(int rid) {
report rep = new report();
try {
con = ConnectionManager.getConnection(); //2. call the method
from ConnectionManager class to establish connection
//String query = "select * from person where id=?";
ps = con.prepareStatement("select * from report where rid=?");
ps.setInt(1, rid);
ResultSet rs = ps.executeQuery(); //4. process the result

if(rs.next()) {
rep.setRid(rs.getInt("rid"));
rep.setRestaurantnum(rs.getInt("restaurantnum"));
rep.setDatevisit(rs.getDate("datevisit"));
rep.setHour(rs.getString("hour"));
rep.setMinute(rs.getString("minute"));
rep.setTime(rs.getString("time"));
rep.setPrice(rs.getDouble("price"));
rep.setProblem(rs.getString("problem"));
rep.setCid(rs.getInt("cid"));
}
}
catch (Exception ex) {
ex.printStackTrace();
}
return rep;
}

//list report
public static List<report> getAllReport() {
List<report> reps = new ArrayList<report>();
try {
con = ConnectionManager.getConnection();
stmt = con.createStatement();
ResultSet rs = stmt.executeQuery("select * from report order by
rid");

while (rs.next()) {
report rep = new report();
rep.setRid(rs.getInt("rid"));
rep.setRestaurantnum(rs.getInt("restaurantnum"));
rep.setDatevisit(rs.getDate("datevisit"));
rep.setHour(rs.getString("hour"));
rep.setMinute(rs.getString("minute"));
rep.setTime(rs.getString("time"));
rep.setPrice(rs.getDouble("price"));
rep.setProblem(rs.getString("problem"));
rep.setCid(rs.getInt("cid"));
reps.add(rep);
}
} catch (SQLException e) {
e.printStackTrace();
}

return reps;
}

//delete report
public void deleteReport(int rid) {
try {
con = ConnectionManager.getConnection(); //2. establish
connection
ps = con.prepareStatement("delete from report where rid=?"); //3.
create statement
ps.setInt(1, rid);
ps.executeUpdate();//3. execute statement

}
catch (Exception ex) {
ex.printStackTrace();
}
}

//update report
public void updateReport(report bean) {
rid = bean.getRid();
restaurantnum = bean.getRestaurantnum();
datevisit = bean.getDatevisit();
hour = bean.getHour();
minute = bean.getMinute();
time = bean.getTime();
price = bean.getPrice();
problem = bean.getProblem();
cid = bean.getCid();

try {
con = ConnectionManager.getConnection(); //2. establish
connection
String query = "UPDATE report SET restaurantnum= '" +
restaurantnum +
"', datevisit= '" + datevisit +
"', hour= '" + hour +
"', minute= '" + minute +
"', time= '" + time +
"', price= '" + price +
"', problem= '" + problem +
"', cid= '" + cid +
"' WHERE rid= '"+ rid +"' ";
stmt = con.createStatement(); //3. create statement
stmt.executeUpdate(query);

}
catch (Exception ex) {
ex.printStackTrace();
}
}
Question 4

Briefly explain and include the screenshots of the database.

The database name for both table customer and table report is customerservice. The pk for table
customer is cid, while the pk for table report is rid. There is a fk in table report which is cid that is
related with the pk of table customer.

This is the data for table customer.


This is the data for table report with the fk of cid from table customer.

You might also like