Class CreditCard

java.lang.Object
com.zybooks.dsaj.primer.CreditCard
Direct Known Subclasses:
PredatoryCreditCard

public class CreditCard extends Object
A simple model for a consumer credit card.
  • Field Details

    • balance

      protected double balance
  • Constructor Details

    • CreditCard

      public CreditCard(String cust, String bk, String acnt, int lim, double initialBal)
      Constructs a new credit card instance.
      Parameters:
      cust - the name of the customer (e.g., "John Bowman")
      bk - the name of the bank (e.g., "California Savings")
      acnt - the account identifier (e.g., "5391 0375 9387 5309")
      lim - the credit limit (measured in dollars)
      initialBal - the initial balance (measured in dollars)
    • CreditCard

      public CreditCard(String cust, String bk, String acnt, int lim)
      Constructs a new credit card instance with default balance of zero.
      Parameters:
      cust - the name of the customer (e.g., "John Bowman")
      bk - the name of the bank (e.g., "California Savings")
      acnt - the account identifier (e.g., "5391 0375 9387 5309")
      lim - the credit limit (measured in dollars)
  • Method Details

    • getCustomer

      public String getCustomer()
      Returns the name of the customer.
    • getBank

      public String getBank()
      Returns the name of the bank
    • getAccount

      public String getAccount()
      Return the account identifier.
    • getLimit

      public int getLimit()
      Return the credit limit.
    • getBalance

      public double getBalance()
      Return the current balance.
    • charge

      public boolean charge(double price)
      Charges the given price to the card, assuming sufficient credit limit.
      Parameters:
      price - the amount to be charged
      Returns:
      true if charge was accepted; false if charge was denied
    • makePayment

      public void makePayment(double amount)
      Processes customer payment that reduces balance.
      Parameters:
      amount - the amount of payment made
    • printSummary

      public static void printSummary(CreditCard card)
    • main

      public static void main(String[] args)