Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Calendar;
- import javax.swing.JOptionPane;
- public class Pessoa1 {
- public String nome;
- public String rg;
- private int mes, ano;
- public Pessoa1(){
- this.nome = " ";
- this.rg = " ";
- this.ano = 0;
- this.mes = 0;
- }
- public Pessoa1(String n, String registro, int m, int a){
- this.nome = n;
- this.rg = registro;
- this.mes = m;
- this.ano = a;
- }
- public String toString(){
- String saida;
- saida = this.nome+" "+this.rg+" "+this.calculaIdade();
- return saida;
- }
- public int calculaIdade(){
- Calendar c = Calendar.getInstance();
- String anostr = String.format("%1$ty", c);
- int anohoje = Integer.parseInt(anostr);
- int meshoje = c.MONTH;
- JOptionPane.showMessageDialog(null, String.format("mes = %d ano = %d", meshoje, anohoje));
- int idade = 0;
- if (this.mes <= meshoje)
- idade = anohoje - this.ano;
- else idade = meshoje - this.ano -1;
- return idade;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement