Skip to content

Commit 01e54d1

Browse files
committed
Mail
0 parents  commit 01e54d1

File tree

2 files changed

+97
-0
lines changed

2 files changed

+97
-0
lines changed

Diff for: Email.java

+89
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
import java.util.Random;
2+
import java.util.Scanner;
3+
4+
public class Email {
5+
6+
private String firstName ;
7+
private String lastName ;
8+
private String email ;
9+
private String password ;
10+
private String deprt ;
11+
private String alterEmail ;
12+
private int mailBoxCap ;
13+
private String companySuf = "comp.com";
14+
15+
// Constructor to receive first and last name
16+
17+
public Email( String firstName , String lastName) {
18+
this.firstName = firstName;
19+
this.lastName = lastName;
20+
System.out.println("Email has been created : "+ this.firstName + " " + this.lastName);
21+
this.deprt = setDept();
22+
System.out.println("Departement : "+this.deprt);
23+
this.password = randmPass(10);
24+
System.out.println("Suggested string password : "+password);
25+
email = firstName.toLowerCase() + "." + lastName.toLowerCase() + "@" + deprt +"."+ companySuf;
26+
27+
System.out.println(email);
28+
}
29+
30+
31+
// Ask for departement
32+
private String setDept() {
33+
System.out.println("Enter the departement \n1 for Sales \n2 for Dev \n3 for Accounting \n0 for none ");
34+
Scanner scan = new Scanner(System.in);
35+
int depChoice = scan.nextInt();
36+
37+
switch (depChoice) {
38+
case 1:
39+
return "Sales";
40+
case 2:
41+
return "Dev";
42+
case 3:
43+
return "Accounting";
44+
case 0:
45+
return "None";
46+
default:
47+
return "Invalid choice";
48+
}
49+
}
50+
// Generate a random pass
51+
52+
private String randmPass(int length) {
53+
String setPassword = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789@#$%^&*";
54+
char[] password = new char[length];
55+
for (int i = 0; i < length; i++) {
56+
int rand = (int)(Math.random() * setPassword.length());
57+
password[i] = setPassword.charAt(rand);
58+
}
59+
return new String(password);
60+
}
61+
62+
63+
// Set the mailBox capacity
64+
65+
public void setMailboxCap(int capacity) {
66+
this.mailBoxCap = capacity ;
67+
}
68+
// Set the alternative email
69+
public void setAlterEmail(String altEmail) {
70+
this.alterEmail = altEmail ;
71+
}
72+
// Change password
73+
public void changePass(String password) {
74+
this.password = password ;
75+
}
76+
77+
public int getMailboxCap() {return mailBoxCap ;}
78+
public String getChangePass() {return password ;}
79+
public String getAlterEmail() {return alterEmail ;}
80+
81+
82+
83+
}
84+
85+
86+
87+
88+
89+

Diff for: emailApp.java

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
public class emailApp {
2+
3+
public static void main(String[] args) {
4+
Email eml = new Email("Hadil", "Zaoudi");
5+
eml.setMailboxCap(500);
6+
System.out.println(eml.getMailboxCap());
7+
}
8+
}

0 commit comments

Comments
 (0)