Advertisement
Alfoli

Poo Aula 2: Classe Pessoa1

Feb 26th, 2019
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.91 KB | None | 0 0
  1. import java.util.Calendar;
  2. import javax.swing.JOptionPane;
  3. public class Pessoa1 {
  4.     public String nome;
  5.     public String rg;
  6.     private int mes, ano;
  7.    
  8.     public Pessoa1(){
  9.         this.nome = " ";
  10.         this.rg = " ";
  11.         this.ano = 0;
  12.         this.mes = 0;
  13.     }
  14.     public Pessoa1(String n, String registro, int m, int a){
  15.         this.nome = n;
  16.         this.rg = registro;
  17.         this.mes = m;
  18.         this.ano = a;
  19.     }
  20.     public String toString(){
  21.         String saida;
  22.         saida = this.nome+" "+this.rg+" "+this.calculaIdade();
  23.         return saida;
  24.     }
  25.     public int calculaIdade(){
  26.         Calendar c = Calendar.getInstance();
  27.         String anostr = String.format("%1$ty", c);
  28.         int anohoje = Integer.parseInt(anostr);
  29.         int meshoje = c.MONTH;
  30.         JOptionPane.showMessageDialog(null, String.format("mes = %d ano = %d", meshoje, anohoje));
  31.         int idade = 0;
  32.         if (this.mes <= meshoje)
  33.             idade = anohoje - this.ano;
  34.         else idade = meshoje - this.ano -1;
  35.         return idade;
  36.     }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement