-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPerson.java
144 lines (121 loc) · 3.97 KB
/
Person.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
package JAVA_Project_student.src;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
abstract class Human{
public abstract int getAge();
public abstract String getaddress() ;
public abstract String getfirstname();
public abstract String getlastname();
public abstract String getPhone_no();
public abstract String getEmail();
public abstract String getBlood_group() ;
}
class Person extends Human {
// name ,address ,phone no,email(auto), age,dob,blood grp, pass(auto)
//constructor
//getter and setter
public String firstname;
public String lastname;
private String address;
private String phone_no;
private String email;
private String blood_group;
private int age;
private int Defaultpasswordlength=10;
private String password;
public Person( String firstname, String lastname, String address, String phone_no, String email, String blood_group, int age ,String password) {
// this.firstname = firstname;
// this.lastname = lastname;
setName(firstname, lastname);
this.address = address;
//this.phone_no = phone_no;
setPhone_no(phone_no);
this.email=email;
this.blood_group= blood_group;
this.age= age;
setAge(age);
this.password = setpassword(Defaultpasswordlength);
}
Person(){}
public Person(String firstname, String lastname, int age) {
setAge(age);
setName(firstname, lastname);
}
public void setAge(int age){
if(age<18 || age>60) System.out.println("Age should be greater than 18");
else
this.age = age;
}
public int getAge(){
return age;
}
public void setAddress(String address){
this.address= address;
}
public String getaddress(){
return address;
}
public void setPhone_no(String phone_no){
if(phone_no.length()==10 && phone_no.matches("[0-9]+"))
this.phone_no=phone_no ;
else System.out.println("Please enter a valid phone number");
}
public String getfirstname(){
return firstname;
}
public String getlastname(){
return lastname;
}
public void setName(String firstname, String lastname){
if(firstname.matches("[a-zA-Z]+") && lastname.matches("[a-zA-Z]+")){
this.firstname = firstname;
this.lastname = lastname;
}
else{
System.out.println("ENTER A VALID NAME");
}
}
public void setEmail(String email) {
try {
if (email.length() < 5)
this.email = null;
String regex = "^[A-Za-z0-9+_.-]+@(.+)$"; // email validation
Pattern pattern = Pattern.compile(regex);
Matcher matcher = pattern.matcher(email);
if (matcher.matches())
this.email = email;
else
System.out.println("\nInvalid email passed!");
} catch (NullPointerException e) {
System.out.println("\nEmail cannot be null");
}
}
public String getPhone_no() {
return this.phone_no;
}
public String getEmail() {
return this.email;
}
public String getBlood_group() {
return this.blood_group;
}
public void setBlood_group(String blood_group) {
if(blood_group.length()==0){
System.out.println("Blood group cannot be null ");
}
this.blood_group = blood_group;
}
public String setpassword(int length) {
String passwordset = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*";
char[] password = new char[length];
for(int i=0;i<length;i++){
int rand = (int) (Math.random() * passwordset.length());
password[i] = passwordset.charAt(rand);
}
return new String (password);
}
public String getPassword() {
System.out.println("Your password for workEmail is :" + password);
return this.password;
}
}