-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEmail.java
More file actions
134 lines (116 loc) · 3.79 KB
/
Email.java
File metadata and controls
134 lines (116 loc) · 3.79 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
package emailapp;
import java.util.Scanner;
import java.util.Random;
public class Email{
public Scanner s = new Scanner(System.in);
// Setting up the variables
// Defined as 'private' so that these cannot be accessed directly
private String fname;
private String lname;
private String dept;
private String email;
private String password;
private int mailCapacity = 60;
private String alter_email;
// Constructor to receive the first name and the last name
public Email(String fname, String lname) {
this.fname = fname;
this.lname = lname;
System.out.println("\nNEW EMPLOYEE: " + this.fname + " " + this.lname);
// Call a method asking for the department - return the department
this.dept = this.setDept();
// Call a method that returns a random password
this.password = this.generate_password(8);
// Combine elements to generate an email
this.email = this.generate_email();
}
// Generating the email according to the given syntax
private String generate_email() {
return this.fname.toLowerCase() + "." + this.lname.toLowerCase() + "@" + this.dept.toLowerCase()
+ ".company.com";
}
// Ask for the department
private String setDept() {
System.out.println(
"\nDEPARTMENT CODES\n\n1 for Sales\n2 for Development\n3 for Accounting\n0 for None");
boolean flag = false;
do {
System.out.print("\nEnter Department Code: ");
int choice = s.nextInt();
switch (choice) {
case 1:
return "Sales";
case 2:
return "Development";
case 3:
return "Accounting";
case 0:
return "None";
default:
System.out.println("***INVALID CHOICE***");
}
} while (!flag);
return null;
}
// Generating a random password
private String generate_password(int length) {
Random r = new Random();
String Capital_chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
String Small_chars = "abcdefghijklmnopqrstuvwxyz";
String numbers = "0123456789";
String symbols = "!@#$%&?";
String values = Capital_chars + Small_chars + numbers + symbols;
String password = "";
for (int i = 0; i < length; i++) {
password = password + values.charAt(r.nextInt(values.length()));
}
return password;
}
// Change the password
public void set_password() {
boolean flag = false;
do {
System.out.print("ARE YOU SURE YOU WANT TO CHANGE YOUR PASSWORD? (Y/N) : ");
char choice = s.next().charAt(0);
if (choice == 'Y' || choice == 'y') {
flag = true;
System.out.print("Enter current password: ");
String temp = s.next();
if (temp.equals(this.password)) {
System.out.println("Enter new password: ");
this.password = s.next();
System.out.println("PASSWORD CHANGED SUCCESSFULLY!");
} else {
System.out.println("Incorrect Password!");
}
} else if (choice == 'N' || choice == 'n') {
flag = true;
System.out.println("PASSWORD CHANGE CANCELED!");
} else {
System.out.println("***ENTER A VALID CHOICE***");
}
} while (!flag);
}
// Set the mailbox capacity
public void set_mailCap() {
System.out.println("Current capacity = " + this.mailCapacity + "GB");
System.out.print("Enter new capacity: ");
this.mailCapacity = s.nextInt();
System.out.println("MAILBOX CAPACITY CHANGED SUCCESSFULLY!");
}
// Set the alternate email
public void alternate_email() {
System.out.print("Enter new alternate email: ");
this.alter_email = s.next();
System.out.println("ALTERNATE EMAIL SET SUCCESSFULLY!");
}
// Displaying the employee's information
public void getInfo() {
System.out.println("NAME: " + this.fname + " " + this.lname);
System.out.println("DEPARTMENT: " + this.dept);
System.out.println("EMAIL: " + this.email);
System.out.println("PASSWORD: " + this.password);
System.out.println("MAILBOX CAPACITY: " + this.mailCapacity +" "+ "GB");
System.out.println("ALTER EMAIL: " + this.alter_email);
}
}