The following table shows a training company\'s workshops, the number of days of
ID: 3853105 • Letter: T
Question
The following table shows a training company's workshops, the number of days of each, and their registration fees. The training company conducts its workshops in the three locations shown in the following table. The table also shows the lodging fees per day at each location. Location Lodging Fees per Day When a customer registers for a workshop, he or she must pay the registration fee plus the lodging fees for the selected location. For example, here are the charge to attend the Supervision Skills workshop in Orlando: Registration: exist1, 500 Lodging: exist300 times 3 days = exist900 Total: exist2, 400 Create an app that lets the user to select a workshop from one list box and a location from another list box. When the user clicks a button, the app should calculate and display the registration cost, the lodging cost, and the total cost.Explanation / Answer
Steps : I have used Netbeans ide to develop this application you can use your own.
-> create index.html
<!DOCTYPE html>
<!--
To change this license header, choose License Headers in Project Properties.
To change this template file, choose Tools | Templates
and open the template in the editor.
-->
<html>
<head>
<title>TODO supply a title</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<div>
<form action="demoServlet" method="post">
<center>
<span>Workshop</span> <select name="workshop">
<option value="Time Management">Time Management</option>
<option value="Supervision Skills">Supervision Skills</option>
<option value="Negotiation">Negotiation</option>
</select>
<br>
<span>Location</span> <select name="location">
<option value="Chicago">Chicago</option>
<option value="Dallas">Dallas </option>
<option value="Orlando">Orlando</option>
</select>
<br>
<input type="submit" name="Get Price"/>
</center>
</form>
</div>
</body>
</html>
Explanation : Here I am used form to submit our data to the server.
Note : Action Name must be equal to url pattern in web.xml file.
Create Servlet - > demoServlet.java
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class demoServlet extends HttpServlet {
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html");
PrintWriter out = response.getWriter();
int a;
String workshop=request.getParameter("workshop");
String location=request.getParameter("location");
if(workshop.equals("Time Management"))
{
if(location.equals("Chicago"))
{
a=225*2+800;
out.println("Total Price is : "+a);
}
else if(location.equals("Dallas"))
{
a=175*2+800;
out.println("Total Price is : "+a);
}
else
{
a=300*2+800;
out.println("Total Price is : "+a);
}
}
if(workshop.equals("Supervision Skills"))
{
if(location.equals("Chicago"))
{
a=225*3+1500;
out.println("Total Price is : "+a);
}
else if(location.equals("Dallas"))
{
a=175*3+1500;
out.println("Total Price is : "+a);
}
else
{
a=300*3+1500;
out.println("Total Price is : "+a);
}
}
if(workshop.equals("Negotiation"))
{
if(location.equals("Chicago"))
{
a=225*5+1300;
out.println("Total Price is : "+a);
}
else if(location.equals("Dallas"))
{
a=175*5+1300;
out.println("Total Price is : "+a);
}
else
{
a=300*5+1300;
out.println("Total Price is : "+a);
}
}
}
}
Explanation : Printwriter is used to send response.
Web.xml : it should be look like this
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.1" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd">
<servlet>
<servlet-name>demoServlet</servlet-name>
<servlet-class>demoServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>demoServlet</servlet-name>
<url-pattern>/demoServlet</url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>
30
</session-timeout>
</session-config>
</web-app>
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.