Advertisement
kaburen

123

May 13th, 2019
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.03 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 data;
  7.  
  8. /**
  9.  *
  10.  * @author Student
  11.  */
  12. class miesiac {
  13.     private int liczbaDni;
  14.     private String nazwa;
  15.     public miesiac (int liczbaDni, String nazwa){
  16.         this.liczbaDni=liczbaDni;
  17.         this.nazwa=nazwa;
  18.     }
  19.     public int getLiczbaDni() {
  20.         return liczbaDni;
  21.     }
  22.     public String getNazwa() {
  23.         return nazwa;
  24.     }
  25.  
  26. }
  27. class miesiace{
  28.    miesiac miesiac[]={
  29.        new miesiac(31,"styczen"),
  30.        new miesiac(28,"luty"),
  31.        new miesiac(31,"marzec"),
  32.        new miesiac(30,"kwiecien"),
  33.        new miesiac(31,"maj"),
  34.        new miesiac(30,"czerwiec"),
  35.        new miesiac(31,"lipiec"),
  36.        new miesiac(31,"sierpien"),
  37.        new miesiac(30,"wrzesien"),
  38.        new miesiac(31,"pazdziernik"),
  39.        new miesiac(30,"listopad"),
  40.        new miesiac(31,"grudzien"),
  41.    };
  42.    public int getIlośćDni(int n){
  43.        return miesiac[n-1].getLiczbaDni();
  44.    }
  45.    public String getNazweMiesiaca(int n){
  46.        return miesiac[n-1].getNazwa();
  47.    }
  48. }
  49. public class data extends miesiace {
  50.     private int dzien,miesiac,rok;
  51.     /**
  52.      * @param args the command line arguments
  53.      */
  54.     public data(int dzien, int miesiac, int rok){
  55.         if(dzien > getIlośćDni(miesiac) && dzien < 0){
  56.             throw new IllegalArgumentException();
  57.         }else{
  58.             this.dzien = dzien;
  59.         }
  60.         if(miesiac > 12 && miesiac < 0){
  61.             throw new IllegalArgumentException();
  62.         }else{
  63.             this.miesiac = miesiac;
  64.         }
  65.         this.rok = rok;
  66.     }
  67.     private boolean isPrzestepny(int rok)
  68.     {
  69.         return (this.rok % 4 == 0 && this.rok % 100 != 0 || this.rok % 400 == 0);
  70.     }
  71.     public int getDzien(){
  72.         return this.dzien;
  73.     }
  74.     public int getMiesiac(){
  75.         return this.miesiac;
  76.     }
  77.     public String getNazweMiesiaca(){
  78.         return getNazweMiesiaca(this.miesiac);
  79.     }
  80.     public int getRok(){
  81.         return this.rok;
  82.     }
  83.     public void tydzienPlus(){
  84.         if(isPrzestepny(this.rok) && this.miesiac ==2){
  85.             if(this.dzien + 7 < getIlośćDni(miesiac)+1){
  86.                 this.dzien +=7;
  87.             }else{
  88.                this.dzien = this.dzien+7-getIlośćDni(miesiac);
  89.                if(this.miesiac < 12){
  90.                   this.miesiac = this.miesiac+1;
  91.                }else{
  92.                   this.rok+=1;
  93.                   this.miesiac = 1;
  94.                }
  95.             }
  96.         }else{
  97.             if(this.dzien + 7 < getIlośćDni(miesiac)){
  98.                 this.dzien +=7;
  99.             }else{
  100.                this.dzien = this.dzien+7-getIlośćDni(miesiac);
  101.                if(this.miesiac < 12){
  102.                   this.miesiac = this.miesiac+1;
  103.                }else{
  104.                   this.rok+=1;
  105.                   this.miesiac = 1;
  106.                }
  107.             }
  108.         }    
  109.     }
  110.     public void tydzienMinus(){
  111.         if(isPrzestepny(this.rok) && this.miesiac ==2){
  112.             if(this.dzien - 7 > getIlośćDni(miesiac)+1){
  113.                     this.dzien -=7;
  114.             }else{
  115.                this.dzien = this.dzien-7+getIlośćDni(miesiac);
  116.                 if(this.miesiac > 1){
  117.                    this.miesiac = this.miesiac-1;
  118.                 }else{
  119.                    this.rok-=1;
  120.                    this.miesiac = 12;
  121.                 }
  122.             }
  123.         }else{
  124.             if(this.dzien - 7 > getIlośćDni(miesiac)){
  125.                     this.dzien -=7;
  126.             }else{
  127.                this.dzien = this.dzien-7+getIlośćDni(miesiac);
  128.                 if(this.miesiac > 1){
  129.                    this.miesiac = this.miesiac-1;
  130.                 }else{
  131.                    this.rok-=1;
  132.                    this.miesiac = 12;
  133.                 }
  134.             }
  135.         }
  136.     }
  137.     public static void main(String[] args) {
  138.         // TODO code application logic here
  139.     }
  140. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement