Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * classe Dados
- * @author Professor Hercio Neto
- */
- import java.awt.GridLayout;
- import javax.swing.JDialog;
- import javax.swing.JFrame;
- import javax.swing.JLabel;
- import javax.swing.JPanel;
- public class Dados {
- private String nome;
- private Integer idade;
- private String sexo;
- private Double peso;
- private Double altura;
- private Double imc;
- public String getNome() {
- return nome;
- }
- public void setNome(String nome) {
- this.nome = nome;
- }
- public Integer getIdade() {
- return idade;
- }
- public void setIdade(Integer idade) {
- this.idade = idade;
- }
- public String getSexo() {
- return sexo;
- }
- public void setSexo(String sexo) {
- this.sexo = sexo;
- }
- public void mostrarDados() {
- JFrame d = new JFrame();
- JPanel p = new JPanel();
- JLabel lNome = new JLabel("Nome: " + this.getNome());
- lNome.setHorizontalAlignment(JLabel.CENTER);
- lNome.setHorizontalTextPosition(JLabel.CENTER);
- JLabel lIdade = new JLabel("Idade: " + this.getIdade().toString());
- lIdade.setHorizontalAlignment(JLabel.CENTER);
- lIdade.setHorizontalTextPosition(JLabel.CENTER);
- JLabel lSexo = new JLabel("Sexo: " + this.getSexo());
- lSexo.setHorizontalAlignment(JLabel.CENTER);
- lSexo.setHorizontalTextPosition(JLabel.CENTER);
- GridLayout layout = new GridLayout(0, 1, 30, 30);
- p.setLayout(layout);
- p.add(lNome);
- p.add(lIdade);
- p.add(lSexo);
- d.setContentPane(p);
- d.setSize(200, 150);
- d.setResizable(false);
- d.setLocationRelativeTo(d);
- d.pack();
- d.setVisible(true);
- }
- public Double getPeso() {
- return peso;
- }
- public void setPeso(Double peso) {
- this.peso = peso;
- }
- public Double getAltura() {
- return altura;
- }
- public void setAltura(Double altura) {
- this.altura = altura;
- }
- public Double calculaImc(){
- this.imc = this.getPeso() / (this.getAltura() * this.getAltura());
- return imc;
- }
- public String classificaIMC() {
- String classificacao = "";
- Double imc = this.calculaImc();
- /* Menor que 18.5 - Abaixo do peso ;
- Entre 18.5 e 24.9 - Peso normal ;
- Entre 25.0 e 29.9 - Pré-obesidade ;
- Entre 30.0 e 34.9 - Obesidade Grau 1 ;
- Entre 35.0 e 39.9 - Obesidade Grau 2 ;
- Acima de 40 - Obesidade Grau 3 */
- if (imc < 18.5) { classificacao = "Abaixo do peso"; }
- if (imc >= 18.5 && imc < 24.9 ) { classificacao = "Peso normal"; }
- if (imc >= 25 && imc < 29.9 ) { classificacao = "Pré-obesidade"; }
- if (imc >= 30 && imc < 34.9 ) { classificacao = "Obesidade Grau 1"; }
- if (imc >= 35 && imc < 39.9 ) { classificacao = "Obesidade Grau 2"; }
- if (imc >= 40) { classificacao = "Obesidade Grau 3"; }
- return classificacao;
- }
- public void mostrarDadosImc() {
- JFrame d = new JFrame();
- JPanel p = new JPanel();
- JLabel lNome = new JLabel("Nome: " + this.getNome());
- lNome.setHorizontalAlignment(JLabel.CENTER);
- lNome.setHorizontalTextPosition(JLabel.CENTER);
- JLabel lIdade = new JLabel("Idade: " + this.getIdade().toString());
- lIdade.setHorizontalAlignment(JLabel.CENTER);
- lIdade.setHorizontalTextPosition(JLabel.CENTER);
- JLabel lSexo = new JLabel("Sexo: " + this.getSexo());
- lSexo.setHorizontalAlignment(JLabel.CENTER);
- lSexo.setHorizontalTextPosition(JLabel.CENTER);
- JLabel lPeso = new JLabel("Peso: " + this.getPeso());
- lPeso.setHorizontalAlignment(JLabel.CENTER);
- lPeso.setHorizontalTextPosition(JLabel.CENTER);
- JLabel lAltura = new JLabel("Altura: " + this.getAltura());
- lAltura.setHorizontalAlignment(JLabel.CENTER);
- lAltura.setHorizontalTextPosition(JLabel.CENTER);
- Double imc = this.calculaImc();
- JLabel lImc = new JLabel("IMC: " + imc);
- lImc.setHorizontalAlignment(JLabel.CENTER);
- lImc.setHorizontalTextPosition(JLabel.CENTER);
- JLabel lClassifica = new JLabel("Classificação: " + this.classificaIMC());
- lClassifica.setHorizontalAlignment(JLabel.CENTER);
- lClassifica.setHorizontalTextPosition(JLabel.CENTER);
- GridLayout layout = new GridLayout(0, 1, 30, 30);
- p.setLayout(layout);
- p.add(lNome);
- p.add(lIdade);
- p.add(lSexo);
- p.add(lPeso);
- p.add(lAltura);
- p.add(lImc);
- p.add(lClassifica);
- d.setContentPane(p);
- d.setResizable(false);
- d.setLocationRelativeTo(d);
- d.pack();
- d.setAlwaysOnTop(true);
- d.setVisible(true);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement