Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package data;
- /**
- *
- * @author Student
- */
- class miesiac {
- private int liczbaDni;
- private String nazwa;
- public miesiac (int liczbaDni, String nazwa){
- this.liczbaDni=liczbaDni;
- this.nazwa=nazwa;
- }
- public int getLiczbaDni() {
- return liczbaDni;
- }
- public String getNazwa() {
- return nazwa;
- }
- }
- class miesiace{
- miesiac miesiac[]={
- new miesiac(31,"styczen"),
- new miesiac(28,"luty"),
- new miesiac(31,"marzec"),
- new miesiac(30,"kwiecien"),
- new miesiac(31,"maj"),
- new miesiac(30,"czerwiec"),
- new miesiac(31,"lipiec"),
- new miesiac(31,"sierpien"),
- new miesiac(30,"wrzesien"),
- new miesiac(31,"pazdziernik"),
- new miesiac(30,"listopad"),
- new miesiac(31,"grudzien"),
- };
- public int getIlośćDni(int n){
- return miesiac[n-1].getLiczbaDni();
- }
- public String getNazweMiesiaca(int n){
- return miesiac[n-1].getNazwa();
- }
- }
- public class data extends miesiace {
- private int dzien,miesiac,rok;
- /**
- * @param args the command line arguments
- */
- public data(int dzien, int miesiac, int rok){
- if(dzien > getIlośćDni(miesiac) && dzien < 0){
- throw new IllegalArgumentException();
- }else{
- this.dzien = dzien;
- }
- if(miesiac > 12 && miesiac < 0){
- throw new IllegalArgumentException();
- }else{
- this.miesiac = miesiac;
- }
- this.rok = rok;
- }
- private boolean isPrzestepny(int rok)
- {
- return (this.rok % 4 == 0 && this.rok % 100 != 0 || this.rok % 400 == 0);
- }
- public int getDzien(){
- return this.dzien;
- }
- public int getMiesiac(){
- return this.miesiac;
- }
- public String getNazweMiesiaca(){
- return getNazweMiesiaca(this.miesiac);
- }
- public int getRok(){
- return this.rok;
- }
- public void tydzienPlus(){
- if(isPrzestepny(this.rok) && this.miesiac ==2){
- if(this.dzien + 7 < getIlośćDni(miesiac)+1){
- this.dzien +=7;
- }else{
- this.dzien = this.dzien+7-getIlośćDni(miesiac);
- if(this.miesiac < 12){
- this.miesiac = this.miesiac+1;
- }else{
- this.rok+=1;
- this.miesiac = 1;
- }
- }
- }else{
- if(this.dzien + 7 < getIlośćDni(miesiac)){
- this.dzien +=7;
- }else{
- this.dzien = this.dzien+7-getIlośćDni(miesiac);
- if(this.miesiac < 12){
- this.miesiac = this.miesiac+1;
- }else{
- this.rok+=1;
- this.miesiac = 1;
- }
- }
- }
- }
- public void tydzienMinus(){
- if(isPrzestepny(this.rok) && this.miesiac ==2){
- if(this.dzien - 7 > getIlośćDni(miesiac)+1){
- this.dzien -=7;
- }else{
- this.dzien = this.dzien-7+getIlośćDni(miesiac);
- if(this.miesiac > 1){
- this.miesiac = this.miesiac-1;
- }else{
- this.rok-=1;
- this.miesiac = 12;
- }
- }
- }else{
- if(this.dzien - 7 > getIlośćDni(miesiac)){
- this.dzien -=7;
- }else{
- this.dzien = this.dzien-7+getIlośćDni(miesiac);
- if(this.miesiac > 1){
- this.miesiac = this.miesiac-1;
- }else{
- this.rok-=1;
- this.miesiac = 12;
- }
- }
- }
- }
- public static void main(String[] args) {
- // TODO code application logic here
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement