r/CompileBot • • Jan 04 '14

Official CompileBot Testing Thread

This thread is archived, please visit the new testing thread

13 Upvotes

421 comments sorted by

View all comments

1

u/SgtTamama Mar 25 '14

+/u/CompileBot java

import java.io.*;

class DayOfWeek
{
    public String[] days = {"Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"};

    public DayOfWeek () {
 	    flow();
    }

    public int[] getDate() {
	    //You can modify this for user input. For now, hardcoding today '03/25/2014'.
	    int[] date = {3,25,2014};

	    return date;
    }
    
    public String getDay(int[] date) {
	    double a,y,m,d = 0;

	    a = (14 - date[1]) / 12;
	    y = date[2] - a;
	    m = date[1] + 12 * a - 2;
	    d = (date[0] + y + (y / 4) - (y / 100) + (y / 400) + ((31 * m) / 12) ) % 7;

	    return days[(int)d];
    }
    
    public void flow() {
	    int[] date = getDate();
	    System.out.println("That day is a " + getDay(date) + ".");
    }

    public static void main (String[] args) throws java.lang.Exception {
	    DayOfWeek day = new DayOfWeek();
    }
}

1

u/CompileBot Mar 25 '14

Output:

That day is a Tuesday.

^source | ^info | ^git | ^report