Current location - Trademark Inquiry Complete Network - Overdue credit card - JAVA helps write code
JAVA helps write code

public?class?Account?{

private?long?accountNO; //Account number

private?String?userName;

private?long?balance;//Balance

public?Account()?{

super();

}

public?Account(long?accountNO,?String?userName,?long?balance)?{

this.accountNO?=?accountNO;

this.userName?=?userName;

this.balance?=?balance;

}

//Deposit

public?long?deposit?(long?deposit ){

return?balance deposit;

}

//Withdrawal

public?long?withdrawal(long?withdrawal)? {

return?balance-withdrawal;

}

//Show balance

public?long?showBalance()?{

return?balance;

}

public?long?getAccountNO()?{

return?accountNO;

}

public?void?setAccountNO(long?accountNO)?{

this.accountNO?=?accountNO;

}

public?String?getUserName()?{

return?userName;

}

public?void?setUserName(String?userName)?{

this.userName?=?userName;

}

public?long?getBalance()?{

return?balance;

}

public?void?setBalance(long?balance)?{

this.balance?=?balance;

}

}

//Credit card account type

public?class?CreditAccount?extends?Account?{

private?long?limitBalance? =?-10000L;

//Call this method for withdrawal.

//First, you instantiate the Account class, that is, you will see it in the table ?Check out?this?account?balance and so on?

//Suppose?Take 1000

public?boolean?xinyongqukuan(long?qukuanshu){

long?x?=?withdrawal(qukuanshu

);

if(x?lt;?limitBalance){?

//Perform other operations

return?false;

}else{

//The operation of updating the database here

return?true;

}

}

public?long?getLimitBalance()?{

return?limitBalance;

}

public?void?setLimitBalance(long?limitBalance)? {

this.limitBalance?=?limitBalance;

}

}

//?Deposit card account type

public?class?SavingAccount?extends?Account?{

private?long?limitBalance?=?0L;

//Savings and withdrawals

public ?boolean?chuxunqukuan(long?qukuanshu)?{

long?x?=?withdrawal(qukuanshu);

if(x?lt;?limitBalance){?

//Perform other operations

return?false;

}else{

//Update the database operation here

return?true;

}

}

public?long?getLimitBalance()?{

return?limitBalance ;

}

public?void?setLimitBalance(long?limitBalance)?{

this.limitBalance?=?limitBalance;

}

}

public class TestAccount {

//xin yong

public boolean qukuan1(long qukuanshu){

//Temporarily, just set a balance. Actually, there will be user name and so on.

//This is obtained from the database. Temporarily, new one. The original poster pays attention to understanding and stipulates that it has 500 yuan.

CreditAccount cred = new CreditAccount();

cred.setBalance(500L);

boolean ?issuccess = cred.xinyongqukuan(qukuanshu);

if (issuccess) {

//Add other logic

System.err.println("Withdrawal successful!");

}else {

//Add other logic

System.err.println("Withdrawal failed!");

}

return issuccess;

}

// chuxu

public boolean qukuan2(long qukuanshu) {

SavingAccount ?sav = new SavingAccount();

sav.setBalance(500L);

boolean ?issuccess2 = sav.chuxunqukuan(qukuanshu);

if (issuccess2) {

//Add other logic

System.err.println("Withdrawal successful!");

}else {

//Add other logic

System.err.println("Withdrawal failed!");

}

return issuccess2;

}

public static void main(String[] args) {

//Testable

TestAccount tt= new TestAccount();

boolean l= tt.qukuan1(10499L);

//boolean l2= tt.qukuan2(501);

}

}