[Release] How Many Day sOld you are

Junior Spellweaver
Joined
Mar 24, 2009
Messages
173
Reaction score
18
Again, these are for optimal GM events to save time


PHP:
public class Age {

	private static final int MONTH = 3, DAY = 26, YEAR = 2009;

	private static int getYear(int year, int month, int day) {
		if (month > MONTH || (month == MONTH && day < DAY))
			return YEAR - 1 - year;
		return YEAR - year;
	}

	private static int getMonth(int month, int day) {
		if (month > MONTH) {
			if (day >= DAY)
				return 12 - month + MONTH;
			return 11 - month + MONTH;
		} else if (month == MONTH && day < DAY) {
			if (month - MONTH < 1)
				return (11 - month + MONTH) % 12;
			return 11 - month + MONTH;
		}
		return MONTH - month;
	}

	private static int getDay(int month, int day) {
		if (month == 4 || month == 6 || month == 9 || month == 11) {
			if (day >= DAY)
				return day - DAY;
			return 30 - DAY + day;
		}
		if (month == 2) {
			if (day > DAY)
				return day - DAY;
			else if (YEAR % 4 == 0 && YEAR % 400 != 0)
				return (29 - day + DAY) % 29;
			else
				return (28 - DAY + day) % 28;
		}
		if (day >= DAY)
			return day - DAY;
		return 31 - DAY + day;
	}

	private static void solve(int month, int day, int year) {
		System.out.println("Date: " + month + "/" + day + "/" + year);
		System.out.println("Years: " + getYear(year, month, day));
		System.out.println("Months: " + getMonth(month, day));
		System.out.println("Days: " + getDay(month, day));
		System.out.println();
	}

	public static void main(String[] args) {
		solve(9, 1, 1989);
	}

}

This was made for Osiris because he needed C help. I made this in Java to aid him.


I did this a loooooooong time ago. This translates seconds into years/etc
PHP:
/**
 * 
 * @author Administrator
 */
public class Years {

	/**
	 * Creates variables centuries, years, days, hours, minutes, and seconds.
	 */
	private int centuries, years, days, hours, minutes, seconds;

	/**
	 * Creates variables for default values for years in centuries, days in
	 * years, hours in days, minutes in hours, seconds in minutes.
	 */
	private int yearsDefault = **** daysDefault = 365, hoursDefault = 24,
			minutesDefault = 60, secondsDefault = 60;

	/**
	 * Creates an instance of years. Seconds is how many seconds to calculate.
	 * Counter is how fast 1 second is in another unit. i.e. .5 seconds in
	 * MoograLand is 1 second on Earth.
	 * 
	 * @param seconds
	 * @param counter
	 */
	public Years(int seconds, double counter) {
		this.seconds = (int) (seconds * counter);
	}

	/**
	 * Creates a more advanced version of Years(int, double). This takes in default values.
	 * 
	 * @param seconds
	 * @param counter
	 * @param yearsDefault
	 * @param daysDefault
	 * @param hoursDefault
	 * @param minutesDefault
	 * @param secondsDefault
	 */
	public Years(int seconds, double counter, int yearsDefault,
			int daysDefault, int hoursDefault, int minutesDefault,
			int secondsDefault) {
		this.seconds = (int) (seconds * counter);
		this.yearsDefault = yearsDefault;
		this.daysDefault = daysDefault;
		this.hoursDefault = hoursDefault;
		this.minutesDefault = minutesDefault;
		this.secondsDefault = secondsDefault;
	}

	/**
	 * Gets how many minutes using seconds.
	 */
	private void getMinutes() {
		this.minutes = seconds / secondsDefault;
		if (minutes > 0)
			this.seconds -= minutes * secondsDefault;
	}

	/**
	 * Gets how many hours using minutes.
	 */
	private void getHours() {
		this.hours = minutes / minutesDefault;
		if (hours > 0)
			this.minutes -= hours * minutesDefault;
	}

	/**
	 * Gets how many days using hours.
	 */
	private void getDays() {
		this.days = hours / hoursDefault;
		if (days > 0)
			this.hours -= days * hoursDefault;
	}

	/**
	 * Gets how many years using days.
	 */
	private void getYears() {
		this.years = days / daysDefault;
		if (years > 0)
			this.days -= years * daysDefault;
	}

	/**
	 * Gets how many centuries using centuries.
	 */
	private void getCenturies() {
		this.centuries = years / yearsDefault;
		if (centuries > 0)
			this.years -= centuries / yearsDefault;
	}

	/**
	 * Calculates centuries, years, days, hours, minutes, and seconds and
	 * displays them nicely.
	 */
	public void calculate() {
		getMinutes();
		getHours();
		getDays();
		getYears();
		getCenturies();
		System.out.println("Centuries: " + centuries);
		System.out.println("Years: " + years);
		System.out.println("Days: " + days);
		System.out.println("Hours: " + hours);
		System.out.println("Minutes: " + minutes);
		System.out.println("Seconds: " + seconds);
	}
}
 
Uhm, can you clarify what...a console is...MS related. I'm not really the know-it-all type. :\
Code:
[U][SlutMS - All Server                           [ - ][ □ ] [ x ]][/U]
| Error: You slut is noob.                                     |
|Grave: Learn Java                                             |
|                                                              |
|                                                              |
|                                                              |
|                                                              |
|                                                              |
|______________________________________________________________|

That is, basically.
 
Back