Monday, April 10, 2006

Lab Class Definitions II

package aaa;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
public class aaa {

private String month;
private int day;
private int year;
public void writeOutput(){
System.out.println(month+","+day+","+year);
}
public void readInput() throws IOException{
BufferedReader keyboard;
keyboard= new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter month,day,and year on three lines:");
month=keyboard.readLine();
day=Integer.parseInt(keyboard.readLine());
year=Integer.parseInt(keyboard.readLine());
}

public int getDay(){
return day;
}
public int getYear(){
return year;
}
public int getMonth(){
if(month.equalsIgnoreCase("January"))
return 1;
else if(month.equalsIgnoreCase("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.equalsIgnoreCase("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("Octorber"))
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;
}
}

}
//===========================================
package aaa;

import java.io.IOException;

public class aaa2 {
public aaa2() {
}

public static void main(String[] args) throws IOException {
fff date=new aaa();
date.readInput();
date.writeOutput();

int dayNumber=date.getDay();
System.out.println("That is the "+dayNumber+"th day of the month.");
}
}

0 Comments:

Post a Comment

<< Home