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

Слайд 2

Home Tasks How old are you in days and months? What

Home Tasks

How old are you in days and months? What day

of week is your birthday?
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%81%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

*

Victor Mozharsky

Слайд 3

Home Task I How old are you in days and months?

Home Task I

How old are you in days and months?
What

day of week is your birthday?

*

Victor Mozharsky

Слайд 4

Home Task I public static void main(String[] args){ LocalDate currDate =

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);

*

Victor Mozharsky

Слайд 5

Home Task I long amount = myBirthDate.until(currDate, ChronoUnit.DAYS); System.out.println("I have "

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));
}
}

*

Victor Mozharsky

Слайд 6

Home Task I See 33a4MyBirthDate project for the full text * Victor Mozharsky

Home Task I

See 33a4MyBirthDate project for the full text

*

Victor Mozharsky

Слайд 7

Home Task II Calculate Orthodox Easter and Trinity dates for the current decade * Victor Mozharsky

Home Task II

Calculate Orthodox Easter and Trinity dates for the current

decade

*

Victor Mozharsky

Слайд 8

Home Task II Для определения даты Православной пасхи по старому стилю

Home Task II

Для определения даты Православной пасхи по старому стилю необходимо:
Разделить

номер года на 19 и определить остаток от деления a.
Разделить номер года на 4 и определить остаток от деления b.
Разделить номер года на 7 и определить остаток от деления c.
Разделить сумму 19a + 15 на 30 и определить остаток d.
Разделить сумму 2b + 4c + 6d + 6 на 7 и определить остаток e.
Определить сумму f = d + e.
Если f ≤ 9, то Пасха будет праздноваться 22 + f марта; если f > 9, то Пасха будет праздноваться f — 9 апреля.

*

Victor Mozharsky

Слайд 9

Home Task II. getEasterAndTrinity public static LocalDate[] getEasterAndTrinity(int year){ LocalDate[] ret

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;

*

Victor Mozharsky

Слайд 10

Home Task II. getEasterAndTrinity LocalDate easter = null; if (f }

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;
}

*

Victor Mozharsky

Слайд 11

Home Task II. Main Method public static void main(String[] args) {

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);
}
}

*

Victor Mozharsky