0
Guys, I’m having a little bit of a problem, but it’s really pissing me off in a simple college exercise.
The intention is only to make a program that receives a quantity x and a value y, and multiply it. However, it is to use java methods, and also jsp..
I did everything right, but my methods are not taking the values typed in the textbox, can someone please help me?
Make a program that receives the quantity and value of three products in the following format: quantity1 value1 quantity2 value2 quantity3 Valor3. The program shall calculate these values in the following format::
TOTAL = Quantity1* Value1 + Quantity2 * value2 + Quantity3 * Value3.
Show sub-total and general total.
Follows codes:
HTML:
<html>
<head>
<title>Exercicio 1 em jsp</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<form name="frm" action="calcularSoma.jsp" method="post">
<table border="0" align="center" bordercolor="blue">
<tr>
<td>
<b>Quantidade 1:</b>
</td>
<td>
<input type="text" name="txtQtd1" size="2" />
</td>
<td>
<b>Valor 1:</b>
</td>
<td>
<input type="text" name="txtVlr1" size="2" />
</td>
</tr>
<tr>
<td>
<b>Quantidade 2:</b>
</td>
<td>
<input type="text" name="txtQtd2" size="2" />
</td>
<td>
<b>Valor 2:</b>
</td>
<td>
<input type="text" name="txtVlr2" size="2" />
</td>
</tr>
<tr>
<td>
<b>Quantidade 3:</b>
</td>
<td>
<input type="text" name="txtQtd3" size="2" />
</td>
<td>
<b>Valor 3:</b>
</td>
<td>
<input type="text" name="txtVlr3" size="2" />
</td>
</tr>
<tr>
<td>
<input type="submit" value="Calcular" name="acao">
</td>
<td>
<input type="reset" value="Limpar">
</td>
</tr>
</table>
</form>
</body>
</html>
JSP:
<%@page contentType="text/html" pageEncoding="UTF-8" errorPage="jspTrataErra.jsp"%>
<jsp:useBean id="objCalcularSub" class="packageJeanZika.somaTudo"/>
<jsp:setProperty name="objCalcularSub" property="*"/>
<!DOCTYPE html>
<html>
<head>
<title>Exercicio</title>
</head>
<body>
<h3>Cálculo</h3>
<%-- Apresentação dos dados via HTML --%>
<pre>
---------- DADOS OBTIDOS DO BROWSER ---------------------
Subtotal1 : <%=objCalcularSub.retornaValorSubTotal1()%>
Subtotal2 : <%=objCalcularSub.retornaValorSubTotal2()%>
Subtotal3 : <%=objCalcularSub.retornaValorSubTotal3()%>
---------------------------------------------------------
Total geral: <%=objCalcularSub.retornaTotalGeral()%>
<%-- Total Geral <%=objSomaNum.RetTotal()%> --%>
---------------------------------------------------------
</pre>
</body>
</html>
Java:
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author Jean Cunha
*/
package packageJeanZika;
public class somaTudo {
private float txtVlr1 ;
private float txtVlr2 ;
private float txtVlr3 ;
private int txtQtd1 ;
private int txtQtd2 ;
private int txtQtd3 ;
public void setVlr1(float txtVlr1) {
this.txtVlr1 = txtVlr1;
}
public void setVlr2(float txtVlr2) {
this.txtVlr2 = txtVlr2;
}
public void setVlr3(float txtVlr3) {
this.txtVlr3 = txtVlr3;
}
public void setQtde1(int txtQtd1) {
this.txtQtd1 = txtQtd1;
}
public void setQtde2(int txtQtd2) {
this.txtQtd2 = txtQtd2;
}
public void setQtde3(int txtQtd3) {
this.txtQtd3 = txtQtd3;
}
public float retornaValorSubTotal1() {
return txtQtd1 * txtVlr1;
}
public float retornaValorSubTotal2() {
return txtQtd2 * txtVlr2;
}
public float retornaValorSubTotal3() {
return txtQtd3 * txtVlr3;
}
public float retornaTotalGeral(){
return retornaValorSubTotal1() + retornaValorSubTotal2() + retornaValorSubTotal3();
}
}
Marcus, good afternoon! Nas mosca!! That’s right, thank you very much!! SOLVED!
– Jean Cunha
Glad you solved :-) Note: The site has a feature to mark the correct answer, a check mark (like this: ) next to the answer.
– marcus