//Date1Driver.java //Test driver for the Date1 class import java.awt.*; import javax.swing.*; public class Date1Driver extends JApplet { //public void init() { public static void main(String[] argv) { //create Date1 objects. constructor executes: Date1 d1 = new Date1(1,12,2003); Date1 xmas = new Date1(12,25,2006); //access methods: int xmasDay = xmas.getDay(); if (d1.getYear() < xmas.getYear()) JOptionPane.showMessageDialog(null,"yes"); int num; //num = d1.month; //syntax error. can not access private members. //***************************************** String command; int month, day, year; Date1 theDate=null; //reference to a Date1, but no object yet. //assignment of null is to fake out the compiler... //loop creating object, using it... demo. do { command = JOptionPane.showInputDialog("Enter command: \n" + " construct\n yearIs\n monthIs\n dayIs\n toString\n quit"); if (command.equalsIgnoreCase("construct")) { month = Integer.parseInt(JOptionPane.showInputDialog("Enter month")); day = Integer.parseInt(JOptionPane.showInputDialog("Enter day")); year = Integer.parseInt(JOptionPane.showInputDialog("Enter year")); //constructor called to create/instantiate object. theDate = new Date1(month, day, year); } else if (command.equalsIgnoreCase("yearIs")) JOptionPane.showMessageDialog(null,"Year is " + theDate.getYear()); else if (command.equalsIgnoreCase("monthIs")) JOptionPane.showMessageDialog(null,"Month is " + theDate.getMonth()); else if (command.equalsIgnoreCase("dayIs")) JOptionPane.showMessageDialog(null,"Day is " + theDate.getDay()); else if (command.equalsIgnoreCase("tostring")) JOptionPane.showMessageDialog(null,"toString: " + theDate.toString()); } while(!command.equalsIgnoreCase("quit")) ; } }