Monday, January 02, 2006

Lab 1-02-2006 modular sorting

package azqza;
import java.io.*;
public class Sorting
{
public static void main(String args[])throws IOException
{
double[] number= new double[5];
int x,y;
double z;

for(x=0;x<5;x++)
{
BufferedReader keyin= new BufferedReader(new InputStreamReader(System.in));
number[x]=Integer.parseInt(keyin.readLine());
}

for(x=0;x<5;x++)
{
for(y=0;y<5;y++)
{
if (number[x]>number[y])
{
z=number[x];
number[x]=number[y];
number[y]=z;
}
}
}

for(x=0;x<5;x++)
{
System.out.print(""+number[x]+" ");

}
System.out.println("");
System.out.println("由大到小");
System.exit(0);
}
}

Lab 12-26-2005 (2)

public class aaa
{
public static void main(String[] args)
{
int i;
if(args.length==0)
System.out.println("No input!");
else
{
System.out.println("The output is:");
for(i=args.length-1;i>=0;i--)
{
System.out.println(args[i]+" ");
}
}
}
}

Thursday, December 29, 2005

Lab 12-26-2005 (1)

public class myProgram
{
public static void main(String[] arg)
{
System.out.println(arg[0]+" "+arg[2]+" "+arg[1]);
System.out.println("The length of parameter is "+arg.length);
}
}

Monday, December 26, 2005

Homework 12-19-2005 Lab Equal Arrays

public class Equality {
public Equality() {
}

public static void main(String[] args) {
int[] a={1,9,6,4,0,2,1,2};
int[] b={1,9,6,4,0,2,1,2};
if (a == b)
System.out.println("a and b are equal by ==.");
else
System.out.println("a and b are not equal by ==.");

System.out.println("== only tests memory addresses.");

if (equalArrays(a, b))
System.out.println(
"a and b are equal by the equalArrays method.");
else
System.out.println(
"a and b are not equal by the equalArrays method.");

System.out.println(
"An equalArrays method is usually a more useful test.");

}

public static boolean equalArrays(int[] a, int[] b)
{
if (a.length != b.length)
return false;
else
{
int i = 0;
while (i < a.length)
{
if (a[i] != b[i])
return false;
i++;
}
}

return true;
}


}

Lab 12-19-2005 Sorting

import java.io.*;

public class Sorting {
public Sorting() {
}

public static void main(String[] args) throws IOException {
double[] score = new double[5];
int index, a, b;
double x;
BufferedReader keyboard = new BufferedReader(new InputStreamReader(
System.in));
System.out.println("Enter 5 numbers :");
for (index = 0; index < a =" 0;" b="a+1;b<5;b++){"> score[b]) {
x = score[a];
score[a] = score[b];
score[b] = x;
}
}
}
for (index = 0; index < 5; index++) {
System.out.println(score[index]);
}
}
}

Monday, December 19, 2005

Lab 12-19-2005 Class Parameter

package zxza;
public class add {
public static void main(String[] args) {
complex a1=new complex(2,3);
complex a2=new complex(4,5);
a1.add(a2);
System.out.println(a1.a+"+"+a1.b+"i");

}
}

package zxza;
public class complex
{int a=0,b=0;
public complex(int a,int b){
setComplex(a,b);
}
public void setComplex(int a,int b) {
this.a=a; this.b=b;
}
public void add(complex Q1){
this.a=this.a+Q1.a;
this.b=this.b+Q1.b;
}
}



"Homework 12-12-2005 Counter II"

mport java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;

