Skip to content

Commit f101f1e

Browse files
committed
updated files
1 parent c51bf2c commit f101f1e

File tree

13 files changed

+486
-0
lines changed

13 files changed

+486
-0
lines changed

.gitignore

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
target/
2+
!.mvn/wrapper/maven-wrapper.jar
3+
!**/src/main/**/target/
4+
!**/src/test/**/target/
5+
6+
### IntelliJ IDEA ###
7+
.idea/modules.xml
8+
.idea/jarRepositories.xml
9+
.idea/compiler.xml
10+
.idea/libraries/
11+
*.iws
12+
*.iml
13+
*.ipr
14+
15+
### Eclipse ###
16+
.apt_generated
17+
.classpath
18+
.factorypath
19+
.project
20+
.settings
21+
.springBeans
22+
.sts4-cache
23+
24+
### NetBeans ###
25+
/nbproject/private/
26+
/nbbuild/
27+
/dist/
28+
/nbdist/
29+
/.nb-gradle/
30+
build/
31+
!**/src/main/**/build/
32+
!**/src/test/**/build/
33+
34+
### VS Code ###
35+
.vscode/
36+
37+
### Mac OS ###
38+
.DS_Store

.idea/.gitignore

+8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/aws.xml

+11
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/encodings.xml

+7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/misc.xml

+14
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/uiDesigner.xml

+124
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/vcs.xml

+6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pom.xml

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
7+
<groupId>org.example</groupId>
8+
<artifactId>daysofthemonth</artifactId>
9+
<version>1.0-SNAPSHOT</version>
10+
11+
<properties>
12+
<maven.compiler.source>11</maven.compiler.source>
13+
<maven.compiler.target>11</maven.compiler.target>
14+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
15+
</properties>
16+
17+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
package org.javatasks.agecomparism;
2+
3+
import java.util.Scanner;
4+
5+
6+
7+
8+
9+
public class AgeComparison {
10+
public static void main(String[] args) {
11+
Person person1 = FillPerson();
12+
Person person2 = FillPerson();
13+
14+
whoIsOlder(person1, person2);
15+
}
16+
17+
public static Person FillPerson() {
18+
Scanner scanner = new Scanner(System.in);
19+
20+
System.out.print("Enter the person's name: ");
21+
String name = scanner.nextLine();
22+
23+
System.out.print("Enter the birth year (e.g., 1990): ");
24+
int year = scanner.nextInt();
25+
26+
System.out.print("Enter the birth month (1-12): ");
27+
int month = scanner.nextInt();
28+
29+
System.out.print("Enter the birth day (1-31): ");
30+
int day = scanner.nextInt();
31+
32+
Date birthday = new Date(year, month, day);
33+
34+
return new Person(name, birthday);
35+
}
36+
37+
public static void writePerson(Person person) {
38+
String[] monthNames = {
39+
"January", "February", "March", "April", "May", "June",
40+
"July", "August", "September", "October", "November", "December"
41+
};
42+
43+
System.out.println("Name: " + person.name);
44+
System.out.println("Birthday: " + monthNames[person.birthday.month - 1] + " " + person.birthday.day + ", " + person.birthday.year);
45+
}
46+
47+
public static void whoIsOlder(Person person1, Person person2) {
48+
int yearDifference = person1.birthday.year - person2.birthday.year;
49+
50+
if (yearDifference < 0) {
51+
System.out.println(person1.name + " is younger than " + person2.name + " by " + (-yearDifference) + " years.");
52+
} else if (yearDifference > 0) {
53+
System.out.println(person1.name + " is older than " + person2.name + " by " + yearDifference + " years.");
54+
} else {
55+
int monthDifference = person1.birthday.month - person2.birthday.month;
56+
57+
if (monthDifference < 0) {
58+
System.out.println(person1.name + " is younger than " + person2.name + " by a few months.");
59+
} else if (monthDifference > 0) {
60+
System.out.println(person1.name + " is older than " + person2.name + " by a few months.");
61+
} else {
62+
int dayDifference = person1.birthday.day - person2.birthday.day;
63+
64+
if (dayDifference < 0) {
65+
System.out.println(person1.name + " is younger than " + person2.name + " by a few days.");
66+
} else if (dayDifference > 0) {
67+
System.out.println(person1.name + " is older than " + person2.name + " by a few days.");
68+
} else {
69+
System.out.println(person1.name + " and " + person2.name + " have the same birthday.");
70+
}
71+
}
72+
}
73+
74+
System.out.println("org.javatasks.agecomparism.Person 1:");
75+
writePerson(person1);
76+
77+
System.out.println("org.javatasks.agecomparism.Person 2:");
78+
writePerson(person2);
79+
}
80+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package org.javatasks.agecomparism;
2+
3+
4+
public class Date {
5+
int year;
6+
int month;
7+
int day;
8+
9+
Date(int year, int month, int day) {
10+
this.year = year;
11+
this.month = month;
12+
this.day = day;
13+
}
14+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package org.javatasks.agecomparism;
2+
3+
public class Person {
4+
String name;
5+
Date birthday;
6+
7+
Person(String name, Date birthday) {
8+
this.name = name;
9+
this.birthday = birthday;
10+
}
11+
}

0 commit comments

Comments
 (0)