Sunday, May 14, 2017

Leap Year Checker in Java OOP Using Getters and Setters

Here is a sample program that I wrote using Java to check if the given year is a leap year or not a leap year using object oriented programming approach. The code is very easy to understand and use.

My email address are the following jakerpomperada@gmail.com and jakerpomperada@yahoo.com.

My mobile number here in the Philippines is 09173084360.






Sample Program Output


Program Listing

package demo;

import java.util.Scanner;

class CheckLeapYear {
public int YearGiven=0;


public CheckLeapYear(int Year)
{
YearGiven = Year;
}
public int getYearGiven() {
return YearGiven;
}

public void setYearGiven(int Year) {
YearGiven = Year;
}
public void displayResult()
{
 
   if((YearGiven % 400 == 0) || ((YearGiven % 4 == 0) && (YearGiven % 100 != 0))) {
   System.out.println();
System.out.print("The year " + YearGiven + " is a LEAP YEAR.");
   System.out.println("\n\n");
   System.out.print("===== END OF PROGRAM ======");
   System.out.println();
   }
           else {
        System.out.println();
    System.out.print("The year " + YearGiven + " is NOT LEAP YEAR.");
       System.out.println("\n\n");
       System.out.print("===== END OF PROGRAM ======");
       System.out.println();
           }
}
}
public class LeapYear {

/* Written By: Mr. Jake R. Pomperada, MAED-IT  */
/* Java                                        */
/* May 14, 2017    Sunday                      */
public static void main(String[] args) {
 Scanner input = new Scanner(System.in);
 int Year=0;
 
 System.out.println();
     System.out.println("Leap Year Checker in JAVA OOP");
     System.out.println();
     System.out.print("What is the year ? :  ");
     Year = input.nextInt();
     
     CheckLeapYear Given_Year = new CheckLeapYear(Year);
     
     Given_Year.displayResult();
     input.close();
}

}



No comments:

Post a Comment