-
Notifications
You must be signed in to change notification settings - Fork 0
/
pr3.java
79 lines (77 loc) · 2 KB
/
pr3.java
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
72
73
74
75
76
77
78
79
import java.util.Scanner;
import java.util.*;
class UserDefined extends Exception
{
public UserDefined (String message)
{
super(message);
}
}
class UserData
{
private int age;
private double amount;
private String city;
private boolean hasfourwheeler;
public UserData(int age,double amount,String city,boolean hasfourwheeler)
{
this.age=age;
this.amount=amount;
this.city=city;
this.hasfourwheeler=hasfourwheeler;
}
public void checkdata() throws UserDefined
{
if(age<18 || age>55)
{
throw new UserDefined("Age is Should be between 18-55 ");
}
if(amount<50000||amount>100000)
{
throw new UserDefined("Salary should be between 50k-100k ");
}
if(!(city.equalsIgnoreCase("Pune")||city.equalsIgnoreCase("Mumbai")||city.equalsIgnoreCase("Banglore")||city.equalsIgnoreCase("Channai")))
{
throw new UserDefined("City should be Pune,Mumbai,Banglore or Channai.");
}
if(hasfourwheeler==false)
{
throw new UserDefined("User should have four wheeler.");
}
System.out.println("Checking done...");
}
}
class Main
{
public static void main(String args[])
{
Scanner sc = new Scanner(System.in);
try{
System.out.println("Enter the age : ");
int age = sc.nextInt();
System.out.println("Enter the Salary : ");
double amount = sc.nextDouble();
sc.nextLine();
System.out.println("Enter the name of City (First Letter should be Capital ) : ");
String city = sc.nextLine();
System.out.println("Do you have four wheeler (if yes enter true else false ) : ");
boolean hasfourwheeler = sc.nextBoolean();
sc.nextLine();
UserData obj = new UserData(age,amount,city,hasfourwheeler);
obj.checkdata();
System.out.println("Checking Done .... ");
}
catch(UserDefined e)
{
System.out.println("User Defined Exception : "+e.getMessage());
}
catch(Exception e)
{
System.out.println("ERROR : "+e.getMessage());
}
finally
{
sc.close();
}
}
}