Switch to full style
Java2 codes,problems ,discussions and solutions are here
Post a reply

Programming Calendar Java

Mon Sep 13, 2010 3:21 am

Programming Calendar in java:
My program is supposed to take a date as in input and return the next day as an output. The input format is MM/DD/YY , and the output should be Month DD, YYYY, i.e. September 09, 2009. I was provided Date and Calendar classes, but there are missing parts specified with TODO comments within the code. Unfortunately, Im having a hard time finishing the missing parts and Im wondering if anyone can help. I attached my java code with this. If it would be easier to post my code too instead of just attaching it, just let me know.
Code:

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;
    }

}

 


Date :
Code:

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;
    }
}

 



Attachments
Calender.java
(1.23 KiB) Downloaded 933 times
Date.java
(1.17 KiB) Downloaded 892 times

Post a reply
  Related Posts  to : Programming Calendar Java
 draw Calendar in java     -  
 java.util Calendar To TimeStamp     -  
 Java Programming help please?     -  
 i want some help in java programming     -  
 Calendar Generator     -  
 Programming a Defragger in Java     -  
 simple javascript calendar     -  
 Java Programming Problem: Pascal's Triangle     -  
 C++ programming     -  
 ALP programming     -