class Date {
private String month;
private int day;
private int year;

public Date() {
month = "Jan";
day = 1;
year = 1000;
}

public Date(int monthInt, int day, int year) {
setDate(monthInt, day, year);
}

public Date(String monthString, int day, int year) {
setDate(monthString, day, year);
}

public Date(int year) {
setDate(1, 1, year);
}

public Date(Date aDate) {
if (aDate == null) {
System.out.println("Fatal Error.");
System.exit(0);
}

month = aDate.month;
day = aDate.day;
year = aDate.year;
}

public void setDate(int monthInt, int day, int year) {
if (dateOK(monthInt, day, year)) {
this.month = monthString(monthInt);
this.day = day;
this.year = year;
} else {
System.out.println("Fatal Error");
System.exit(0);
}
}

public void setDate(String monthString, int day, int year) {
if (dateOK(monthString, day, year)) {
this.month = monthString;
this.day = day;
this.year = year;
} else {
System.out.println("Fatal Error");
System.exit(0);
}
}

public void setDate(int year) {
setDate(1, 1, year);
}

public void setYear(int year) {
if ((year < 1000) || (year > 9999)) {
System.out.println("Fatal Error");
System.exit(0);
} else {
this.year = year;
}
}

public void setMonth(int monthNumber) {
if ((monthNumber <= 0) || (monthNumber > 12)) {
System.out.println("Fatal Error");
System.exit(0);
} else {
month = monthString(monthNumber);
}
}

public void setDay(int day) {
if ((day <= 0) || (day > 31)) {
System.out.println("Fatal Error");
System.exit(0);
} else {
this.day = day;
}
}

public int getMonth() {
if (month.equals("Jan")) {
return 1;
} else if (month.equals("Feb")) {
return 2;
} else if (month.equals("Mar")) {
return 3;
} else if (month.equals("Apr")) {
return 4;
} else if (month.equals("May")) {
return 5;
} else if (month.equals("Jun")) {
return 6;
} else if (month.equals("Jul")) {
return 7;
} else if (month.equals("Aug")) {
return 8;
} else if (month.equals("Sep")) {
return 9;
} else if (month.equals("Oct")) {
return 10;
} else if (month.equals("Nov")) {
return 11;
} else if (month.equals("Dec")) {
return 12;
} else {
System.out.println("Fatal Error");
System.exit(0);
return 0; //Needed to keep the compiler happy
}
}

public int getDay() {
return day;
}

public int getYear() {
return year;
}

public String toString() {
return (month + " " + day + ", " + year);
}

public boolean equals(Date otherDate) {
return ((month.equals(otherDate.month))
&& (day == otherDate.day) && (year == otherDate.year));
}

public boolean precedes(Date otherDate) {
return ((year < otherDate.year) ||
(year == otherDate.year && getMonth() < otherDate.getMonth()) ||
(year == otherDate.year && month.equals(otherDate.month)
&& day < otherDate.day));
}

public void readInput() throws IOException {
boolean tryAgain = true;
BufferedReader keyboard = new BufferedReader(
new InputStreamReader(System.in));
while (tryAgain) {
System.out.println(
"Enter month, day, and year on three lines.");
System.out.println(
"Enter month, day, and year as three integers.");

int monthInput = Integer.parseInt(keyboard.readLine());
int dayInput = Integer.parseInt(keyboard.readLine());
int yearInput = Integer.parseInt(keyboard.readLine());
if (dateOK(monthInput, dayInput, yearInput)) {
setDate(monthInput, dayInput, yearInput);
tryAgain = false;
} else {
System.out.println("Illegal date. Reenter input.");
}
}
}

private boolean dateOK(int monthInt, int dayInt, int yearInt) {
return ((monthInt >= 1) && (monthInt <= 12) &&
(dayInt >= 1) && (dayInt <= 31) &&
(yearInt >= 1000) && (yearInt <= 9999));
}

private boolean dateOK(String monthString, int dayInt, int yearInt) {
return (monthOK(monthString) &&
(dayInt >= 1) && (dayInt <= 31) &&
(yearInt >= 1000) && (yearInt <= 9999));
}

private boolean monthOK(String month) {
return (month.equals("Jan") || month.equals("Feb") ||
month.equals("Mar") || month.equals("Apr") ||
month.equals("May") || month.equals("Jun") ||
month.equals("Jul") || month.equals("Aug") ||
month.equals("Sep") || month.equals("Oct") ||
month.equals("Nov") || month.equals("Dec"));
}

private String monthString(int monthNumber) {
switch (monthNumber) {
case 1:
return "Jan";
case 2:
return "Feb";
case 3:
return "Mar";
case 4:
return "Apr";
case 5:
return "May";
case 6:
return "Jun";
case 7:
return "Jul";
case 8:
return "Aug";
case 9:
return "Sep";
case 10:
return "Oct";
case 11:
return "Nov";
case 12:
return "Dec";
default:
System.out.println("Fatal Error");
System.exit(0);
return "Error";
}
}
}

public class aa {
public static void main(String[] args) {
Date date1 = new Date("Dec", 16, 1770), date2 = new Date(1, 27, 1756),
date3 = new Date(1882), date4 = new Date();

System.out.println("Whose birthday is " + date1 + "?");
System.out.println("Whose birthday is " + date2 + "?");
System.out.println("Whose birthday is " + date3 + "?");
System.out.println("The default date is " + date4 + ".");
}
}

Lab 12-12-2005 (2) Static Class

public class Fibonacci {
public static double n0=1,n1=1,n2=0;
public static double next()
{
n2=n0+n1;
n0=n1;
n1=n2;
return n2;
}
}


/////////Fibonacci
public class Next {
public static void main(String[] args)
{
for(int i=0;i<100;i++)
{
System.out.println(Fibonacci.next());
}
}
}

Monday, December 12, 2005

Lab 12-12-2005 (1) Constructor

檔案 ConstructorsDemo
package aaa;

public class ConstructorsDemo
{
public static void main(String[] args)
{
Date date1 = new Date("December", 16, 1770);
Date date2 = new Date(12, 27, 1756);
Date date3 = new Date(1882);
Date date4 = new Date( );

System.out.println("Whose birthday is " + date1 + "?");
System.out.println("Whose birthday is " + date2 + "?");
System.out.println("Whose birthday is " + date3 + "?");
System.out.println("The default date is " + date4 + ".");
}
}

檔案 Date

package aaa;
import java.io.*;
public class Date
{
private String month;
private int day;
private int year;

public Date( )
{
month = "January";
day = 1;
year = 1000;
}

public Date(int monthInt, int day, int year)
{
setDate(monthInt, day, year);
}

public Date(String monthString, int day, int year)
{
setDate(monthString, day, year);
}

public Date(int year)
{
setDate(1, 1, year);
}

public Date(Date aDate)
{
if (aDate == null)
{
System.out.println("Fatal Error.");
System.exit(0);
}

month = aDate.month;
day = aDate.day;
year = aDate.year;
}

public void setDate(int monthInt, int day, int year)
{
if (dateOK(monthInt, day, year))
{
this.month = monthString(monthInt);
this.day = day;
this.year = year;
}
else
{
System.out.println("Fatal Error");
System.exit(0);
}
}

public void setDate(String monthString, int day, int year)
{
if (dateOK(monthString, day, year))
{
this.month = monthString;
this.day = day;
this.year = year;
}
else
{
System.out.println("Fatal Error");
System.exit(0);
}
}

public void setDate(int year)
{
setDate(1, 1, year);
}

public void setYear(int year)
{
if ( (year < 1000) || (year > 9999) )
{
System.out.println("Fatal Error");
System.exit(0);
}
else
this.year = year;
}
public void setMonth(int monthNumber)
{
if ((monthNumber <= 0) || (monthNumber > 12))
{
System.out.println("Fatal Error");
System.exit(0);
}
else
month = monthString(monthNumber);
}

public void setDay(int day)
{
if ((day <= 0) || (day > 31))
{
System.out.println("Fatal Error");
System.exit(0);
}
else
this.day = day;
}

public int getMonth( )
{
if (month.equals("January"))
return 1;
else if (month.equals("February"))
return 2;
else if (month.equalsIgnoreCase("March"))
return 3;
else if (month.equalsIgnoreCase("April"))
return 4;
else if (month.equalsIgnoreCase("May"))
return 5;
else if (month.equals("June"))
return 6;
else if (month.equalsIgnoreCase("July"))
return 7;
else if (month.equalsIgnoreCase("August"))
return 8;
else if (month.equalsIgnoreCase("September"))
return 9;
else if (month.equalsIgnoreCase("October"))
return 10;
else if (month.equals("November"))
return 11;
else if (month.equals("December"))
return 12;
else
{
System.out.println("Fatal Error");
System.exit(0);
return 0;
}
}

public int getDay( )
{
return day;
}

public int getYear( )
{
return year;
}

public String toString( )
{
return (month + " " + day + ", " + year);
}

public boolean equals(Date otherDate)
{
return ( (month.equals(otherDate.month))
&& (day == otherDate.day) && (year == otherDate.year) );
}

public boolean precedes(Date otherDate)
{
return ( (year < otherDate.year) ||
(year == otherDate.year && getMonth( ) < otherDate.getMonth( )) ||
(year == otherDate.year && month.equals(otherDate.month)
&& day < otherDate.day) );
}

public void readInput( ) throws IOException
{
boolean tryAgain = true;
BufferedReader keyboard= new BufferedReader(new InputStreamReader(System.in));

while (tryAgain)
{
System.out.println("Enter month, day, and year.");
System.out.println("Do not use a comma.");
String monthInput = keyboard.readLine( );
int dayInput = keyboard.read( );
int yearInput = keyboard.read( );
if (dateOK(monthInput, dayInput, yearInput) )
{
setDate(monthInput, dayInput, yearInput);
tryAgain = false;
}
else
System.out.println("Illegal date. Reenter input.");
}
}

private boolean dateOK(int monthInt, int dayInt, int yearInt)
{
return ( (monthInt >= 1) && (monthInt <= 12) &&
(dayInt >= 1) && (dayInt <= 31) &&
(yearInt >= 1000) && (yearInt <= 9999) );
}

private boolean dateOK(String monthString, int dayInt, int yearInt)
{
return ( monthOK(monthString) &&
(dayInt >= 1) && (dayInt <= 31) &&
(yearInt >= 1000) && (yearInt <= 9999) );
}

private boolean monthOK(String month)
{
return (month.equals("January") || month.equals("February") ||
month.equals("March") || month.equals("April") ||
month.equals("May") || month.equals("June") ||
month.equals("July") || month.equals("August") ||
month.equals("September") || month.equals("October") ||
month.equals("November") || month.equals("December") );
}

private String monthString(int monthNumber)
{
switch (monthNumber)
{
case 1:
return "January";
case 2:
return "February";
case 3:
return "March";
case 4:
return "April";
case 5:
return "May";
case 6:
return "June";
case 7:
return "July";
case 8:
return "August";
case 9:
return "September";
case 10:
return "October";
case 11:
return "November";
case 12:
return "December";
default:
System.out.println("Fatal Error");
System.exit(0);
return "Error";
}
}
}




Homework 12-5-2005

package abcd;

public class Temperature {

private double value;
private char scale;

public Temperature() {
this.value = 0;
this.scale = 'C';
}

public Temperature(double value) {
this.value = value;
this.scale = 'C';
}

public Temperature(char scale) {
this.value = 0;
if (scale == 'f' || scale == 'F') {
this.scale = 'F';
}
else if (scale == 'c' || scale == 'C') {
this.scale = 'C';
}
else {
System.out.println("Error Scale,and scale set C");
this.scale = 'C';
}
}

public Temperature(double value, char scale) {
this.value = value;
if (scale == 'f' || scale == 'F') {
this.scale = 'F';
}
else if (scale == 'c' || scale == 'C') {
this.scale = 'C';
}
else {
System.out.println("Error Scale,and scale set C");
this.scale = 'C';
}
}

public double getTempC() {
double temp = 0;
if (scale == 'C')
{
temp = value;
}
else if (scale == 'F') {
temp = (value - 32) * 5 / 9;
}
return temp;
}

public double getTempF() {
double temp = 0;
if (scale == 'F') {
temp = value;
}
else if (scale == 'C') {
temp = (value * 9 / 5) + 32;
}
return temp;
}

public void setValue(double value) {
this.value = value;
}

public void setScale(char scale) {
if (scale == 'f' || scale == 'F') {
this.scale = 'F';
}
else if (scale == 'c' || scale == 'C') {
this.scale = 'C';
}
else {
System.out.println("Error Scale,and scale no change");
}
}

public void setTemp(double value, char scale) {
if (scale == 'f' || scale == 'F') {
this.scale = 'F';
}
else if (scale == 'c' || scale == 'C') {
this.scale = 'C';
}
else {
System.out.println("Error Scale,and scale no change");
}
this.value = value;
}

public boolean Equals(Temperature otherTemp) {
if (this.scale == 'C' && this.value == otherTemp.getTempC()) {
return true;
}
else if (this.scale == 'F' && this.value == otherTemp.getTempF()) {
return true;
}
else {
return false;
}
}

public boolean GreaterThan(Temperature otherTemp) {
if (this.scale == 'C' && this.value >= otherTemp.getTempC()) {
return true;
}
else if (this.scale == 'F' && this.value >= otherTemp.getTempF()) {
return true;
}
else {
return false;
}
}

public boolean LessThan(Temperature otherTemp) {
if (this.scale == 'C' && this.value <= otherTemp.getTempC()) {
return true;
}
else if (this.scale == 'F' && this.value <= otherTemp.getTempF()) {
return true;
}
else {
return false;
}
}

public String toString() {
return Double.toString(value) + scale;
}

}


