3. Essential Java Classes
Home Tasks
Home Task I
Home Task I
Home Task I
Home Task I
Home Task II
Home Task II
Home Task II. getEasterAndTrinity
Home Task II. getEasterAndTrinity
Home Task II. Main Method
Home Task II. Output
239.50K
Категория: ПрограммированиеПрограммирование

3. Essential Java Classes 3. Date and Time Home Tasks

1. 3. Essential Java Classes

3. Date and Time Home Tasks

2. Home Tasks

1. How old are you in days and months? What
day of week is your birthday?
2. Calculate Orthodox Easter and Trinity dates
for the current decade
http://ru.wikipedia.org/wiki/%D0%90%D0%BB%D0%B3%D0%BE%
D1%80%D0%B8%D1%82%D0%BC_%D0%93%D0%B0%D1%83%D1
%81%D1%81%D0%B0_%D0%B2%D1%8B%D1%87%D0%B8%D1%8
1%D0%BB%D0%B5%D0%BD%D0%B8%D1%8F_%D0%B4%D0%B0
%D1%82%D1%8B_%D0%9F%D0%B0%D1%81%D1%85%D0%B8
28.12.2016 4:18
Victor Mozharsky
2

3. Home Task I

• How old are you in days and months?
• What day of week is your birthday?
28.12.2016 4:18
Victor Mozharsky
3

4. Home Task I

public static void main(String[] args){
LocalDate currDate = LocalDate.now();
LocalDate myBirthDate = LocalDate.of(2012, 11, 25);
DateTimeFormatter formatter =
DateTimeFormatter.ofPattern("dd.MM.yyyy");
String txt = myBirthDate.format(formatter);
System.out.println("My birth date = " + txt);
28.12.2016 4:18
Victor Mozharsky
4

5. Home Task I

long amount = myBirthDate.until(currDate, ChronoUnit.DAYS);
System.out.println("I have " + amount + " days old");
amount = myBirthDate.until(currDate, ChronoUnit.MONTHS);
System.out.println("I have " + amount + " months old");
amount = myBirthDate.until(currDate, ChronoUnit.YEARS);
System.out.println("I have " + amount + " years old");
DayOfWeek dof = myBirthDate.getDayOfWeek();
Locale locale = new Locale("en");
System.out.println("I was born on " +
dof.getDisplayName(TextStyle.FULL, locale));
}
}
28.12.2016 4:18
Victor Mozharsky
5

6. Home Task I

• See 33a4MyBirthDate project for the full text
28.12.2016 4:18
Victor Mozharsky
6

7. Home Task II

• Calculate Orthodox Easter and Trinity dates for
the current decade
28.12.2016 4:18
Victor Mozharsky
7

8. Home Task II

Для определения даты Православной пасхи по
старому стилю необходимо:
1. Разделить номер года на 19 и определить остаток от
деления a.
2. Разделить номер года на 4 и определить остаток от
деления b.
3. Разделить номер года на 7 и определить остаток от
деления c.
4. Разделить сумму 19a + 15 на 30 и определить остаток d.
5. Разделить сумму 2b + 4c + 6d + 6 на 7 и определить
остаток e.
6. Определить сумму f = d + e.
7. Если f ≤ 9, то Пасха будет праздноваться 22 + f марта;
если f > 9, то Пасха будет праздноваться f — 9 апреля.
28.12.2016 4:18
Victor Mozharsky
8

9. Home Task II. getEasterAndTrinity

public static LocalDate[] getEasterAndTrinity(int year){
LocalDate[] ret = new LocalDate[2];
int a = year % 19;
int b = year % 4;
int c = year % 7;
int d = (19 * a + 15) % 30;
int e = (2 * b + 4 * c + 6 * d + 6) % 7;
int f = d + e;
28.12.2016 4:18
Victor Mozharsky
9

10. Home Task II. getEasterAndTrinity

LocalDate easter = null;
if (f <= 9) { easter = LocalDate.of(year, 3, 22 + f);
} else{ easter = LocalDate.of(year, 4, f - 9);
}
easter = easter.plusDays(13);
ret[0] = easter;
LocalDate trinity = easter.plusWeeks(7);
ret[1] = trinity;
return ret;
}
28.12.2016 4:18
Victor Mozharsky
10

11. Home Task II. Main Method

public static void main(String[] args) {
System.out.println(" Year
Easter Date Trinity Date");
DateTimeFormatter formatter =
DateTimeFormatter.ofPattern("dd.MM.yyyy");
for (int i = 2010; i < 2021; i++){
LocalDate[] dt = getEasterAndTrinity(i);
String easter = dt[0].format(formatter);
String trinity = dt[1].format(formatter);
System.out.format(" %1$4d
%2$10s %3$10s
%n", i, easter, trinity);
}
}
28.12.2016 4:18
Victor Mozharsky
11

12. Home Task II. Output

Year
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
28.12.2016 4:18
Easter Date
04.04.2010
24.04.2011
15.04.2012
05.05.2013
20.04.2014
12.04.2015
01.05.2016
16.04.2017
08.04.2018
28.04.2019
19.04.2020
Trinity Date
23.05.2010
12.06.2011
03.06.2012
23.06.2013
08.06.2014
31.05.2015
19.06.2016
04.06.2017
27.05.2018
16.06.2019
07.06.2020
Victor Mozharsky
12
English     Русский Правила