[Show all top banners]

Slackdemic
Replies to this thread:

More by Slackdemic
What people are reading
Subscribers
:: Subscribe
Back to: Kurakani General Refresh page to view new replies
 Java Programming Help!
[VIEWED 2215 TIMES]
SAVE! for ease of future access.
Posted on 09-14-06 4:33 PM     Reply [Subscribe]
Login in to Rate this Post:     0       ?    
 

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:

 
Posted on 09-14-06 5:02 PM     Reply [Subscribe]
Login in to Rate this Post:     0       ?    
 

http://java.sun.com/j2se/1.4.2/docs/api/java/util/Date.html

if you can't do this by looking at this, let us know. The task is pretty much straight forward and easy.
 
Posted on 09-14-06 5:19 PM     Reply [Subscribe]
Login in to Rate this Post:     0       ?    
 

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 < 12 )
dateMonth = month;

}

public Date ( int dateDay )

if
{ ( dateDay > 0 )
( dateDay < 31 )
dateDay = day;
}
}
public int getMonth()
{
return month;
}

public int getDay()
{
return day;
}


}
 
Posted on 09-14-06 7:19 PM     Reply [Subscribe]
Login in to Rate this Post:     0       ?    
 

I think the way I put if statement is not correct, and I am not sure if if sentence is needed there...
 
Posted on 09-14-06 7:40 PM     Reply [Subscribe]
Login in to Rate this Post:     0       ?    
 

Change this
if
{
( dateMonth > 0 )
( dateMonth < 12 )
dateMonth = month;

}

To
if
{
( 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...
 
Posted on 09-14-06 8:28 PM     Reply [Subscribe]
Login in to Rate this Post:     0       ?    
 

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! :(
 
Posted on 09-14-06 11:15 PM     Reply [Subscribe]
Login in to Rate this Post:     0       ?    
 

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?
 
Posted on 09-15-06 9:17 AM     Reply [Subscribe]
Login in to Rate this Post:     0       ?    
 

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.
 
Posted on 09-15-06 9:39 AM     Reply [Subscribe]
Login in to Rate this Post:     0       ?    
 

Just the regular testclass!
 
Posted on 09-15-06 4:21 PM     Reply [Subscribe]
Login in to Rate this Post:     0       ?    
 

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!
 


Please Log in! to be able to reply! If you don't have a login, please register here.

YOU CAN ALSO



IN ORDER TO POST!




Within last 200 days
Recommended Popular Threads Controvertial Threads
शीर्षक जे पनि हुन सक्छ।
NRN card pros and cons?
What are your first memories of when Nepal Television Began?
TPS Re-registration
TPS Re-registration case still pending ..
Democrats are so sure Trump will win
Basnet or Basnyat ??
nrn citizenship
Sajha has turned into MAGATs nest
Nas and The Bokas: Coming to a Night Club near you
ChatSansar.com Naya Nepal Chat
डीभी परेन भने खुसि हुनु होस् ! अमेरिकामाधेरै का श्रीमती अर्कैसँग पोइला गएका छन् !
3 most corrupt politicians in the world
अमेरिकामा बस्ने प्राय जस्तो नेपालीहरु सबै मध्यम बर्गीय अथवा माथि (higher than middle class)
if you are in USA illegally and ask for asylum it is legal
Travelling to Nepal - TPS AP- PASSPORT
emergency donation needed
Top 10 Anti-vaxxers Who Got Owned by COVID
आज बाट तिहारको सेल सकियो
निगुरो थाहा छ ??
Nas and The Bokas: Coming to a Night Club near you
Mr. Dipak Gyawali-ji Talk is Cheap. US sends $ 200 million to Nepal every year.
Harvard Nepali Students Association Blame Israel for hamas terrorist attacks
TPS Update : Jajarkot earthquake
NOTE: The opinions here represent the opinions of the individual posters, and not of Sajha.com. It is not possible for sajha.com to monitor all the postings, since sajha.com merely seeks to provide a cyber location for discussing ideas and concerns related to Nepal and the Nepalis. Please send an email to admin@sajha.com using a valid email address if you want any posting to be considered for deletion. Your request will be handled on a one to one basis. Sajha.com is a service please don't abuse it. - Thanks.

Sajha.com Privacy Policy

Like us in Facebook!

↑ Back to Top
free counters