class TemperatureTest {

public static void main(String[] args) {

Temperature iceC = new Temperature(0.0, 'C');
Temperature iceF = new Temperature(32.0, 'F');

Temperature fireC = new Temperature(100.0);
fireC.setScale('C');
Temperature fireF = new Temperature(212.0);
fireF.setScale('F');

Temperature coldC = new Temperature();
coldC.setTemp( -40.0, 'C');
Temperature coldF = new Temperature();
coldF.setScale('F');
coldF.setValue( -40.0);

System.out.println("iceC = " + iceC );
System.out.println("iceF = " + iceF );
System.out.println("fireC = " + fireC );
System.out.println("fireF = " + fireF );
System.out.println("coldC = " + coldC + " , " + coldC.getTempF() + "F");
System.out.println("coldF = " + coldF + " , " + coldF.getTempC() + "C");

System.out.print("\nTest Equals ? \n");
System.out.println(iceC + " = " + coldC + " ? " + iceC.Equals(coldC));
System.out.println(iceC + " = " + iceF + " ? " + iceC.Equals(iceF));
System.out.println(iceF + " = " + coldC + " ? " + iceF.Equals(coldC));
System.out.println(iceF + " = " + iceC + " ? " + iceF.Equals(iceC));

System.out.print("\nTest LessThan ? \n");
System.out.println(iceC + " <= " + coldC + " ? " + iceC.LessThan(coldC));
System.out.println(iceC + " <= " + fireF + " ? " + iceC.LessThan(fireF));
System.out.println(iceF + " <= " + coldC + " ? " + iceF.LessThan(coldC));
System.out.println(iceF + " <= " + fireC + " ? " + iceF.LessThan(fireC));

System.out.print("\nTest GreaterThan ? \n");
System.out.println(iceC + " >= " + fireC + " ? " + iceC.GreaterThan(fireC));
System.out.println(iceC + " >= " + coldF + " ? " + iceC.GreaterThan(coldF));
System.out.println(iceF + " >= " + fireF + " ? " + iceF.GreaterThan(fireF));
System.out.println(iceF + " >= " + coldF + " ? " + iceF.GreaterThan(coldF));


}

}

Monday, December 05, 2005

Lab 12-5-2005 (2) Overloading

package untitled3;
import java.io.*;
public class DateSixthTry
{
private String month;
private int day;
private int year;

public void setDate(int monthInt, int day, int year)
{
if (dateOK(monthInt, day, year))
{
this.month = monthString(monthInt);
this.day = day;
this.year = year;
}
else
{
System.out.println("Fatal Error");
System.exit(0);
}
}

public void setDate(String monthString, int day, int year)
{
if (dateOK(monthString, day, year))
{
this.month = monthString;
this.day = day;
this.year = year;
}
else
{
System.out.println("Fatal Error");
System.exit(0);
}
}

public void setDate(int year)
{
setDate(1, 1, year);
}

private boolean dateOK(int monthInt, int dayInt, int yearInt)
{
return ( (monthInt >= 1) && (monthInt <= 12) &&
(dayInt >= 1) && (dayInt <= 31) &&
(yearInt >= 1000) && (yearInt <= 9999) );
}

private boolean dateOK(String monthString, int dayInt, int yearInt)
{
return ( monthOK(monthString) &&
(dayInt >= 1) && (dayInt <= 31) &&
(yearInt >= 1000) && (yearInt <= 9999) );
}

private boolean monthOK(String month)
{
return (month.equals("January") || month.equals("Feb") ||
month.equals("March") || month.equals("Apr") ||
month.equals("May") || month.equals("June") ||
month.equals("July") || month.equals("August") ||
month.equals("September") || month.equals("October") ||
month.equals("November") || month.equals("December") );
}


public void readInput( )throws IOException
{
boolean tryAgain = true;
BufferedReader keyboard = new BufferedReader(new InputStreamReader(System.in));
while (tryAgain)
{
System.out.println("Enter month, day, and year.");
System.out.println("Do not use a comma.");
String monthInput = keyboard.readLine( );
int dayInput = keyboard.read( );
int yearInput = keyboard.read( );
if (dateOK(monthInput, dayInput, yearInput) )
{
setDate(monthInput, dayInput, yearInput);
tryAgain = false;
}
else
System.out.println("Illegal date. Reenter input.");
}
}


public void writeOutput( )
{
System.out.println(month + " " + day + ", " + year);
}

public void setMonth(int month)
{
if ((month <= 0) || (month > 12))
{
System.out.println("Fatal Error");
System.exit(0);
}
else
this.month = monthString(month);
}
public void setMonth(String month)
{
this.month = month;
}

public void setDay(int day)
{
if ((day <= 0) || (day > 31))
{
System.out.println("Fatal Error");
System.exit(0);
}
else
this.day = day;
}

public void setYear(int year)
{
if ( (year < 1000) || (year > 9999) )
{
System.out.println("Fatal Error");
System.exit(0);
}
else
this.year = year;
}

public boolean equals(DateSixthTry otherDate)
{
return ( (month.equalsIgnoreCase(otherDate.month))
&& (day == otherDate.day) && (year == otherDate.year) );
}
public boolean precedes(DateSixthTry otherDate)
{
return ( (year < otherDate.year) ||
(year == otherDate.year && getMonth( ) < otherDate.getMonth( )) ||
(year == otherDate.year && month.equals(otherDate.month)
&& day < otherDate.day) );
}

public String toString( )
{
return (month + " " + day + ", " + year);
}

public int getDay( )
{
return day;
}

public int getYear( )
{
return year;
}

public int getMonth( )
{
if (month.equalsIgnoreCase("January"))
return 1;
else if (month.equalsIgnoreCase("Feb"))
return 2;
else if (month.equalsIgnoreCase("March"))
return 3;
else if (month.equalsIgnoreCase("Apr"))
return 4;
else if (month.equalsIgnoreCase("May"))
return 5;
else if (month.equals("June"))
return 6;
else if (month.equalsIgnoreCase("July"))
return 7;
else if (month.equalsIgnoreCase("August"))
return 8;
else if (month.equalsIgnoreCase("September"))
return 9;
else if (month.equalsIgnoreCase("October"))
return 10;
else if (month.equalsIgnoreCase("November"))
return 11;
else if (month.equalsIgnoreCase("December"))
return 12;
else
{
System.out.println("Fatal Error");
System.exit(0);
return 0;
}
}


private String monthString(int monthNumber)
{
switch (monthNumber)
{
case 1:
return "January";
case 2:
return "February";
case 3:
return "March";
case 4:
return "April";
case 5:
return "May";
case 6:
return "June";
case 7:
return "July";
case 8:
return "August";
case 9:
return "September";
case 10:
return "October";
case 11:
return "November";

case 12:
return "December";
default:
System.out.println("Fatal Error");
System.exit(0);
return "Error";
}
}
}


package untitled3;

public class overloadingdemo {
public static void main(String[]args) {
DateSixthTry date1=new DateSixthTry();
DateSixthTry date2=new DateSixthTry();
DateSixthTry date3=new DateSixthTry();

date1.setDate(1,2,2007);
date1.setMonth(3);
date2.setDate("Feb",2,2007);
date2.setMonth("Apr");
date3.setDate(2007);

System.out.println(date1);
System.out.println(date2);
System.out.println(date3);




}
}

