Demo entry 3913146

Boom

   

Submitted by Stephen on Mar 06, 2016 at 23:25
Language: Java. Code size: 1.3 kB.

package com.hfad.databasetest;

/**
 * Created by Stephen on 3/5/2016.
 */
public class Day {

    int month;
    int day;
    int year;
    public Day(int inputYear, int inputMonth, int inputDay){
        month = inputMonth;
        day = inputDay;
        year = inputYear;
    }

    public Day(){
        month = 0;
        day = 0;
        year = 0;
    }

    /**
     * Returns 1 if the input date is at a later date than itself.
     * Returns 0 if the input date is the same as itself
     * Returns -1 if the input data is at an earlier date than itself.
     * @param inputDay
     * @return
     */
    public int compareTo(Day inputDay){
        if(year != inputDay.year){
            if(year > inputDay.year) return 1;
            else if(year < inputDay.year) return -1;
        }
        else
        if(month != inputDay.month){
            if(month > inputDay.month) return 1;
            else if(month < inputDay.month) return -1;
        }
        else
        if(day != inputDay.day){
            if(day > inputDay.day) return 1;
            else if(day < inputDay.day) return -1;
            else return 0;
        }
        return 0;
    }

    public String toString(){
        String output = year + " " + month + " " + day;
        return output;
    }

}

This snippet took 0.01 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).