星期一, 4月 10, 2006

Lab Class Definitions

public class DateFirstTry
{
public String month;
public int day;
public int year;
public void writeOutput()
{
System.out.println(month+" "+day+","+year);

}
public void makeItNewYears()
{
month ="January";
day=1;

}
}

---------------------------------

public class DateFirstTryDemo
{

public static void main(String[] args)
{
DateFirstTry date1,date2;
date1=new DateFirstTry();
date2=new DateFirstTry();

date1.month="December";
date1.day=31;
date1.year=2007;
System.out.println("date1:");
date1.writeOutput();
System.out.println("The New year is :");
date1.makeItNewYears();
date1.writeOutput();


date2.month="July";
date2.day=4;
date2.year=1776;
System.out.println("date2:");
date2.writeOutput();
System.out.println("The New year is :");
date2.makeItNewYears();
date2.writeOutput();
}
}

-----------------------------------


date1:
December 31, 2007
The New year is :
January 1, 2007

date2:
July 4, 1776
The New year is :
January 1, 1776

0 Comments:

張貼留言

<< Home

Creative Commons License
This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 2.5 Taiwan License.