--- --
. . .
---
public class UserEmail {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("请输入邮箱号");
String user = sc.nextLine();
Email mail = new Email(user);
try {
mail.emilHeFa();
System.out.println("邮箱正确");
System.out.println("请输入密码");
String pw = sc.next();
PassWord passWord = new PassWord(pw);
try {
passWord.passWord();
System.out.println("密码正确");
} catch (SeverPassWordException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
} catch (NUmException e) {
e.printStackTrace();
} catch (WeikongException e) {
e.printStackTrace();
} catch (OrderException e) {
e.printStackTrace();
} catch (LengthException e) {
e.printStackTrace();
} catch (SeverUserException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
}
}
class NUmException extends Exception {
public NUmException() {
super();
}
public NUmException(String message) {
super(message);
}
}
class WeikongException extends Exception {
public WeikongException() {
super();
}
public WeikongException(String message) {
super(message);
}
}
class OrderException extends Exception {
public OrderException() {
super();
}
public OrderException(String message) {
super(message);
}
}
class LengthException extends Exception {
public LengthException() {
super();
}
public LengthException(String message) {
super(message);
}
}
class SeverUserException extends Exception {
public SeverUserException() {
super();
}
public SeverUserException(String message) {
super(message);
}
}
class SeverPassWordException extends Exception {
public SeverPassWordException() {
super();
}
public SeverPassWordException(String message) {
super(message);
}
}
class Email {
private String mail;
public Email(String mail) {
this.mail = mail;
}
public String getMail() {
return mail;
}
public void setMail(String mail) {
this.mail = mail;
}
public void emilHeFa() throws NUmException, WeikongException, OrderException, LengthException, SeverUserException {
if (!(mail.contains("@") && mail.contains("."))) {
throw new NUmException("没有 @ .");
}
if (mail.contains(" ") || mail.endsWith(".") || !shunXu(mail)) {
throw new WeikongException("@和.前后不能为空");
}
if (mail.indexOf("@") > mail.indexOf(".")) {
throw new OrderException("格式不正确");
}
if (mail.indexOf("@") < 10 && !(bigLetter(mail))
|| ((numLetter(mail) && mail.indexOf("@") < 10 && !(bigLetter(mail))))) {
throw new LengthException("@前面的长度至少是10,包含数字,字母且必须有大写字母");
}
UAP c = new UAP();
String us = c.user;
if (!(mail.equals(us))) {
throw new SeverUserException("用户名错误");
}
System.out.println("用户正确");
}
public boolean shunXu(String user) {
if ((mail.indexOf(".") - mail.indexOf("@") >1)) {
return true;
}
return false;
}
public boolean numLetter(String user) {
for (int i = 0; i < user.length(); i++) {
char a = user.charAt(i);
if (a >= 97 && a <= 122 || a >= 0 && a <= 9) {
return true;
}
}
return false;
}
public boolean bigLetter(String user) {
for (int i = 0; i < user.length(); i++) {
char a = user.charAt(i);
if (a >= 65 && a <= 90) {
return true;
}
}
return false;
}
}
class PassWord {
private String pw;
public PassWord(String pw) {
this.pw = pw;
}
public String getPw() {
return pw;
}
public void setPw(String pw) {
this.pw = pw;
}
public void passWord() throws SeverPassWordException {
UAP c = new UAP();
String mi = c.pw;
if (!(pw.equals(mi))) {
throw new SeverPassWordException("用户密码不正确");
}
System.out.println("密码通过");
}
}
class UAP {
public static String user = "Q123456789@163.com";
public static String pw = "1234567";
}