-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathPerson.java
More file actions
65 lines (57 loc) · 1.53 KB
/
Person.java
File metadata and controls
65 lines (57 loc) · 1.53 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
import java.util.Scanner;
public class Person {
Scanner sc = new Scanner(System.in);
String name;
int age;
String sex;
long aadhar;
String address;
public Person(String n, int a, String sx, long aad, String addr )
{
name = n;
age = a;
sex = sx;
aadhar = aad;
address = addr;
}
public Person()
{
System.out.println("Enter Name:");
String n = sc.nextLine();
String numRegex = ".*[0-9].*";
while(n.matches(numRegex))
{
System.out.println("Name cannot contain number. \n Try again. \n");
n = sc.nextLine();
}
name = n;
System.out.println("Enter Age: ");
int a = Integer.parseInt(sc.nextLine());
while(a>85 || a<15)
{
System.out.println("Age cannot exceede 85 or be less than 15. \n Try again. \n");
a = Integer.parseInt(sc.nextLine());
}
age = a;
System.out.println("Enter Sex [F/M/X] : ");
String s = sc.nextLine() ;
while(!(s.equalsIgnoreCase("F")||s.equalsIgnoreCase("M")||s.equalsIgnoreCase("X")))
{
System.out.println("Invalid Entry. Enter F, M or X for Female, Male or Non-Binary. \n Try again. \n");
s = sc.nextLine();
}
sex = s;
System.out.println("Enter Aadhar: ");
String aadc = sc.nextLine();
String alphaRegex = ".*[A-Z].*";
while(aadc.matches(alphaRegex) || aadc.length()!=10)
{
System.out.println("Invalid Entry. Aadhar Number must be 10 digits with no alphabets. \n Try again. \n");
aadc = sc.nextLine();
}
aadhar = Long.parseLong(aadc);
System.out.println("Enter Adress: ");
String addr = sc.nextLine();
address = addr;
}
}