Aplikacja do tworzenia adresu e-mail. Określania działu itp. Pytanie czy to jest odpowiednio napisane? Getoza i setoza zachowana.
*
package emailapp;
import java.util.Scanner;
public class EmailApp {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
Email em1 = new Email("John", "Smith");
int choice = -1;
do {
System.out.println("\nENTER CHOICE\n1.Show Info\n2.Change Password"
+ "\n3.Change Mailbox Capacity\n4.Set Alternate Email\n5.Exit");
choice = s.nextInt();
switch(choice) {
case 1:
em1.getInfo();
break;
case 2:
em1.set_password();
break;
case 3:
em1.set_mailCap();
break;
case 4:
em1.alternate_email();
break;
case 5:
System.out.println("\nTHANKS!!!");
break;
default:
System.out.println("INVALID CHOICE! ENTER AGAIN!");
}
}while(choice!=5);
}
}
package emailapp;
import java.util.Scanner;
import java.util.Random;
public class Email {
public Scanner s = new Scanner(System.in);
private String firstName;
private String lastName;
private String department;
private String email;
private String password;
private int mailCapacity = 500;
private String altEmail;
public Email(String firstName, String lastName) {
this.firstName = firstName;
this.lastName = lastName;
System.out.println("New worker: " + this.firstName + " " + this.lastName);
this.department = this.setDept();
this.password = this.generate_password(8);
this.email = this.generate_email();
}
private String generate_email() {
return this.firstName.toLowerCase() + "." + this.lastName.toLowerCase() + "@" + this.department.toLowerCase()
+ ".4programmers.net";
}
private String setDept() {
System.out.println(
"Department code\n1 Sales\n2 Development\n3 Accounting\n0 None");
boolean flag = false;
do {
System.out.print("Enter 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;
}
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;
}
public void set_password() {
boolean flag = false;
do {
System.out.print("Change 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");
} 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);
}
public void set_mailCap() {
System.out.println("Current capacity = " + this.mailCapacity + "mb");
System.out.print("Enter new capacity: ");
this.mailCapacity = s.nextInt();
System.out.println("MAILBOX CAPACITY CHANGED SUCCESSFULLY!");
}
public void alternate_email() {
System.out.print("Enter new alternate email: ");
this.altEmail = s.next();
System.out.println("ALTERNATE EMAIL SET SUCCESSFULLY!");
}
public void getInfo() {
System.out.println("Name: " + this.firstName + " " + this.lastName);
System.out.println("Department: " + this.department);
System.out.println("Email: " + this.email);
System.out.println("Password: " + this.password);
System.out.println("Mailbox Capacity: " + this.mailCapacity + "mb");
System.out.println("Alter Email: " + this.altEmail);
}
}