"Lab 12-5-2005 (1) Using "this""

public void setDate(int month, int day, int year)
{
this.month = monthString(month);
this.day = day;
this.year = year;
}


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
只要改這一部分就可以了,不用多加三個變數,只要用THIS就OK了...

Homework 11-28-2005

public class Counter {
private int count;
public Counter() {
}
public void setZero()
{
count=0;
}
public void countIncrease()
{
count=count+1;
}
public void countDecrease()
{
if((count-1)>=0)
count=count-1;
else if((count-1)<0)
System.out.println("Decrease counnt is negative");
}
public int accessor()
{
return count;
}
public void out()
{
System.out.println(""+count);
}
public static void main(String[] args) {
}
}


public static void main(String[] args) {
Counter count1 = new Counter(),count2=new Counter();
System.out.println("count set to zero.");
count1.setZero();
System.out.print("coun1=");
count1.out();
System.out.print("coun2=");
count2.setZero();
count2.out();
System.out.println("count is increase or dercase");
System.out.print("coun1=");
count1.countIncrease();
count1.countIncrease();
count1.out();
System.out.print("coun2=");
count2.countIncrease();
count2.countDecrease();
count2.out();
if(count1 ==count2)
System.out.println("count1 is equal count2");
else
System.out.println("count1 does not equal count2");
count2.countIncrease();
count2.accessor();
}

Monday, November 28, 2005

display 4.7 4.8

package aaa;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;


public class DateFourthTry
{
private String month;
private int day;
private int year;

public String toString( )
{
return (month + " " + day + ", " + year);
}

public void writeOutput( )
{
System.out.println(month + " " + day + ", " + year);
}



public boolean equals(DateFourthTry otherDate)
{
return ( (month.equals(otherDate.month))
&&amp; (day == otherDate.day) && (year == otherDate.year) );
}

public boolean precedes(DateFourthTry otherDate)
{
return ( (year < year ="="" year ="="" month =" monthString(newMonth);" day =" aday;" year =" ayear;" keyin=" new" month =" keyin.readLine(" day =" keyin.read(" year =" keyin.read(" date1 =" new" date2 =" new" onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://photos1.blogger.com/blogger/4172/1585/1600/2222.0.jpg">

Class Definition (2)

package project 111;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
public class class1
{
public String month;
public int day;
public int year;

public void readInput()throws IOException
{
System.out.println("Please enter month.(Ex:Jan, Feb...)");
BufferedReader keyinMonth = new BufferedReader(new InputStreamReader(System.in));
month = keyinMonth.readLine();
System.out.println("Please enter day.");
BufferedReader keyinDay = new BufferedReader(new InputStreamReader(System.in));
day = Integer.parseInt(keyinDay.readLine());
System.out.println("Please enter year.");
BufferedReader keyinYear = new BufferedReader(new InputStreamReader(System.in));
year = Integer.parseInt(keyinYear.readLine());
}

public void setDate()
{
month="Jun";
day=01;
year=2004;
}

public int getDay()
{
return day;
}
public int getYear()
{
return year;
}
public int getMonth()
{
if(month.equalsIgnoreCase("Jan"))
return 1;
else if(month.equalsIgnoreCase("Feb"))
return 2;
else if(month.equalsIgnoreCase("Mar"))
return 3;
else if(month.equalsIgnoreCase("Apr"))
return 4;
else if(month.equalsIgnoreCase("May"))
return 5;
else if(month.equalsIgnoreCase("Jun"))
return 6;
else if(month.equalsIgnoreCase("Jul"))
return 7;
else if(month.equalsIgnoreCase("Aug"))
return 8;
else if(month.equalsIgnoreCase("Sep"))
return 9;
else if(month.equalsIgnoreCase("Oct"))
return 10;
else if(month.equalsIgnoreCase("Nov"))
return 11;
else if(month.equalsIgnoreCase("Dec"))
return 12;
else
{
System.out.println("Fatal Error");
System.exit(0);
return 0;
}
}
}