Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6385485
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T02:54:21+00:00 2026-05-25T02:54:21+00:00

I’m new to Java and trying to learn it after having learn C, having

  • 0

I’m new to Java and trying to learn it after having learn C, having some trouble with the syntax. This is a code my professor gave me to look at and I can understand basically what it’s doing accept for the last section with [public boolean isAfter(Date b)]. Where did the Date b come from, and what is compareTo?

import java.util.Calendar;
import java.util.GregorianCalendar;

public class Date implements Proj1Constants {

    private static final int[] DAYS = { 0, 31, 29, 31, 30, 31, 30, 31, 31,
            30, 31, 30, 31 };
    private static final int LEAP_YEAR = 366;
    private static final int NON_LEAP_YEAR = 365;

    private final int month; // month (between 1 and 12)
    private final int day; // day (between 1 and DAYS[month])
    private final int year; // year



    /**
     * Constructor: default; returns today's date
     */
    // creates today's date as the date; obtaines it from Java library

    public Date() 

    {
        GregorianCalendar c = new GregorianCalendar();
        month = c.get(Calendar.MONTH)+1; //our month starts from 1
        day = c.get(Calendar.DAY_OF_MONTH);
        year = c.get(Calendar.YEAR);
    }



    /**
     * Constructor: Does bounds-checking to ensure object represents a valid
     * date
     *
     * @param m represents the month between 1 and 12
     * @param d represents the date between 1 and the corresponding number
     * from array DAYS
     * @param y represents the year
     * @exception RuntimeException
     * if the date is invalid
     */
    public Date(int m, int d, int y) 

        {
        if (!isValid(m, d, y))
            throw new RuntimeException("Invalid date");
        month = m;
        day = d;
        year = y;
    }


    /**
     * Constructor: Does bounds-checking to ensure string represents a valid
     * date
     *
     * @param sDate represents a date given in format mm-dd-yyyy
     * @exception RuntimeException if the date is invalid
     */

    public Date(String sDate)

        {
        int m, d, y;
        String[] chopDate = sDate.split("-");
        m = Integer.parseInt(chopDate[ZEROI]);
        d = Integer.parseInt(chopDate[ONEI]);
        y = Integer.parseInt(chopDate[TWOI]);
        if (!isValid(m, d, y))
            throw new RuntimeException("Invalid date");
        month = m;
        day = d;
        year = y;
    }


    /**
     * constructor: creates a date with a given year; fills in valid month and day;
     * as december 31st.
     *
     * @param y represents a date given in year as integer
     */


    public Date(int y) 

        {

        month = 12;
        day = DAYS[12];
        year = y;
    }


    /**
     * create a date with a given month and year; fills in valid day;
     *
     * @param m represents the month between 1 and 12
     * @param y represents the year
     * @exception RuntimeException if the date is invalid
     */

    public Date(int m, int y) 

    {

        if (!isValid(m, DAYS[m], y))
            throw new RuntimeException("Invalid date; correct input");
        month = m;
        day = DAYS[m];
        year = y;
    }


    /**
     * Is the given date valid?
     *
     * @param month, day, and year
     * @return false if month exceeds 12 or is less than 1
     * @return false if day exceeds the corresponding days for a month from
     * array DAYS
     * @return false if the year is not a leap year and has 29 days
     */

    private static boolean isValid(int m, int d, int y) 

    {
        if (m < 1 || m > 12)
            return false;
        if (d < 1 || d > DAYS[m])
            return false;
        if (m == 2 && d == 29 && !isLeapYear(y))
            return false;
        return true;
    }


    /**
     * is y a leap year?
     *
     * @param y
     * represents the year specified
     * @return true if year divisible by 400
     * @return false if year divisible by 100 and not by 400
     */

    private static boolean isLeapYear(int y) 

    {
        if (y % 400 == 0)
            return true;
        if (y % 100 == 0)
            return false;
        return (y % 4 == 0);
    }


    /**
     * is (m, y) a leap month?
     *
     * @param m represents the month specified
     * @param y represents the year specified
     * @return true if it is a leap month
     * @return false otherwise
     */

    private static boolean isLeapMonth(int m, int y) 
    {
        if (isLeapYear(y)) return ((m == 2) ? true : false);
        return false;
    }


    // return the next Date
    /**
     * adds a day and returns a new Date object
     *
     * @return returns a new Date object adding a day
     */

    public Date next() 

    {
        if (isValid(month, day + 1, year))
            return new Date(month, day + 1, year);
        else if (isValid(month + 1, 1, year))
            return new Date(month + 1, 1, year);
        else
            return new Date(1, 1, year + 1);
    }


    // is this Date after b?
    /**
     * compares two Date objects
     *
     * @param b Date object
     * @return true if this Date is after Date b
     */

    public boolean isAfter(Date b)

    {
        return compareTo(b) > 0;
    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T02:54:21+00:00Added an answer on May 25, 2026 at 2:54 am

    isAfter is an instance method that takes on argument, a Date, the reference to which is b in the scope of the function.

    If that is the complete code, it is not valid, because the method compareTo is not defined anywhere.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I have some data like this: 1 2 3 4 5 9 2 6
I'm having trouble keeping the paragraph square between the quote marks. In firefox the
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
I have just tried to save a simple *.rtf file with some websites and
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.