gpt4 book ai didi

java - 3 个支票账户 2 个 build 者为客户提供没有 overdraw 的服务,但是不想 overdraw 的客户可以得到一个

转载 作者:行者123 更新时间:2023-12-02 03:28:51 25 4
gpt4 key购买 nike

ChequeAccount 类扩展了 Account 类。帐户类包含 ID、名称和余额属性。 ChequesAccount 类具有来自帐户的 overdraftLimit、amtOverdrawn 和 transactionNo 以及 super(ID、姓名、余额)。我在数组中创建了 3 个 chqAccount 对象并打印了它们的详细信息。 Ringo 已选择退出其 chq 帐户中的 overdraw 功能,因此为他提供了单独的构造函数。然而,当我打印所有支票帐户的详细信息时,他是唯一获得 overdraw 便利的人。它让我头疼,请帮忙

public class TestAccounts6
{
private static ChequeAccount[] chqAccount = new ChequeAccount[5];
private static int indexNo = 0;

public static void main(String[] args)
{
ChequeAccount c1 = new ChequeAccount("S1111", "Paul", 1245.00, 0, 0, 0);
ChequeAccount c2 = new ChequeAccount("S2222", "Ringo", 2500.00);
ChequeAccount c3 = new ChequeAccount("S3333", "John", 1575.00, 0, 0, 0);
chqAccount[0] = c1;
chqAccount[1] = c2;
chqAccount[2] = c3;
indexNo = 3;
System.out.printf("%-10s%-10s%-10s%-10s%-10s%-10s%n", "ID", "Name", "Balance",
"Overdraft", "Amount", "No of");
System.out.printf("%-10s%-10s%-10s%-10s%-10s%-10s%n", "", "", "",
"Limit", "Overdrawn", "Transactions\n");
for (int i = 0; i < indexNo; i++)
{
chqAccount[i].print();
}

}

}
public class ChequeAccount extends Account
{
protected double overdraftLimit = 10000;
protected double amtOverdrawn = 0;
protected int transactionNo = 0;

// constructor
public ChequeAccount(String ID, String name, double balance,
double overdraftLimit, double amtOverdrawn,
int transactionNo)
{
super(ID, name, balance);
this.overdraftLimit = overdraftLimit;
this.amtOverdrawn = amtOverdrawn;
this.transactionNo = transactionNo;
}

public ChequeAccount(String ID, String name, double balance)
{
super(ID, name, balance);
}

public void print()
{

System.out.printf("%-10s%-10s$%-9.2f$%-9.2f$%-9.2f%-10d%n", ID, name,
balance, overdraftLimit, amtOverdrawn, transactionNo);
}

}
public class Account
{
protected String ID;
protected String name;
protected double balance;

// Constructor
public Account(String ID, String name, double balance)
{
this.ID = ID;
this.name = name;
this.balance = balance;
}

预期林戈不会获得 overdraw 额度,而约翰和保罗会。与预期相反

最佳答案

它的行为正确。因为

  1. 您已创建 3 个 chqAccount 对象

ChequeAccount c1 = new ChequeAccount("S1111", "Paul", 1245.00, 0, 0, 0);

ChequeAccount c2 = new ChequeAccount("S2222", "Ringo", 2500.00);

ChequeAccount c3 = new ChequeAccount("S3333", "John", 1575.00, 0, 0, 0);

  • 当您尝试打印该对象的值时。它的打印方式如下。
  • ID Name Balance Overdraft Amount No of
    Limit Overdrawn Transactions

    S1111 Paul $1245.00 $0.00 $0.00 0 S2222
    Ringo $2500.00 $10000.00 $0.00 0 S3333 John
    $1575.00 $0.00 $0.00 0

    当我们观察上述情况并检查林戈的详细信息时。它的余额为: $10000.00 因为您尚未为 Ringo 分配任何值。但在 ChequeAccount 中如下。

      protected double overdraftLimit = 10000;
    protected double amtOverdrawn = 0;
    protected int transactionNo = 0;

    它有默认值。这样在打印时它就采用默认值。

    关于java - 3 个支票账户 2 个 build 者为客户提供没有 overdraw 的服务,但是不想 overdraw 的客户可以得到一个,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56896385/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com