-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathemailapp
130 lines (67 loc) · 2.48 KB
/
emailapp
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
package com.demo;
import java.util.*;
public class Email {
private String firstname;
private String lastname;
private String password;
private String department;
private int mailboxCapacity = 100;
private String alternateEmail;
private String comName = "Google.com";
private String changePassword;
// Constructor to accept first name and last name
public Email(String firstname, String lastname) {
this.firstname = firstname;
this.lastname = lastname;
System.out.println("Email account created for: " + this.firstname +" " + this.lastname);
//call the method for the department setup
this.department = setDepartment();
System.out.println("Department:" + this.department);
//call a method that returns a random password
this.password = setPassword(8);
System.out.println("Your password is: " + this.password);
}
// ask for department
private String setDepartment() {
System.out.print("Department codes:\n1) Sales \n2) Development \n3) Accounting \n0) None\nEnter department code ");
Scanner scanner = new Scanner(System.in);
int department = scanner.nextInt();
scanner.close();
if(department == 1) { return "Sales"; }
else if(department == 2) { return "Development"; }
else if(department == 3) { return "Accounting"; }
else if(department == 4) { return "IT departmwnt"; }
else if(department == 0) { return " "; }
else { return " ";}
}
// generate a random password
private String setPassword(int length) {
String passwordChar = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789#$*%!";
char[] password = new char[length];
for(int i=0;i<length;i++) {
int random = (int) (Math.random() * passwordChar.length());
password[i] = passwordChar.charAt(random);
}
return new String(password);
}
// set the mailbox capacity
public int setMailBoxCapacity(int capacity) {
this.mailboxCapacity = capacity;
return mailboxCapacity;
}
// set the alternate email
public String setAltEmail(String altEmail) {
this.alternateEmail = altEmail;
return alternateEmail;
}
// change the password
public String changePassword(String password) {
this.changePassword = password;
return changePassword;
}
public void info() {
System.out.println("Name: " + this.firstname + " " + this.lastname);
System.out.println("Email address is: " + this.firstname.toLowerCase() + "." + this.lastname.toLowerCase() + "@" + this.department + "." + comName );
System.out.println("Your mail box capacity is: " + mailboxCapacity + "mb");
}
}