@Vitor_Machado escreveu:
obrigado galera, com forme as informações de vcs desenvolvi o seguinte código, vcs poderiam avaliar se tem algo de errado? ou se fica assim msm, desde ja mt obg, segue o código:
public class Paciente {
String nome; double peso; double altura; DecimalFormat decimal = new DecimalFormat( "0.00" ); Paciente() { nome = ""; peso = 0; altura = 0; } boolean validarNome(String nome) { Pattern selecao = Pattern.compile("[0-9]"); Matcher resultado = selecao.matcher(nome); if (resultado.find()) { return false; } else if (nome.length() < 2 || nome.length() > 50) { return false; } else { return true; } } boolean validarPeso(String peso) { try { this.peso = Double.parseDouble(peso); if (this.peso > 00 && this.peso < 350) { return true; } else { return false; } } catch (NumberFormatException nfs) { return false; } } boolean validarAltura(String altura) { try { this.altura = Double.parseDouble(altura); if (this.altura > 0 && this.altura < 2.5) { return true; } else { return false; } } catch (NumberFormatException nfs) { return false; } } double caucalarIMC() { double imc; imc = peso / (Math.pow(altura, 2)); return imc; } String classificarIMC() { double imc = caucalarIMC(); if (imc < 18.4) { return "A baixo do peso"; } else if (imc >= 18.5 && imc <= 24.9) { return "Peso normal"; } else if (imc >= 25 && imc <= 29.9) { return "Sobre peso"; } else if (imc >= 30 && imc <= 34.9) { return "Obesidade grau I"; } else if (imc >= 35 && imc <= 39.9) { return "Obesodade grau II"; } else { return "Obesidade grau III"; } } String recuperarResultado() { return "Resultado.\n" + "Nome: " + nome + "\nPeso: " + peso + "\nAltura: " + altura + "\nIMC: " + decimal.format(caucalarIMC()) + "\nCategoria: " + classificarIMC(); }
}
e
public class TesteIMC {
public static void main(String[] args) { Paciente paciente = new Paciente(); String nome, peso, altura; double imc; while (true) { while (true) { nome = JOptionPane.showInputDialog(null, "Nome do paciente"); if (nome == null) { break; } if (paciente.validarNome(nome)) { paciente.nome = nome.trim(); break; } else { JOptionPane.showMessageDialog(null, "Nome inválido", "Erro", 0); } } if (nome == null) { break; } while (true) { peso = JOptionPane.showInputDialog(null, "Informe seu peso"); if (peso == null) { break; } if (paciente.validarPeso(peso)) { paciente.peso = Double.parseDouble(peso); break; } else { JOptionPane.showMessageDialog(null, "Peso inválido!", "ERRO", 0); } }if(peso==null)break;; while (true) { altura = JOptionPane.showInputDialog(null, "Infome a altura"); if (altura == null) { break; } if (paciente.validarAltura(altura)) { paciente.altura = Double.parseDouble(altura); break; } else { JOptionPane.showMessageDialog(null, "Altura inválida", "ERRO", 0); } }if(altura == null)break; JOptionPane.showMessageDialog(null, paciente.recuperarResultado()); } }
}