天天看點

java實驗題_java實驗題

展開全部

代碼如下:public class Account {

private String accountNumber;

private String username;

private String identityCard;

private String level;

public static double accountBalance;

public String getAccountNumber() {

62616964757a686964616fe58685e5aeb931333363396334return accountNumber;

}

public void setAccountNumber(String accountNumber) {

this.accountNumber = accountNumber;

}

public String getUsername() {

return username;

}

public void setUsername(String username) {

this.username = username;

}

public String getIdentityCard() {

return identityCard;

}

public void setIdentityCard(String identityCard) {

this.identityCard = identityCard;

}

public String getLevel() {

return level;

}

public void setLevel(String level) {

this.level = level;

}

public double getAccountBalance() {

return accountBalance;

}

public void setAccountBalance(double accountBalance) {

this.accountBalance = accountBalance;

}

// 存款

public void deposit(){ }

// 取款

public void withdrawal(){ }

// 統計

public void total(){

System.out.println(username + "的賬戶餘額:" + accountBalance);

}

}public class Trans extends Account {

private String date;

private static char type;

private static double money;

public Trans(char type, double money){

this.type = type;

this.money = money;

}

@Override

public void deposit() {

Account.accountBalance = getAccountBalance() + money;

}

@Override

public void withdrawal() {

Account.accountBalance = getAccountBalance() - money;

}

}public class Test {

public static void main(String[] args) {

Account a = new Account();

a.setLevel("五星");

a.setUsername("張三");

a.setAccountBalance(55000);

Trans t1 = new Trans('C', 1000);

t1.deposit();

a.total();

Trans t2 = new Trans('Q', 6000);

t2.withdrawal();

a.total();

}

}