-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEmail.java
More file actions
82 lines (73 loc) · 3.2 KB
/
Email.java
File metadata and controls
82 lines (73 loc) · 3.2 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
import java.util.Scanner;
public class Email {
//yaha se object creation hoga
private String firstName;
private String lastName;
private String password;
private int defaultPasswordLength = 10;
private String department;
private String email;
private int mailboxCapacity = 500;
private String companySuffix = "mycompany.com";
private String alternateEmail;
// constructor to recieve the first name and last name
public Email(String firstName, String lastName){
// this refers to the class level variable
// this(class level) = local level
this.firstName = firstName;
this.lastName = lastName;
// System.out.println("EMAIL CREATED: "+this.firstName+" "+this.lastName);
// call a method to ask for department and then return the department
this.department = setDepartment();
// System.out.println("Department is "+this.department);
// call a method to generate a random password
this.password = randomPassword(defaultPasswordLength);
// System.out.println("Your Password is "+this.password);
//combine elements to form the email
email = firstName.toLowerCase() + "." + lastName.toLowerCase() + "@" + this.department +"." + this.companySuffix;
// System.out.println("Your email is: "+email);
System.out.println("Email Succesfully Created\n\n\n");
}
// ask for the department (setter method for department)
private String setDepartment(){
System.out.print("DEPARTMENT CODES:\n1.For Sales\n2.For Development\n3.For Accounting\n0.For None\nEnter the Department Code:");
Scanner scn = new Scanner(System.in);
int depChoice = scn.nextInt();
if(depChoice == 1) return "sales";
else if(depChoice == 2) return "dev";
else if(depChoice == 3) return "acct";
else return "";
}
// random password needs to be generated
private String randomPassword(int length){
String passwordSet = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ123456789!@#";
char [] password = new char[length];
for(int i=0;i<length;i++){
int random = (int) (Math.random() * passwordSet.length());
password[i] = passwordSet.charAt(random);
}
return new String(password);
}
// mailbox ki capacity set karni hai
public void setMailboxCapacity(int capacity){
this.mailboxCapacity = capacity;
}
// alt email set up karna hai
public void setAlternateEmail(String alternateEmail){
this.alternateEmail = alternateEmail;
}
// password manage karna hai
public void changePassword(String password){
this.password = password;
}
//getter methods
public int getMailboxCapacity() { return this.mailboxCapacity; }
public String getAlternateEmail() { return this.alternateEmail; }
public String getPassword() { return this.password; }
public String showInformation(){
return "Employee Name: " + this.firstName + " " + this.lastName + "\n" +
"Employee Email: "+ this.email + "\n" +
"Password: "+ this.password +"\n" +
"Mailbox Capacity: "+ this.mailboxCapacity +" Mb\n";
}
}