The Artima Developer Community
Sponsored Link

Java Answers Forum
I would like to ask some help....

3 replies on 1 page. Most recent reply: Sep 29, 2005 4:09 PM by rey

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 3 replies on 1 page
rey

Posts: 10
Nickname: zerocoal
Registered: Sep, 2005

I would like to ask some help.... Posted: Sep 28, 2005 11:16 PM
Reply to this message Reply
Advertisement
Create a class named DateClass. It should contain three fields for the month, day and year. Create a two constructors. The first initializes the fields to any value that you want, and the second should accept three arguments, one for each field, the constructor then initializes the fields to these arguments. The class should also have a getDateString method that returns the specified date in MMMM dd yyyy format (i.e.Wednesday September 28, 2005). Be sure that invalid dates are not accepted, (i.e. Feb 29 2005). Lastly, include a method named isLeapYear which returns true if the date is a leap year, false otherwise.

My problem is on how to get the day of the week. Example, Wednesday September 28, 2005... thanks alot..
God bless you...


Kondwani Mkandawire

Posts: 530
Nickname: spike
Registered: Aug, 2004

Re: I would like to ask some help.... Posted: Sep 28, 2005 11:46 PM
Reply to this message Reply
public class DateClass{
   //  Or you can make these Strings
   //  Default constructor...
   int month, day, year;
   public DateClass(){
      month = 1;
      day = 1;
      year = 2005;
   }
   
   public DateClass(int month, int day, int year){
      this.month = month;
      if((month == 2)&&(day > 29)){
         //  do whatever validation you need for day
         //  in this case default to last Feb day
         //  may test for leap year -- check out
         //  www.kmatech.co.uk for possible verification
         //  algorithm - or an idea - don't kill my bandwidth
         //  though, coz its not a corporate website.  
         //  Though it does give the impression that it is.
         //  There is a section that says click HERE
         //  it has code of something similar in reverse thinking
         //  That would cater for leap years etc...
         this.day = 29;
      }else{
         this.day = day;
      }
      this.year = year;
   }
   
   public void setMonth(int month){
      this.month = month;
   }
   
   public int getMonth(){
      return this.month;
   }
   
   //  create Getters and setters for day and year...
   //  in effect this is what you call a Container Class
   //  You can set your attributes and retrieve values
   //  for the current object
}

Enjoy debugging whatever typos I've whipped in...
Oops, the payment hour has started, gotta jet...
Good luck...

Kondwani Mkandawire

Posts: 530
Nickname: spike
Registered: Aug, 2004

Re: I would like to ask some help.... Posted: Sep 28, 2005 11:50 PM
Reply to this message Reply
Sorry again, here's where you can get an idea to create
an algorithm for verification of leap year etc...

http://www.kmatech.co.uk/code/WeekReverseIterator.java

Once again, mind the bandwidth... Its not a corporate
site... (avoid Refreshes and Reloading)...

rey

Posts: 10
Nickname: zerocoal
Registered: Sep, 2005

thanks Posted: Sep 29, 2005 4:09 PM
Reply to this message Reply
Thanks alot of the codes and the site that you give to me..

More power! God bless you!

Flat View: This topic has 3 replies on 1 page
Topic: Text in a JFrame? Previous Topic   Next Topic Topic: Local variable:  null declaration

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use