Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixed #62 problem with entering date after 24th december. #89

Open
wants to merge 2 commits into
base: exercises/java-api/03
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 27 additions & 3 deletions Exercise.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,30 @@
public class Exercise {

public static void main(String[] args) {
// implement exercise here
}
public static void main(String[] args) {
@SuppressWarnings("resource")
Scanner sc = new Scanner(System.in);

System.out.print("Gib bitte ein Datum ein (dd.mm.yyyy): ");
String input = sc.next();

int day = Integer.valueOf(input.substring(0, 2));
int month = Integer.valueOf(input.substring(3, 5));
int year = Integer.valueOf(input.substring(6, 10));

LocalDate inputDate = LocalDate.of(year, month, day);
LocalDate christmas;

System.out.println("Wochentag: " + inputDate.getDayOfWeek());

if (day <= 24 || month < 12) {
christmas = LocalDate.of(year, 12, 24);
int daysUntilChristmas = christmas.getDayOfYear() - inputDate.getDayOfYear();
System.out.printf("Tage bis Weihnachte: %d%n", daysUntilChristmas);
} else {
christmas = LocalDate.of(year + 1, 12, 24);
int daysUntilNewYear = LocalDate.of(year,12,31).getDayOfYear() - inputDate.getDayOfYear();
int daysUntilNextYearsChristmas = daysUntilNewYear + christmas.getDayOfYear();
System.out.printf("Tage bis Weihnachten: %d%n",daysUntilNextYearsChristmas);
}
}
}