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();

}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值