Advertisement
hercioneto

Classe Dados

Nov 29th, 2023
799
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5.07 KB | None | 0 0
  1. /**
  2.  * classe Dados
  3.  * @author Professor Hercio Neto
  4.  */
  5.  
  6.  
  7. import java.awt.GridLayout;
  8. import javax.swing.JDialog;
  9. import javax.swing.JFrame;
  10. import javax.swing.JLabel;
  11. import javax.swing.JPanel;
  12.  
  13. public class Dados {
  14.     private String nome;
  15.     private Integer idade;
  16.     private String sexo;
  17.     private Double peso;
  18.     private Double altura;
  19.     private Double imc;
  20.  
  21.     public String getNome() {
  22.         return nome;
  23.     }
  24.  
  25.     public void setNome(String nome) {
  26.         this.nome = nome;
  27.     }
  28.  
  29.     public Integer getIdade() {
  30.         return idade;
  31.     }
  32.  
  33.     public void setIdade(Integer idade) {
  34.         this.idade = idade;
  35.     }
  36.  
  37.     public String getSexo() {
  38.         return sexo;
  39.     }
  40.  
  41.     public void setSexo(String sexo) {
  42.         this.sexo = sexo;
  43.     }
  44.    
  45.     public void mostrarDados() {
  46.         JFrame d = new JFrame();
  47.         JPanel p = new JPanel();
  48.         JLabel lNome = new JLabel("Nome: " + this.getNome());
  49.         lNome.setHorizontalAlignment(JLabel.CENTER);
  50.         lNome.setHorizontalTextPosition(JLabel.CENTER);
  51.        
  52.         JLabel lIdade = new JLabel("Idade: " + this.getIdade().toString());
  53.         lIdade.setHorizontalAlignment(JLabel.CENTER);
  54.         lIdade.setHorizontalTextPosition(JLabel.CENTER);
  55.        
  56.         JLabel lSexo = new JLabel("Sexo: " + this.getSexo());
  57.         lSexo.setHorizontalAlignment(JLabel.CENTER);
  58.         lSexo.setHorizontalTextPosition(JLabel.CENTER);
  59.        
  60.         GridLayout layout = new GridLayout(0, 1, 30, 30);
  61.         p.setLayout(layout);
  62.        
  63.        
  64.         p.add(lNome);
  65.         p.add(lIdade);
  66.         p.add(lSexo);
  67.                
  68.         d.setContentPane(p);
  69.         d.setSize(200, 150);
  70.         d.setResizable(false);
  71.         d.setLocationRelativeTo(d);
  72.         d.pack();
  73.         d.setVisible(true);
  74.     }
  75.  
  76.     public Double getPeso() {
  77.         return peso;
  78.     }
  79.  
  80.     public void setPeso(Double peso) {
  81.         this.peso = peso;
  82.     }
  83.  
  84.     public Double getAltura() {
  85.         return altura;
  86.     }
  87.  
  88.     public void setAltura(Double altura) {
  89.         this.altura = altura;
  90.     }
  91.    
  92.     public Double calculaImc(){
  93.         this.imc = this.getPeso() / (this.getAltura() * this.getAltura());
  94.         return imc;
  95.     }
  96.    
  97.     public String classificaIMC() {
  98.         String classificacao = "";
  99.         Double imc = this.calculaImc();
  100.         /* Menor que 18.5 - Abaixo do peso ;
  101. Entre 18.5 e 24.9 - Peso normal ;
  102. Entre 25.0 e 29.9 - Pré-obesidade ;
  103. Entre 30.0 e 34.9 - Obesidade Grau 1 ;
  104. Entre 35.0 e 39.9 - Obesidade Grau 2 ;
  105. Acima de 40 - Obesidade Grau 3 */
  106.         if (imc < 18.5) {  classificacao = "Abaixo do peso"; }
  107.        
  108.         if (imc >= 18.5 && imc < 24.9 ) {  classificacao = "Peso normal"; }
  109.        
  110.         if (imc >= 25 && imc < 29.9 ) {  classificacao = "Pré-obesidade"; }
  111.        
  112.         if (imc >= 30 && imc < 34.9 ) {  classificacao = "Obesidade Grau 1"; }
  113.        
  114.         if (imc >= 35 && imc < 39.9 ) {  classificacao = "Obesidade Grau 2"; }
  115.        
  116.         if (imc >= 40) {  classificacao = "Obesidade Grau 3"; }
  117.        
  118.        
  119.         return classificacao;
  120.     }
  121.    
  122.    
  123.     public void mostrarDadosImc() {
  124.         JFrame d = new JFrame();
  125.         JPanel p = new JPanel();
  126.         JLabel lNome = new JLabel("Nome: " + this.getNome());
  127.         lNome.setHorizontalAlignment(JLabel.CENTER);
  128.         lNome.setHorizontalTextPosition(JLabel.CENTER);
  129.        
  130.         JLabel lIdade = new JLabel("Idade: " + this.getIdade().toString());
  131.         lIdade.setHorizontalAlignment(JLabel.CENTER);
  132.         lIdade.setHorizontalTextPosition(JLabel.CENTER);
  133.        
  134.         JLabel lSexo = new JLabel("Sexo: " + this.getSexo());
  135.         lSexo.setHorizontalAlignment(JLabel.CENTER);
  136.         lSexo.setHorizontalTextPosition(JLabel.CENTER);
  137.        
  138.         JLabel lPeso = new JLabel("Peso: " + this.getPeso());
  139.         lPeso.setHorizontalAlignment(JLabel.CENTER);
  140.         lPeso.setHorizontalTextPosition(JLabel.CENTER);
  141.        
  142.         JLabel lAltura = new JLabel("Altura: " + this.getAltura());
  143.         lAltura.setHorizontalAlignment(JLabel.CENTER);
  144.         lAltura.setHorizontalTextPosition(JLabel.CENTER);
  145.        
  146.         Double imc = this.calculaImc();
  147.         JLabel lImc = new JLabel("IMC: " + imc);
  148.         lImc.setHorizontalAlignment(JLabel.CENTER);
  149.         lImc.setHorizontalTextPosition(JLabel.CENTER);
  150.        
  151.         JLabel lClassifica = new JLabel("Classificação: " + this.classificaIMC());
  152.         lClassifica.setHorizontalAlignment(JLabel.CENTER);
  153.         lClassifica.setHorizontalTextPosition(JLabel.CENTER);
  154.        
  155.         GridLayout layout = new GridLayout(0, 1, 30, 30);
  156.         p.setLayout(layout);
  157.        
  158.        
  159.         p.add(lNome);
  160.         p.add(lIdade);
  161.         p.add(lSexo);
  162.         p.add(lPeso);
  163.         p.add(lAltura);
  164.         p.add(lImc);
  165.         p.add(lClassifica);
  166.        
  167.                
  168.         d.setContentPane(p);
  169.         d.setResizable(false);
  170.         d.setLocationRelativeTo(d);
  171.         d.pack();
  172.         d.setAlwaysOnTop(true);
  173.         d.setVisible(true);
  174.     }
  175. }
  176.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement