A simple applet for displaying dates, mainly to learn the usage of static variables
Source: Internet
Author: User
// Design a simple date class, and write a main program to demonstrate its usage. The date has different display formats,
// For example, if yyyy, mm, and DD are set to represent year, month, and day, the common format is yyyy. Mm. DD.
// Mm/DD/YYYY. The common format in Europe is dd-mm-yyyy. Generally, multiple date objects in the same program are unified.
// Display format. Therefore, the format attribute should define a static data member.
/*
* Auther starshus
*
* Date 04/11/20
*/
// 5.8.2
Public class date
{
Private int year = 2000, month = 1, Day = 1; // define and initialize the variable
Private string greet = "the date is:"; // string that describes the date
Private Static string format = "."; // display format, static variable
Public void setdate (INT year, int month, int day) // set the date
{
This. Year = year;
This. month = month;
This. Day = Day;
}
Public void setgreet (string greet) // you can specify a date string.
{
This. Greet = greet;
}
Public static void setformat (string note) // set the format, which should also be a static method
{
Format = note;
}
Public String getdate () // return date
{
Return (GREET + year + format + month + format + Day );
}
Public static void main (string [] ARGs) // demonstrate the main method of class usage
{
Date = new date (); // create an object
Date. setdate (maid, 28 );
System. Out. println (date. getdate ());
Date. format = "/"; // set the format
Date usadate = new date ();
Usadate. setdate (maid, 13 );
Usadate. setgreet ("this is U. S. A format :");
System. Out. println (usadate. getdate ());
Date. format = "-"; // set the format
Date europedate = new date ();
Europedate. setdate (maid, 13 );
Europedate. setgreet ("this is europedate :");
System. Out. println (europedate. getdate ());
}
}
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.