Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

JAVA Program: please include tabs Your application must include at least three t

ID: 663555 • Letter: J

Question

JAVA Program: please include tabs

Your application must include at least three tabs. The user will choose wood flooring or carpet, enter the length and width of the floor, as well as the customer name and address. The application will compute the area of the floor and the cost of the flooring considering that wood floor is $20 per square foot and carpet is $10 per square foot. A summary should be displayed, either in a tab or another window, listing the customer name and address, floor selection, area, and cost. This information should also be stored in the MySQL database table. The program should validate that all information is entered and that the length and width are numeric values. Any numeric or currency values must be formatted appropriately when output. Recommendations for the components used for input are

radio buttons—flooring type (wood or carpet);

text fields—customer name, customer address, floor length, and floor width; and

buttons—calculate area, calculate cost, submit order, display order summary, display order list.The MySQL database table is called flooring and has the following description.

In addition to entering new customer orders, your application should list all customer orders stored in the database. These will be viewed as a list, in a text area, and will not be updated by the user.

Field Type CustomerName varchar(30) CustomerAddress varchar(50) FlooringType varchar(10) FloorArea double FloorCost double

Explanation / Answer

<html>
<head>Calculating Floor Cost</head>
<body>
<form action="Calculate" method="post">
select:
<input type="radio" name="myradio" value="wood"/>Wood Flooring
<input type="radio" name="myradio" value="Carpet"/>Carpet
<input type="text" name="length" value="" />Length
<input type="text" name="breadth" value="" />Breadth
<input type="text" name="name" value="" />Name
<input type="text" name="Address" value="" />Address
<input type="submit" value="Submit" />
&nbsp<input type="reset" value="Reset" />
<input type="button" value="area" />Area
&nbsp<input type="button" value="Cost" />Cost
</form>
</body></html>

--------------------------------------------------------------------------------------------------------
import java.sql.*;

public class Calculate {
String type = request.getParameter("myradio");   
String length = request.getParameter("length");
String breadth = request.getParameter("breadth");
String name = request.getParameter("name");
String address = request.getParameter("Address");

double arealength = Double.parseDouble(length);
double areabreadth = Double.parseDouble(breadth);
double calculatedArea = arealength*areabreadth;
double totalCost=0;
if(type.equals("wood")){
totalCost = calculatedArea*20;
}
else{
totalCost = calculatedArea*10;
}

Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/myDatabase",
"root", "root");
Statement st = con.createStatement();
int i = st.executeUpdate("insert into flooring(CustomerName, CustomerAddress, FlooringType, FloorArea, FloorCost) values ('" + name + "','"
+ address + "','" + type + "','" + calculatedArea + "','" + totalCost);
if (i > 0) {
response.sendRedirect("total.jsp");
  
} else {
response.sendRedirect("main.jsp");
}
}


--------------------------------------------------****total.jsp*******************8----------------------------------

<%@page import="java.sql.DriverManager"%>
<%@page import="java.sql.ResultSet"%>
<%@page import="java.sql.Statement"%>
<%@page import="java.sql.Connection"%>

<%
String driverName = "com.mysql.jdbc.Driver";
String connectionUrl = "jdbc:mysql://localhost:3306/";
String dbName = "myDatabase";
String userId = "root";
String password = "root";

try {
Class.forName(driverName);
} catch (ClassNotFoundException e) {
e.printStackTrace();
}

Connection connection = null;
Statement statement = null;
ResultSet resultSet = null;
%>
<h2 align="center"><font><strong>Total Orders</strong></font></h2>
<table align="center" cellpadding="5" cellspacing="5" border="1">
<tr>

</tr>
<tr bgcolor="cyan">
<td><b>name</b></td>
<td><b>Address</b></td>
<td><b>FlooringType</b></td>
<td><b>Area</b></td>
<td><b>Cost</b></td>
</tr>
<%
try{
connection = DriverManager.getConnection(connectionUrl+dbName, userId, password);
statement=connection.createStatement();
String sql ="SELECT * FROM flooring";

resultSet = statement.executeQuery(sql);
while(resultSet.next()){
%>
<tr bgcolor="cyan">

<td><%=resultSet.getString("CustomerName") %></td>
<td><%=resultSet.getString("CustomerAddress") %></td>
<td><%=resultSet.getString("FlooringType") %></td>
<td><%=resultSet.getString("FloorArea") %></td>
<td><%=resultSet.getString("FloorCost") %></td>

</tr>

<%
}

} catch (Exception e) {
e.printStackTrace();
}
%>
</table>