Skip to main content

Program to write Date in Java

DATE PROGRAM





Date Class:

public class Date
{
private int month;
private int year;
private int day;

public int getMonth() {
return month;
}
public void setMonth(int month) {
this.month = month;
}
public int getYear() {
return year;
}
public void setYear(int year) {
this.year = year;
}
public int getDay() {
return day;
}
public void setDay(int day) {
this.day = day;
}

public void displayDate()
{
System.out.print(getMonth()+ "/" +getDay()+ "/" +getYear() ) ;
}

}


Date Test Class:

import java.util.Scanner;

public class DateTest
{

public static void main (String args[])

{
Scanner in=new Scanner(System.in);
System.out.println("Enter the day");
int d=in.nextInt();

System.out.println("Enter the month ");
int m=in.nextInt();

System.out.println("Enter the year ");
int y=in.nextInt();

Date date=new Date();
date.setDay(d);
date.setMonth(m);
date.setYear(y);

date.displayDate();



}


}

Comments

Popular posts from this blog

Technology

Virtual Reality The Next Upcoming Domain in Pakistan is VIRTUAL REALITY and people are making themselves obsessed with it because it takes your imagination to what you are seeing through VR gadget as we know the technology is going to boom in Pakistan through last few years.

Program to Make Canvas in Java For GUI

GRAPHICAL USER INTERFACE : CANVAS CLASS: import javax.swing.*; import java.awt.*; import java.util.List; import java.util.*; /**  * Canvas is a class to allow for simple graphical drawing on a canvas.  * This is a modification of the general purpose Canvas, specially made for  * the BlueJ "shapes" example.   *  * @author: Bruce Quig  * @author: Michael Kšlling (mik)  *  * @version 2011.07.31  */ public class Canvas {     // Note: The implementation of this class (specifically the handling of     // shape identity and colors) is slightly more complex than necessary. This     // is done on purpose to keep the interface and instance fields of the     // shape objects in this project clean and simple for educational purposes.     private static Canvas canvasSingleton;     /**      * Factory method to get t...

Cricket Match

Finally International Cricket again hit the Grounds of Pakistan  Now in Pakistan the Best thing is to about the start of International cricket. Finally the cricket hits the Ground of Pakistan with this phase of  WORLD IX vs PAKISTAN. The schedule is for three days continuous 12 , 13 , 14 September 2017. The all matches will be play in Gaddafi Stadium Lahore , as a FINAL of PSL 02 was also held there.The recent picture is as shown below from Lahore Stadium Cricket is one of the most favourite game of Pakistani's and we love cricket more than our National game because all we like to say that         ↪ "YAR CRICKET LOVE HAI''  We Pakistani's consider to be the most craziest fan's of CRICKET. As we are also moving towards PSL 03 and all the matches are probably be going to Play in Pakistan. The more is coming to pakistan with the passage of time we are moving forward to Meet the International Cricket Standards. Wish All the Be...