public class Acc{
private double balance;
public Account()
{
balance = 5;
}
public Acc(double sBalance)
{
balance = sBalance;
}
public void depos(double amount)
{
balance = balance + amount;
}
public void withd(double amount)
{
balance = balance - amount;
if (withd>balance){
System.out.println("Error");
}
}
public double gBalance()
{
return balance;
}
}
主要的:
public class Main{
public static void main(String[] args){
Acc newBank = new Acc(50);
newBank.withd(20);
newBank.depos(5);
System.out.println(newBank.gBalance());
}
}
基本上我想创建一个函数来从余额中提取和存入一个值,其中 $5 被添加到每个创建的新帐户中。它似乎有效,但是我想延长并使其提取超过余额的金额会出现错误并且不会从余额中扣除
慕丝7291255
相关分类