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.

Circle Square and Triangle in Java for GUI

Java Code of Shapes for Graphical User Interface: For Circle: import java.awt.*; import java.awt.geom.*; /**  * A circle that can be manipulated and that draws itself on a canvas.  *   * @author  Michael Kšlling and David J. Barnes  * @version 2011.07.31  */ public class Circle {     private int diameter;     private int xPosition;     private int yPosition;     private String color;     private boolean isVisible;          /**      * Create a new circle at default position with default color.      */     public Circle()     {         diameter = 68;         xPosition = 230;         yPosition = 90;         color = "blue";     }     /**      * Make this circle visible. If it was already visible, do nothing.      */     public void makeVisible()     {         isVisible = true;         draw();     }          /**      * Make this circle invisible. If it was already invisible, do nothing.  

Kashmir

Kashmir The Heaven on Earth  Kashmir is considered one of the part of Paradise on earth because of its beautiful landscape and hilly mountains which makes it different from other northern areas in Pakistan !  Here is the Video Link of some beautiful landscape of Kashmir