-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJulianDate.java
82 lines (71 loc) · 1.67 KB
/
JulianDate.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
/**
* This class takes any date and converts it to a Julian Date otherwise takes a
* Julian Date and converts it back to Gregorian.
*
* @author n-c0de-r
* @version 25.05.2021 update 23.06.2021
*
*/
public class JulianDate {
private int value;
/**
* Constructor of the class, takes dates and converts to a JulianDate number
*
* @param year Year of the given date
* @param month Month of the given date
* @param day Day of the given date
*/
public JulianDate (int year, int month, int day) {
//Using the formula from https://quasar.as.utexas.edu/BillInfo/JulianDatesG.html
int A = year/100;
int B = A/4;
int C = 2-A+B;
int E = (int) (365.25 * (year+4716));
int F = (int) (30.6001 * (month +1));
value = (int) (C+day+E+F-1524.5);
if (value%100 == 0) {
System.out.println("Your lifetime is divisible by 100!");
}
}
/**
* Constructor, if only days are entered.
* @param days Days lived as a julian day number.
*/
public JulianDate (int days) {
value = days;
}
/**
* Getter to return the JulianDate number.
* @return Integer value for that date.
*/
public int getNumber() {
return value;
}
/**
* Returns the day of the week for that specific date.
* @return String with the weekday.
*/
public String getWeekday() {
//Calculate day value for each weekday
int w =(value % 7)+1;
switch(w) {
case 0:
return "Monday";
case 1:
return "Tuesday";
case 2:
return "Wednesday";
case 3:
return "Thursday";
case 4:
return "Friday";
case 5:
return "Saturday";
case 6:
System.out.println("Your are a Sunday's Child! YAY!");
return "Sunday";
default:
return "Not a day!";
}
}
}