Home
»Unlabelled
»
Konten Lain di Sini
SPECIAL TUGAS JAVA
import java.text.*;
public class Date extends Object {
private int date, month, year;
public Date ()
{
setDate (18,5,1998);
}
public void setDate (int d, int m, int y)
{
date =( ( d>=1 && d < 30) ? d : 18 );
month =( ( m>=1 && m < 12) ? m : 5 );
year =( ( y>=1900 && y < 2001) ? y : 1998 );
}
public String toUniversalString()
{
DecimalFormat twoDigits = new DecimalFormat ( "00" );
DecimalFormat fourDigits = new DecimalFormat ( "0000" );
return twoDigits.format ( date ) + ":" + twoDigits.format( month ) + ":" + fourDigits.format( year );
}
public String toStandardString()
{
DecimalFormat twoDigits = new DecimalFormat ( "00" );
DecimalFormat fourDigits = new DecimalFormat ( "0000" );
return twoDigits.format ( date ) + ":" + twoDigits.format ( month ) + ":" +fourDigits.format ( year );
}
}
import javax.swing.*;
public class demoDate{
public static void main(String[] dana){
Date date=new Date();
String output="The initial ONE date is : " + date.toUniversalString() +
"\nThe initial TWO date is : " + date.toStandardString();
date.setDate(13, 27, 2001);
output+="\n\nUniversal ONE after setDate is : " +
date.toUniversalString() + "\nTWO date after setDate is : " +
date.toStandardString();
date.setDate(99, 99, 9999);
output+="\n\nAfter attempting invalid setiings : " + "\nONE date : " +
date.toUniversalString() + "\nTWO date : " + date.toStandardString();
JOptionPane.showMessageDialog(null, output, "Testing Class date1", JOptionPane.INFORMATION_MESSAGE);
System.exit(0);
}
}