Mon Sep 13, 2010 3:21 am
package cs2000.Lab2;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Calender {
public Date calculateNextDay(Date today) {
Date nextDay = null;
// TODO
// calculate the next day
return nextDay;
}
/**
* @param args
*/
public static void main(String[] args) {
System.out.println("Welcome to the calender program of class CS2003! \n");
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
String choice = "y";
while(choice.equals("y")){
// take the input date from the command line
String input = "";
try {
System.out.println("Please type the date in the format MM/DD/YYYY");
System.out.println("or \"n\" to exit the program?");
input = in.readLine();
} catch (IOException e) {
e.printStackTrace();
continue;
}
// user decided to finish
if(input.equals("n")) {
System.out.println("Thank you for using our calender");
// exit the while loop by using break command
break;
}
// TODO
// Create a new Date object with given input
// Get the next day and display it to the user
}
return;
}
}
package cs2000.Lab2;
public class Date {
public static final double PI = 3.14;
// field variables
private String monthString;
private int month;
private int day;
private int year;
public Date(int month, int day, int year) {
super();
this.month = month;
this.day = day;
this.year = year;
}
public Date(String date) {
super();
// TODO
// parse the given string "date"
// for parsing, you can use StringTokenizer class of JAVA API
// then call the other constructor
// or set the values of field variables
}
// setter/getter methods of the field variables
public String getMonthString() {
return monthString;
}
public void setMonthString(String monthString) {
this.monthString = monthString;
}
public int getMonth() {
return month;
}
public void setMonth(int month) {
this.month = month;
}
public int getDay() {
return day;
}
public void setDay(int day) {
this.day = day;
}
public int getYear() {
return year;
}
public void setYear(int year) {
this.year = year;
}
// delegate method toString()
public String toString() {
return monthString+" "+day+", "+year;
}
}
Codemiles.com is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to Amazon.com
Powered by phpBB © phpBB Group.