Current location - Trademark Inquiry Complete Network - Overdue credit card - Java question
Java question

I've written it.

There is too much code to post.

Please contact me.

The following is part of the code: (incomplete)

public class Bank {

private ArrayListlt; Accountgt; list=new ArrayListlt; Accountgt; ();

public static final long startNO=1000L;

private static long NO=startNO;

public void registery(){

Scanner scan =new Scanner(System.in);

String name, key1, key2, id, email;

double money=0;

int state=0 ;

do {

System.out.print("Please select the type of account you want to open 1. Debit card 2. Credit card: ");

try {

state=Integer.parseInt(scan.next().trim());

if(state!=1amp;amp;state!=2)

throw new Exception();

}

catch (Exception e) {

System.out.println("Illegal character or command input Error");

}

}while(state==0);

do {

System.out.print( "Enter the user name, the length is gt;=3:");

name=scan.next().trim();

if(name.length()lt; 3)

System.out.println("Username is not long enough");

else break;

} while (true);

do {

System.out.print("Enter the password, the length is gt; = 6, must contain numbers, characters and special symbols: ");

key1= scan.next().trim();

if(key1.length()lt; 6){

System.out.println("Password length is not long enough");

continue;}

if(!key1.matches("\\d \\p{Punct} \\p{Alpha} ")amp;amp;!

key1.matches("\\p{Alpha} \\p{Punct} \\d ")){

System.

out.println("The password format is incorrect and must contain numbers, characters and special symbols:");

continue;}

System.out.print("Confirm password:") ;

key2=scan.next().trim();

if(!key1.equals(key2))

System.out.println( "Two passwords do not match");

else break;

} while (true);

do {

System. out.print("Enter the 18-digit ID number: ");

id=scan.next().trim();

if(id.length()! =18||!id.matches("\\d "))

System.out.println("The length of the ID number does not match or the format is incorrect");

else break;

} while(true);

do {

System.out.print("Please enter your email address: ");

email=scan.next().trim();

if(!email.matches("^\\w @\\w $"))

System .out.println("The email format is incorrect");

else break;

} while (true);

do {

System.out.print("Please enter the deposit amount: ");

try {

money=Double.parseDouble(scan.next().trim());

if(moneylt;=0)

throw new Exception();

}

catch (Exception e){

System.out.println("The amount format is wrong or unreasonable (lt;=0)");

}

} while (moneylt;=0);

System.out.print("Account opened successfully, card number is: " NO " type is " (state==1? "Debit Card": "Credit Card") " Name: " name

" ID number: " id " Email: " email " Pre-deposit amount: " money "yuan");

if(state==2){

CreditAccount creditAccount=new CreditAccount(NO,nam

e, key1, id, email, money);

System.out.println("The available amount is: " (creditAccount.getCeiling() money "yuan"));

list.add(creditAccount);

}

else{

list.add(new DebtAccount(NO, name, key1, id, email, money) );

System.out.println();

}

NO ;

}

public Account login(long id, String password){

Account a=searchAccount(id);

if(a!=null)

if(a. getPasswd().equals(password))

return a;

return null;

}

public Account deposit(long id , double money){

Account a=searchAccount(id);

if(a!=null){

a.deposit(money);

return a;

}

return null;

}

public Account withdraw(long id, double money){

Account a=searchAccount(id);

if(a!=null)

if(a.withdraw(money)gt;0 )

return a;

return null;

}

public Account setCeiling(long id, double ceiling){

Account a=searchAccount(id);

if(a!=null)

if(a.getClass()==CreditAccount.class){//Find The id corresponds to the account and is a credit card account

((CreditAccount)a).setCeiling(ceiling);

return a;

}

return null;

}

public String balanceStr(Account a){

String str="Your balance is:" a.getBalance( );

if(a.getClass()==CreditAccount.class)

str=str "The available credit limit is:"

(((CreditAccount)a).getCeiling() a. getBalance()) "元";

return str;

}

public double allBalance(boolean isComputeCredit){

double allRemain =0;

if(isComputeCredit){

for(Account a: list)

if(a.getClass()==CreditAccount.class)

allRemain=allRemain a.getBalance();

}

else{

for(Account a: list)

allRemain=allRemain a.getBalance();

}

return allRemain;

}

public Account searchAccount(long id){

for(Account a: list)

if(a.getId()==id)

return a;

return null;

}

public static void main(String[] args) {

Bank bank=new Bank();

Scanner scan=new Scanner(System.in);

int state=0;

do {

System.out.print("Welcome To use the online banking system, please enter the instructions 1. Open an account 2. Log in 3. Exit: ");

try {

state=Integer.parseInt(scan.next().trim( ));

if(state!=1amp;amp;state!=2amp;amp;state!=3)

throw new Exception();

} catch (Exception e) {

System.out.println("Illegal character or command input error");

continue;

}

if(state==1)

bank.registery();

else

if(state==2){

Account log=bank.logCheck();

if(log!=null){

bank.operate( log);

}

}

} while (state!=3);

System.out.println("Thank you Use, welcome to use next time!!");

}

public Account logCheck(){

Scanner scan=new Scanner(System.in);

String password;

long id=0;

do {

try {

System.out .print("Enter card number:");

id=Long.parseLong(scan.next().trim());

if(idlt;startNO)

throw new Exception();

}

catch (Exception e) {

System.out.println("The card number is not long enough or illegal Character input ");

continue;

}

do {

System.out.print("Enter password: ") ;

password=scan.next().trim();

if(password.length()lt;6)

System.out.println ("Password length is not long enough");

else break;

} while (true);

Account log=login(id, password);

p>

if(log==null){

System.out.println("Login failed! The card number or password is incorrect, please log in again! ");

}

else{

System.out.println("Login successful! Your card type is " (log.getClass()= =

CreditAccount.class?"Credit Card":"Debit Card"));

return log;

}

} while(true);

}

public void operate(Account a){

Scanner scan=new Scanner(System.in);

int

state=-1;

do {

System.out.print("Please enter the command 1. Withdraw 2. Deposit 3. Exit 0. Balance inquiry: ");

p>

try {

state=Integer.parseInt(scan.next().trim());

if(state!=1amp;amp;state!= 2amp;amp;state!=3amp;amp;state!=0)

throw new Exception();

}

catch (Exception e) {

System.out.println("Illegal character or command input error");

continue;

}

if(state ==0){

System.out.println(balanceStr(a));

}

else if(state==1){

double money=0;

do {

System.out.print("Please enter the withdrawal amount: ");

try {

money=Double.parseDouble(scan.next().trim());

if(moneylt;=0)

throw new Exception() ;

}

catch (Exception e) {

System.out.println("The amount format is wrong or unreasonable (lt;=0)") ;

}

} while (moneylt;=0);

if(a.withdraw(money)==0){

System.out.println("Sorry, your balance is insufficient, please re-enter");

}

else System.out.println("Withdrawal successful," balanceStr (a));

}

else if(state==2){

double money=0;

do {

System.out.print("Please enter the deposit amount: ");

try {

money=Double.parseDouble(scan.next(). trim());

if(moneylt;=0)

throw new Exception();

}

catch (Exception e) {

System.out.println

("The amount format is incorrect or unreasonable (lt;=0)");

}

} while (moneylt;=0);

a. deposit(money);

System.out.println("Deposit successful," balanceStr(a));

}

} while(state!= 3);

System.out.println(a.getName() "Exited successfully.");

}

}