- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEmail.java
More file actions
Latest commit
184 lines (159 loc) · 6.48 KB
/
Copy pathEmail.java
File metadata and controls
184 lines (159 loc) · 6.48 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
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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
importjava.util.Random;
importjava.util.Scanner;
classEmailApp {
privateStringfirstName;
privateStringlastName;
privateStringdepartment;
privateStringalternateEmail;
privateStringemail;
privateStringcompanySuffix = "xyz.com";
privateintmailboxCapacity = 500;
privateintdefaultPasswordLength = 10;
privatechar[] password;
// Constructor for first and last name
publicEmailApp(StringfirstName, StringlastName) {
this.firstName = firstName;
this.lastName = lastName;
System.out.println("NEW EMPLOYEE: " + this.firstName + " " + this.lastName);
// Method for calling department
this.department = setDepartment();
System.out.println("Your Department is: " + this.department);
// Call method for random password
this.password = generatePassword(defaultPasswordLength);
System.out.println("Your password is: " + newString(this.password));
// Combining email
email = firstName.toLowerCase() + "." + lastName.toLowerCase() + "@" + department.toLowerCase() + "." + companySuffix;
System.out.println("Your Email is: " + email);
}
// Method for asking department
privateStringsetDepartment() {
System.out.println("Department Codes: \n1. Sales \n2. Development \n3. Accounts \nEnter your Department:");
Scannerread = newScanner(System.in);
intdepChoice = read.nextInt();
if (depChoice == 1) {
return"sales";
} elseif (depChoice == 2) {
return"development";
} elseif (depChoice == 3) {
return"accounts";
} else {
return"none";
}
}
// Generate random password
privatechar[] generatePassword(intlen) {
StringcapitalChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
StringsmallChars = "abcdefghijklmnopqrstuvwxyz";
Stringnumbers = "0123456789";
Stringvalues = capitalChars + smallChars + numbers;
Randomrandom = newRandom();
char[] password = newchar[len];
for (inti = 0; i < len; i++) {
password[i] = values.charAt(random.nextInt(values.length()));
}
returnpassword;
}
// Set mailbox capacity
publicvoidsetMailboxCapacity(intcapacity) {
this.mailboxCapacity = capacity;
}
// Set the alternate email
publicvoidsetAlternateEmail(StringaltEmail) {
this.alternateEmail = altEmail;
}
// Change the password
publicvoidsetPassword(Stringpassword) {
this.password = password.toCharArray();
}
// Change department
publicvoidchangeDepartment(StringnewDepartment) {
this.department = newDepartment;
this.email = firstName.toLowerCase() + "." + lastName.toLowerCase() + "@" + department.toLowerCase() + "." + companySuffix;
}
// Get mailbox capacity
publicintgetMailboxCapacity() {
returnmailboxCapacity;
}
// Get the alternate email
publicStringgetAlternateEmail() {
returnalternateEmail;
}
// Get the password
publicStringgetPassword() {
returnnewString(password);
}
// Display employee information
publicStringshowInfo() {
return"\nDISPLAY NAME: " + firstName + " " + lastName +
"\nCOMPANY EMAIL: " + email +
"\nMAILBOX CAPACITY: " + mailboxCapacity + "mb";
}
// Display all employee details
publicStringdisplayAllDetails() {
returnshowInfo() +
"\nALTERNATE EMAIL: " + (alternateEmail != null ? alternateEmail : "Not Set") +
"\nPASSWORD: " + newString(password);
}
}
// Main Method
publicclassEmail {
publicstaticvoidmain(String[] args) {
Scannerscanner = newScanner(System.in);
// Get employee's first and last name
System.out.print("Enter first name: ");
StringfirstName = scanner.nextLine();
System.out.print("Enter last name: ");
StringlastName = scanner.nextLine();
EmailAppem1 = newEmailApp(firstName, lastName);
// Admin Actions Menu
while (true) {
System.out.println("\n--- Admin Actions ---");
System.out.println("1. Set Alternate Email");
System.out.println("2. Set Mailbox Capacity");
System.out.println("3. Change Department");
System.out.println("4. Reset Password");
System.out.println("5. Display All Details");
System.out.println("6. Exit");
System.out.print("Choose an option: ");
intchoice = scanner.nextInt();
scanner.nextLine(); // Consume newline
switch (choice) {
case1:
System.out.print("Enter alternate email: ");
StringaltEmail = scanner.nextLine();
em1.setAlternateEmail(altEmail);
System.out.println("Alternate Email Set: " + em1.getAlternateEmail());
break;
case2:
System.out.print("Enter new mailbox capacity: ");
intcapacity = scanner.nextInt();
em1.setMailboxCapacity(capacity);
System.out.println("Mailbox Capacity Updated: " + em1.getMailboxCapacity() + "mb");
break;
case3:
System.out.print("Enter new department: ");
StringnewDepartment = scanner.nextLine();
em1.changeDepartment(newDepartment);
System.out.println("Department changed successfully to " + newDepartment);
System.out.println("Your new email is: " + em1.showInfo());
break;
case4:
System.out.print("Enter new password: ");
StringnewPassword = scanner.nextLine();
em1.setPassword(newPassword);
System.out.println("Password Updated: " + em1.getPassword());
break;
case5:
System.out.println("\n--- Displaying All Details ---");
System.out.println(em1.displayAllDetails());
break;
case6:
System.out.println("Exiting Admin Actions.");
System.exit(0);
break;
default:
System.out.println("Invalid option. Please try again.");
}
}
}
}