Bom dia pessoal…
Eu tenho uma pequena dúvida.
Um problema bem simples
Sobre decimal format.
Eu já tentei importar de tudo quanto é jeito
ai segue os códigos html e jsp.
Se alguém souber certinho como é o import
eu agradeço, pois é só oque falta para funcionar perfeitamente.
Obrigado
<%@page contentType="text/html"%>
<%@page pageEncoding="ISO-8859-1"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title></title>
</head>
<h2 align=center>Classificação de Peso</h2>
<form id="form1" name="form1" method="post" action="resultado.jsp">
<table width="331" border="1" align="center">
<tr>
<td width="395"><p><strong>:: Sistema de Classificação :: </strong></p>
<table width="321" border="0" align="center">
<tr>
<td width="76" bgcolor="#CCCCCC"><strong>Nome:</strong></td>
<td width="229"><label>
<input name="nome" type="text" id="nome" size="35" />
</label></td>
</tr>
<tr>
<td bgcolor="#CCCCCC"><strong>Idade:</strong></td>
<td><label>
<input name="idade" type="text" id="idade" size="8" />
</label></td>
</tr>
<tr>
<td bgcolor="#CCCCCC"><strong>Peso:</strong></td>
<td><label>
<input name="peso" type="text" id="peso" size="10" />
</label></td>
</tr>
<tr>
<td colspan="2"><label>
<input name="imc" type="checkbox" id="imc" value="1" />
Calcular IMC </label></td>
</tr>
<tr>
<td bgcolor="#CCCCCC"><strong>Altura:</strong></td>
<td><label>
<input name="altura" type="text" id="altura" size="10" />
<input name="omc" type="checkbox" id="omc" value="1" />
Classificar (OMC) </label></td>
</tr>
<tr>
<td colspan="2"><label>
<input type="submit" name="Submit" value="Calcular" />
</label></td>
</tr>
</table></td>
</tr>
</table>
</form>
</body>
</html>
<%@page contentType="text/html"%>
<%@page pageEncoding="ISO-8859-1"%>
<%import "java.text.DecimalFormat"; %>
<html>
<body>
<%
String nome, imc, omc, pesoLetra="a", condicao="a", imcCalc2 = "a";
double altura, peso, idade, imcCalc=0;
DecimalFormat df = new DecimalFormat("0.00");
nome = request.getParameter("nome");
imc = request.getParameter("imc");
omc = request.getParameter("omc");
peso = Double.parseDouble(request.getParameter("peso"));
idade = Double.parseDouble(request.getParameter("idade"));
if(idade < 19)
{
if(peso < 41)
{
pesoLetra = "A";
}
if(peso >= 41 && peso <= 70)
{
pesoLetra = "B";
}
if(peso > 70)
{
pesoLetra = "C";
}
}
if(idade >= 19 && idade <= 37)
{
if(peso < 41)
{
pesoLetra = "D";
}
if(peso >= 41 && peso <= 70)
{
pesoLetra = "E";
}
if(peso > 70)
{
pesoLetra = "F";
}
}
else
{
pesoLetra = "Não solicitado.";
}
if(idade > 37)
{
if(peso < 41)
{
pesoLetra = "G";
}
if(peso >= 41 && peso <= 70)
{
pesoLetra = "H";
}
if(peso > 70)
{
pesoLetra = "I";
}
}
if(imc != null)
{
altura = Double.parseDouble(request.getParameter("altura"));
imcCalc = peso / (altura * altura);
}
else
{
pesoLetra = "Não solicitado";
}
if(omc != null)
{
if(imcCalc < 18.5)
{
condicao = "Abaixo do peso";
}
if(imcCalc >= 18.5 && imcCalc < 25)
{
condicao = "No peso normal";
}
if(imcCalc >= 25 && imcCalc < 30)
{
condicao = "Acima do peso";
}
if(imcCalc >= 30)
{
condicao = "Obeso";
}
}
else
{
condicao = "Não solicitado";
}
imcCalc2 = df.format(imcCalc);
if(imc == null)
{
imcCalc2 = " ";
}
%>
<table width="321" border="0" align="center">
<tr>
<td width="76" bgcolor="#CCCCCC"><strong>Nome:</strong></td>
<td width="229"><label><%=nome%></label></td>
</tr>
<tr>
<td bgcolor="#CCCCCC"><strong>Classificação:</strong></td>
<td><label><%=pesoLetra%></label></td>
</tr>
<tr>
<td bgcolor="#CCCCCC"><strong>IMC:</strong></td>
<td><label><%= imcCalc2 + "( " + condicao + " )" %></label></td>
</tr>
</table>
</body>
</html>