← Back to Kurakani

Java Programming Help!

Original Post

Maybe few people here know that I had a problem with JDK and JCreator. Because it took several days before I could successfully compile a simple java program, I didn't get to practice as I am supposed to. Anyway, I have a project to work on. I am kinda lost here because I am not sure where to start. To get this program done, I have divided this into three phases. If some Java people can direct me to get started for the phase I, I would be amply rewarded Here's what I've to do: Purpose: To write a class for a Date Object and a Class that will test the Date Class. DATE CLASS DESCRIPTION The object will include three properties, month, day and year as instance variables. Include two constructors in your class. A default constructor which initializes all instance variables to zero and a constructor which initializes the instance variables with parameter values passed to the constructor. On this assignment you may assume the values provided are correct…you do not have to provide error detection. Provide the following methods. 􀂃 set and get methods for each of the instance variables. 􀂃 a method to add a specified number of days based on a parameter value passed to the method. 􀂃 a method to add a specified number of months based on a parameter value passed to the method. 􀂃 a method to add a specified number of years based on a parameter value passed to the method. 􀂃 a toString () that will print the date in the following format mm/dd/yyyy TESTDATE CLASS DESCRIPTION Create a TestDate class which will test your Date class by doing the following. 􀂃 Create a default Date Object 􀂃 Create a Date Object with a valid day, month, year (use your birthday) 􀂃 Print the Date Objects before any modifications to the objects have been made 􀂃 Set the day, month and year on the default Date Object using set methods 􀂃 Add days to the birthdate Date Object to test the addDay method 􀂃 Add months to the birthdate Date Object to test the addMonth method 􀂃 Add years to the birthdate Date Object to test the addYear method 􀂃 Print the Date Objects after modifications 􀂃 Print the days, month, and year of a Date Object with the get methods. PHASES Phase I: Date class will calculate not be concerned with valid dates after adding days and months. Phase II: Your Date class will calculate valid dates after adding days and months but will not be concerned with leap year. Phase III: Your Date class will calculate valid dates for each year. OBJECTIVES 􀂃 Demonstrate ability to declare a class and use it to create an object 􀂃 Demonstrate ability to declare methods in a class to implement the class behaviors 􀂃 Demonstrate ability to declare instance variables to implement class attributes 􀂃 Demonstrate ability to use a constructor to ensure an object’s data is initialized when the object is created 􀂃 Demonstrate ability to use problem-solving techniques 􀂃 Demonstrate ability to use if and if…else selection statements. 􀂃 IF: o Birthday is 9/30/1986 o Default date was set to 6/26/1960 o One day is added to birthday Date Object o Six months is added to birthday Date Object o 10 years is added to birthday Date Object The output for PHASE-I and PHASE-II will be:

Slackdemic
Sep 14, 2006 4:33 PM · 5,151 views
9 Replies
Gajedi Sep 14, 2006 5:02 PM
http://java.sun.com/j2se/1.4.2... if you can't do this by looking at this, let us know. The task is pretty much straight forward and easy.
Slackdemic Sep 14, 2006 5:19 PM
The one I am trying to do here should be way too easier than the example on the site. I try to get started, and I am sure, it is wrong, but this is what I tried to do. public class Date { private int month; private int day; private int year; public Date ( int dateMonth ) { if { ( dateMonth > 0 ) ( dateMonth 0 ) ( dateDay < 31 ) dateDay = day; } } public int getMonth() { return month; } public int getDay() { return day; } }
Slackdemic Sep 14, 2006 7:19 PM
I think the way I put if statement is not correct, and I am not sure if if sentence is needed there...
GreenMapleTree Sep 14, 2006 7:40 PM
Change this if { ( dateMonth > 0 ) ( dateMonth 0 ) && ( dateMonth < 12 ) dateMonth = month; //so what is the requirement if someone pass you invalid date/month or Year.. do you ignore it or replace with something? } to implement toString method do this public string toString(){ //if you need to add '0' in front of day and month do it here String dateString=month+"/"+date+"/"+Year } Phase II and III will be a piece of cake if you know how to implement Java's own calendar object. Calendar object will take care of adding/subtracting/... all the date calculation. You just need to know how to call it. I can do it for you but you won't learn anything. If this is for the first year programming course, instructor may not like it either. I think I even had this problem in my college days... but we had to do it in C++ with Object oriented methodology... that was 2 weeks of pure torture... but after that everything was downhill... If you can afford to put some time, do it now... it will reward you for the rest of your life...
Slackdemic Sep 14, 2006 8:28 PM
Thank you GreenMapleTree..Well, I am just the beginner in Java; I am not to use calendar object yet. I myself don't think phase II and phase III would be that hard if I can go through with Phase-I. Like you told, it is being kinda of torture to me. I have to turn it in tomorrow and I am just stuck here! :(
Slackdemic Sep 14, 2006 11:15 PM
OK, now I am done with Date.jave...this is what I did: public class Date { private int month; private int day; private int year; public Date ( int dateMonth, int dateDay, int dateYear ) { { month = dateMonth; day = dateDay; year = dateYear; } public void setMonth ( int dateMonth ) { month = dateMonth; } public void setDay (int dateDay ) { day = dateDay; } public void setYear( int dateYear ) { year = dateYear; } public int getMonth() { return month; } public int getDay() { return day; } public int getYear() { return Year; } public String toString() { Sring dateMonth = " "; Sring dateDay = " "; Sring dateYear = " "; return dateMonth + "/" + dateDay + "/" dateYear; } } Now I am stuck with class TestDate.java part. Any idea?
Gajedi Sep 15, 2006 9:17 AM
There are so many things that you need to consider in your date class. Your date class doesn't have methods to add date. Make a package for the date class and import it in the datetest or a make a package for both date and datetest classes. Do you want to make the datetest a Junit testcase or just a regular testclass? Ask specific questions rather than asking us to post the whole datetest class for you.
Slackdemic Sep 15, 2006 9:39 AM
Just the regular testclass!
Slackdemic Sep 15, 2006 4:21 PM
Thank you, all of you who tried to help me in one way or another. Now I am done with Phase-I, I am "promoted" to work for Phase-II. I will be posting as my problems arise when I will start...maybe later today or tomorrow! Thank you, all!
Login to join the conversation.

You might be interested in...

Recent Classifieds View all
Upcoming Events View all
Service Providers View all
Ask Sajha AI Assistant