-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMenstrualApp.java
More file actions
66 lines (46 loc) · 2.41 KB
/
Copy pathMenstrualApp.java
File metadata and controls
66 lines (46 loc) · 2.41 KB
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
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.Scanner;
public class MenstrualApp {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
DateTimeFormatter dateFormat = DateTimeFormatter.ofPattern("yyyy-MM-dd");
System.out.print("Welcome to FlowMenstral App is your name? ");
String name = input.nextLine();
System.out.print("What is your age? ");
int age = input.nextInt();
input.nextLine();
System.out.print("Enter the last period start date (yyyy-MM-dd): ");
LocalDate lastPeriodStart = LocalDate.parse(input.nextLine(), dateFormat);
System.out.print("Enter the cycle length: ");
int cycleLength = input.nextInt();
input.nextLine();
System.out.print("Enter the period duration: ");
int periodDuration = input.nextInt();
LocalDate resultNextPeriod = checkNextPeriod(lastPeriodStart, cycleLength);
System.out.println("Next Period: " + resultNextPeriod);
LocalDate resultOvulationDay = checkOvulationDay(resultNextPeriod);
System.out.println("Ovulation Day: " + resultOvulationDay);
String resultFertilityWindow = checkFertilityWindow(resultOvulationDay, periodDuration);
System.out.println("Fertile Window: " + resultFertilityWindow);
LocalDate resultPeriodEnd = checkPeriodEnd(lastPeriodStart, periodDuration);
System.out.println("Expected Period End: " + resultPeriodEnd);
}
public static LocalDate checkNextPeriod(LocalDate lastPeriodStart, int cycleLength){
LocalDate nextPeriod = lastPeriodStart.plusDays(cycleLength);
return nextPeriod;
}
public static LocalDate checkOvulationDay(LocalDate resultNextPeriod){
LocalDate ovulationDay = resultNextPeriod.minusDays(14);
return ovulationDay;
}
public static String checkFertilityWindow(LocalDate resultOvulationDay, int periodDuration){
LocalDate fertileStart = resultOvulationDay.minusDays(periodDuration);
LocalDate fertileEnd = resultOvulationDay.plusDays(1);
return fertileStart + " to " + fertileEnd;
}
public static LocalDate checkPeriodEnd(LocalDate lastPeriodStart, int periodDuration){
LocalDate periodEnd = lastPeriodStart.plusDays(periodDuration - 1);
return periodEnd;
}
}