Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit d35fa8a

Browse files
Add files via upload
1 parent 036b01b commit d35fa8a

File tree

8 files changed

+158
-0
lines changed

8 files changed

+158
-0
lines changed

‎javaDate/bin/Q2/DateOfBirth.class‎

2.21 KB
Binary file not shown.
376 Bytes
Binary file not shown.
2.41 KB
Binary file not shown.
371 Bytes
Binary file not shown.

‎javaDate/src/Q2/DateOfBirth.java‎

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
package Q2;
2+
3+
import java.time.LocalDate;
4+
import java.time.Period;
5+
import java.time.format.DateTimeFormatter;
6+
import java.util.Scanner;
7+
8+
public class DateOfBirth {
9+
10+
11+
12+
public int DateOfBirth(String date)throws InvalidDateFormatException{
13+
14+
try {
15+
DateTimeFormatter dateTime = DateTimeFormatter.ofPattern("dd/MM/yyyy");
16+
17+
LocalDate localD = LocalDate.parse(date,dateTime);
18+
19+
LocalDate localD1 = LocalDate.now();
20+
21+
Period p = Period.between(localD, localD1);
22+
23+
if(p.getYears() > 0 || p.getMonths() > 0 || p.getDays() > 0) {
24+
25+
return p.getYears();
26+
27+
}else {
28+
29+
return -1;
30+
}
31+
}catch(Exception IDF) {
32+
33+
InvalidDateFormatException IDF1 = new InvalidDateFormatException("Invalid dte format");
34+
35+
throw IDF1;
36+
37+
}
38+
39+
}
40+
41+
public static void main(String[] args) throws InvalidDateFormatException{
42+
// TODO Auto-generated method stub
43+
44+
try {
45+
46+
Scanner sc = new Scanner(System.in);
47+
48+
System.out.println("Enter the Date Of Birth in Formate : dd/MM/yyyy");
49+
50+
String date = sc.next();
51+
52+
DateOfBirth dateOB = new DateOfBirth();
53+
54+
55+
int Age = dateOB.DateOfBirth(date);
56+
57+
if(Age < 0) {
58+
System.out.println("Date should not be in future");
59+
}else {
60+
System.out.println(Age);
61+
}
62+
}catch(InvalidDateFormatException IDFE) {
63+
64+
IDFE.printStackTrace();
65+
}
66+
67+
}
68+
69+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package Q2;
2+
3+
public class InvalidDateFormatException extends Exception{
4+
5+
public InvalidDateFormatException(String message) {
6+
7+
super(message);
8+
}
9+
10+
}
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
package javaDateQ1;
2+
3+
import java.time.LocalDate;
4+
import java.time.Period;
5+
import java.time.format.DateTimeFormatter;
6+
import java.util.Date;
7+
import java.util.Scanner;
8+
9+
10+
public class EmployeeBonus {
11+
12+
public double bonusGet(String date)throws InvalidAgeException{
13+
14+
DateTimeFormatter dateTime = DateTimeFormatter.ofPattern("dd/MM/yyyy");
15+
16+
LocalDate locaDate = LocalDate.parse(date,dateTime);
17+
18+
LocalDate locald1 = LocalDate.now();
19+
20+
Period p1 = Period.between(locaDate, locald1);
21+
22+
if(p1.getYears() < 1 && p1.getDays() >= 1 && p1.getMonths() >= 1) {
23+
24+
return 5000;
25+
26+
}else if(p1.getYears() > 1 && p1.getYears() < 2) {
27+
28+
return 8000;
29+
30+
}else if(p1.getYears() > 2) {
31+
32+
return 10000;
33+
34+
}else {
35+
36+
InvalidAgeException ia = new InvalidAgeException("Invalid Age....");
37+
throw ia;
38+
}
39+
40+
}
41+
42+
public static void main(String[] args) throws InvalidAgeException{
43+
44+
Scanner sc = new Scanner(System.in);
45+
46+
System.out.println("Enter the date of joining in : dd/MM/yyyy format");
47+
48+
String date = sc.next();
49+
50+
EmployeeBonus EB = new EmployeeBonus();
51+
52+
try {
53+
double bonus = EB.bonusGet(date);
54+
55+
System.out.println("Your Bonus is : "+" "+bonus);
56+
}catch(InvalidAgeException IA) {
57+
58+
InvalidAgeException Ia = new InvalidAgeException("Invalid Date Format");
59+
60+
Ia.printStackTrace();
61+
62+
63+
}catch(Exception EX) {
64+
65+
EX.printStackTrace();
66+
}
67+
68+
}
69+
70+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package javaDateQ1;
2+
3+
public class InvalidAgeException extends Exception{
4+
5+
public InvalidAgeException(String message) {
6+
super(message);
7+
}
8+
9+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /