Results 1 to 5 of 5
  1. #1
    anniedee is offline Member
    Join Date
    Aug 2013
    Posts
    2
    Rep Power
    0

    Default object class help

    need help understanding how to connect these two files

    word from instructor:
    You need to create an object of the class Date:

    Date d = new Date();

    and connect it back to the method isLeapYear().

    Date Java file:

    Java Code:
    public class Date
    {
    		public int dayIs(int day)
    		{
    			return day;
    		}
    		public int monthIs(int month)
    		{
    			return month;
    		}
    		public int yearIs(int year)
    		{
    			return year;
    		}
    
    	public boolean isLeapYear(int year)
    		{
    		if (year % 4 != 0)
    		{
    			return false;
    		}
    		else if (year % 400 == 0)
    		{
    			return false;
    		}
    		else if (year % 100 == 0)
    		{
    			return false;
    		}
    		else
    		{
    			return true;
    		}
    	}
    
    public Date(int day, int month, int year)
    {}
    }
    DateJDialog file:

    Java Code:
    import javax.swing.JOptionPane;
    
    public class DateJDialog
     {
     	public static void main(String[] args)
     	{
    		Date d = new Date();
    
    		int day; String dayStr = JOptionPane.showInputDialog(null, "Enter a day");
     		day = Integer.parseInt( dayStr );
    
     		int month; String monthStr = JOptionPane.showInputDialog(null, "Enter a month");
     		month = Integer.parseInt( monthStr);
    
     		int year; String yearStr = JOptionPane.showInputDialog(null, "Enter a year");
     		year = Integer.parseInt( yearStr );
    
     		if (d.isLeapYear( day, month, year ))
     		{
    			JOptionPane.showMessageDialog(null, "The date entered is a Leap Year!");
    		}
    		else
    		{
    			JOptionPane.showMessageDialog(null, "The date entered is NOT a Leap Year!");
    		}
    	}
    }
    Last edited by anniedee; 08-05-2013 at 04:30 AM.

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,458
    Rep Power
    20

    Default Re: object class help

    Forum Rules -- particularly the third paragraph
    Guide For New Members
    BB Code List - Java Programming Forum - Learn Java Programming

    Read those and edit your post accordingly.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  3. #3
    anniedee is offline Member
    Join Date
    Aug 2013
    Posts
    2
    Rep Power
    0

    Default Re: object class help

    thnx

  4. #4
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,458
    Rep Power
    20

    Default Re: object class help

    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  5. #5
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,771
    Blog Entries
    7
    Rep Power
    21

    Default Re: object class help

    Your isLeapYear( ... ) method is incorrect, e.g. the 2000 was a leap year ...

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

Similar Threads

  1. Replies: 3
    Last Post: 05-02-2011, 05:37 AM
  2. Replies: 1
    Last Post: 02-02-2011, 07:11 PM
  3. Replies: 2
    Last Post: 06-22-2010, 05:29 AM
  4. Replies: 3
    Last Post: 03-15-2010, 09:44 PM
  5. Creating object of Type Object class
    By venkatv in forum New To Java
    Replies: 3
    Last Post: 07-17-2007, 04:33 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •