代码
Blank类
public class Blank {
private int total;
public Blank() {
}
public Blank(int total) {
this.total = total;
}
public void show() {
System.out.println("当前的存款为:" + total);
}
public void Withdraw_money(int num) {
if (total < num) {
System.out.println("余额不足无法取款!");
} else {
System.out.println("成功取款" + num + "元");
total -= num;
System.out.println("当前的存款为:" + total);
}
}
public void Save_money(int num) {
System.out.println("成功存款" + num + "元");
total += num;
System.out.println("当前的存款为:" + total);
}
}
main方法
public class Demo01 {
public static void main(String[] args) {
Blank one=new Blank(500);
one.show();
one.Save_money(1000);
one.Withdraw_money(800);
}
}