-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEmail.java
More file actions
86 lines (75 loc) · 2.53 KB
/
Email.java
File metadata and controls
86 lines (75 loc) · 2.53 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
package email_application;
import java.util.Scanner;
public class Email {
private String firstname;
private String lastname;
private String department;
private String password;
private String email;
private String randomPassword;
private int mailboxcapacity=500;
private int defaultPasswordlength=10;
private String alternateEmail;
private String companySuffix="xyzcomany.com";
// asking first and last name
public Email(String firstname,String lastname)
{
this.firstname=firstname;
this.lastname=lastname;
System.out.println("EMAIL CREATED: "+this.firstname+" "+this.lastname);
// Call a method asking for department and return department
this.department=setDepartment();
System.out.println("Department: "+this.department);
//method that returns a random password
this.password=randomPassword(defaultPasswordlength);
System.out.println("Your password is:"+this.password);
//combining elements to generate email
email=firstname.toLowerCase()+"."+lastname.toLowerCase()+"@"+department +companySuffix;
System.out.println("Your email is:"+email);
}
private String setDepartment()
{
System.out.println(" ENTER THE DEPARTMENT CODE\n1 for sales \n2 for development \2 for accounting \n0 for none");
Scanner in=new Scanner(System.in);
int Deptchoice=in.nextInt();
if(Deptchoice==1) {return "sales";}
else if(Deptchoice==2) {return "development";}
else if(Deptchoice==3) {return "accounting";}
else {return " ";}
}
//Generate a random password
private String randomPassword(int length) {
String passwordSet="ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@$%";
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);
}
//Set the mailbox capacity
public void setMailCapacity(int capacity) {
this.mailboxcapacity=capacity;
}
//Set the alternate email
public void setAlternateEmail(String altEmail)
{
this.alternateEmail=altEmail;
}
//change the password
public void changePassword(String password) {
this.password=password;
}
public int getMailboxCapacity() {return mailboxcapacity;}
public String getAlternateEmail() {return alternateEmail;}
public String getPassword() {return password;}
public String showInfo() {
return "DISPLAY NAME:"+firstname+" "+lastname+
"COMPANY EMAIL:"+email+
"MAILBOX CAPACITY:"+ mailboxcapacity+"ab";
}
public static void main(String[] args) {
// TODO Auto-generated method stub
}
}