java不允许使用空类型_【萌新求助!】此处不能使用空类型??

该楼层疑似违规已被系统折叠 隐藏此楼查看此楼

前面还有一部分代码我省去了

public class Account {

String customerId;

String accountNo;

float balance;

public Account(String customerId,String accountNo,float balance){

this.customerId = customerId;

this.accountNo = accountNo;

if (balance < 0) {

System.out.println("余额不能为负");

} else {

this.balance = balance;}

}

public Account(String customerId,String accountNo){

this.customerId = customerId;

this.accountNo = accountNo;

this.balance = 0;

}

public void deposit(float amount){

this.balance = balance + amount;

return ;

}

public void withdraw(float amount){

if (amount>balance){

System.out.println("账户余额不足!");

}else {

this.balance = balance - amount;}

return ;

}

public float getBalance(){

return balance;

}

}

public class Ex4_3 {

public static void main(String args[]) {

//为张三李四开设账户

Customer zhangsan = new Customer("1","zhangsan",'F');

Customer lisi = new Customer("2","lisi",'M');

Account zhangsan1 = new Account(zhangsan.getID(),"zhangsan1",2000);

Account zhangsan2 = new Account(zhangsan.getID(),"zhangsan2");

Account lisi1 = new Account(lisi.getID(),"lisi",3000);

//张三第一个账户取款500

if (!zhangsan1.withdraw(500))

{System.out.println("zhangsan1余额不足,取款失败!");

}

//张三从第一个账户转账1000到第二个账户中

if (!zhangsan1.withdraw(1000))

{System.out.println("zhangsan1余额不足,转帐失败!");

}

else

zhangsan2.deposit(1000);

//李四取款300

if (!lisi1.withdraw(300))

{System.out.println("lisi余额不足,取款失败!");

}

//查询张三与李斯的客户信息与账户余额

System.out.println(zhangsan);

System.out.println("张三的第一个账户余额为 " + zhangsan1.getBalance());

System.out.println("张三的第二个账户余额为 " + zhangsan2.getBalance());

System.out.println(lisi);

System.out.println("李四的余额为" + lisi1.getBalance());

}

}

【问题】就是在执行文件时 指出if (!lisi1.withdraw(300))这里不能使用空类型,求大神解答一下 不懂啊

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值