-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBasicIO.java
More file actions
71 lines (61 loc) · 2.42 KB
/
BasicIO.java
File metadata and controls
71 lines (61 loc) · 2.42 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
67
68
69
70
71
/*
╭────────────────────────────────────────────────────╮
│ ╵
│ File: BasicIO.java
│ Project: FirstProject
│
│ Created by Everett Wilber on 21/09/09 at 11:30 AM.
│ ╷
╰────────────────────────────────────────────────────╯
*/
import java.text.DateFormat;
import java.text.DateFormatSymbols;
import java.time.chrono.ChronoLocalDate;
import java.time.temporal.ChronoUnit;
import java.time.temporal.TemporalField;
import java.util.*;
import java.time.*;
public class BasicIO {
public static void main(String[] args) {
// get time zone
ZoneId defaultZoneId = ZoneId.systemDefault();
// call vars
double age = 0;
Scanner input = new Scanner(System.in);
//ask name
System.out.println("Enter UR nam!");
String name = input.nextLine();
System.out.println(name);
//ask birthday
LocalDate birthday = LocalDate.now();
//year
System.out.println("What is your birth year?");
int year = input.nextInt();
birthday = birthday.withYear(year);
//month
System.out.println("What is your birth month?");
int month = input.nextInt();
// is month valid
while ((month > 12 || month < 1)) {
System.out.println("Try a number from 1-12");
month = input.nextInt();
}
birthday = birthday.withMonth(month);
//day
YearMonth birthMonth = YearMonth.of(year, month);
System.out.println("What *day* of your birth month?");
int day = 999999;
// is month valid
while (!birthMonth.isValidDay(day)) {
day = input.nextInt();
}
birthday = birthday.withDayOfMonth(day);
//yearsSince
int yearsSinceBday = Math.toIntExact(ChronoUnit.YEARS.between(birthday, LocalDate.now()));
System.out.println("There are "+yearsSinceBday+" years since your birthday");
//daysAlive
int daysAlive = Math.toIntExact(ChronoUnit.DAYS.between(birthday, LocalDate.now()));
System.out.println("You have been alive "+daysAlive+" days!");
input.close();
}
}