This preview shows page 1. Sign up to view the full content.
Unformatted text preview: gorianCalendar ; class CurrentDate extends Date
= = new GregorianCalendar() ; current_system_date.get( Calendar.DAY_OF_MONTH ) ;
current_system_date.get( Calendar.MONTH ) + 1 ;
current_system_date.get( Calendar.YEAR ) ; date_print_format = 'A' ; }
public CurrentDate( char given_date_print_format )
date_print_format = given_date_print_format ;
} The second constructor of class CurrentDate first calls the first constructor
with the help of the this keyword, and then
sets the date_print_format to the given
When you compile programs which use the value. CurrentDate class (e.g. Titanic.java and Weddingdates.java), you should have the files
CurrentDate.java, Date.java, and DateDistance.java in the same folder (directory) as the
file being compiled. The file DateDistance.java
is always needed because Date.java cannot be
compiled without it. CurrentDate.java - 1. The declaration of class CurrentDate. 12.1 Base classes and derived classes Objects of class CurrentDate
are usually created without supplying any parameters to the constructor of the class. This declaration
results in that the object referenced
by date_of_today contains the
date information that is maintained
by the operating system of the computer where this program is being
// Titanic.java (c) Kari Laitinen class Titanic
public static void main( String not_in_use )
Date date_when_titanic_sank = new Date( "04/15/1912" ) ;
DateDistance date_of_today = time_from_sinking new CurrentDate() ; = date_of_today.get_distance_to( date_when_titanic_sank ) ;
+ "\n Today it is " + date_of_today
".\n On " + date_when_titanic_sank
", the famous ship \"Titanic\" went to"
"\n the bottom of Atlantic Ocean."
"\n That happened "
+ " years, "
time_from_sinking.months + " months, and "
+ " days ago. \n\n" ) ; }
} Because of inheritance, the methods of class Date can be called for
CurrentDate objects. Here, for example, methods get_distance_to()
and toString() are invoked for the CurrentDate object pointed by
date_of_today. Titanic.java - 1. A program that uses both a Date object and a CurrentDate object. D:\javafiles3>java Titanic
Today it is 03/01/2005.
On 04/15/1912, the famous ship "Titanic" went to
the bottom of Atlantic Ocean.
That happened 92 yea...
View Full Document
This document was uploaded on 01/20/2014.
- Winter '14