Thiagofsr

Java Class

Aug 21st, 2016
27
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.33 KB | None | 0 0
  1. /*
  2.  * To change this license header, choose License Headers in Project Properties.
  3.  * To change this template file, choose Tools | Templates
  4.  * and open the template in the editor.
  5.  */
  6. package atividade;
  7.  
  8. /**
  9.  *
  10.  * @author Thiago Filipe
  11.  */
  12. public class Data {
  13.    
  14.     private int dia;
  15.     private int mes;
  16.     private int ano;
  17.    
  18.     public int getDiaFDP(){
  19.         return this.dia;
  20.     }
  21.    
  22.     public void setDiaCarai(int dia){
  23.         this.dia = dia;
  24.     }
  25.    
  26.     public int getMesFDP(){
  27.         return this.mes;
  28.     }
  29.    
  30.     public void setMesCarai(int mes){
  31.         this.mes = mes;
  32.     }
  33.    
  34.     public int getAnoFDP(){
  35.         return this.ano;
  36.     }
  37.    
  38.     public void setAnoCarai(int ano){
  39.         this.ano = ano;
  40.     }
  41.    
  42.     public String toStringFormated(){
  43.         // Segurança adicional
  44.         String dataFormated = "";
  45.         if (this.dia > 0 && this.mes > 0 && this.ano > 0){
  46.             dataFormated = this.dia + "/" + this.mes + "/" + this.ano;
  47.            
  48.         }
  49.         return dataFormated;
  50.     }
  51.     public boolean isValid(){
  52.         if (this.dia > 0 && this.dia <= 31){
  53.             if (this.mes > 0 && this.mes <= 12){
  54.                 return true; // a data eh valida.
  55.             }
  56.         }
  57.         return false; // se chegou aqui, os ifs foram falso.
  58.     }
  59. }
Add Comment
Please, Sign In to add comment