Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

IN JAVA rite An Inte 1-34106273-dt-content-rid-146073787 1/courses/KCCO1 CP 6200

ID: 3909936 • Letter: I

Question

IN JAVA

rite An Inte 1-34106273-dt-content-rid-146073787 1/courses/KCCO1 CP 6200 01 1182/1/KCCo1 CP.6200 01 1179.1. mpor - + 110% Part A Include an equals method in both the CreditCard and DebiCard classes to compare two objects Part B- Wallet class Write a class called Wallet to store information about the current state of a wallet. A wallet has different compartments for the dollar bills, loose change, credit /debit cards and ID cards. Data Members should include: Amount of cash - keep track of value of dollar bills and valuc of change separately Array of ChargeCards-it can contain both CreditCards and DebitCards. Array of ID cards- this can be simply an array of Strings. information . . It's up to you how to store this Methods should include: at least two constructors accessor, mutator methods TotalCashOnHand total value of dollar bills and change TotalCanSpend- includes both cash and amount that can be spent on credit/ debit cards. a method that tells you how many ID Cards are in the wallet a method that tells you how many credit / debit cards are in the wallet a method that lets you add a credit / debit card to the set a method to append an ID card to the set toString method-should delegate to CreditCard class to print information about each . credit card and DebitCard class to print information about each debit card. Remember to keep the design paradigms of data hiding and encapsulation in mind as much as possible. Delegate tasks to the component classes (of ChargeCard, DebitCard, CreditCard) whenever you can. Perform input validation as appropriate. Part C- Menu Driven Program Write a menu-driven program that allows the user to interact with a single Wallet object. 1. Print all information about Wallet. [This should call the toString method of the Wallet class 2. Add a Credit Card. [Prompt the user for information about the Credit Card] 3. Add a Debit Card. [Prompt the user for information about the Debit Card. 4. Add an ID Card. [Prompt the user for information about the ID card.] 5. Add Cash. [Prompt the user for the value of additional coins or dollar bills. 6. Make a purchase. [Should ask for purchase amount. Then let the user choose whether to pay with cash or charge card. If cash, make sure there is sufficient cash in the wallet to cover the purchase, and then deduct accordingly. If charge card, there should be a submenu in which the user chooses a card from the list to use. Then the system should check that the card can be used for that purchase, i.e., that there are sufficient funds available on that card, and actually process the purchase on the selected ChargeCard.)

Explanation / Answer

Answer:

Here, I have following java code as programming as shown below

Code:

Wallet.java:

import java.util.ArrayList;

import java.util.Scanner;

// implement a class

public class Wallet {

   

    private double TotCash;

    private ArrayList<ChargeCard> Cards = new ArrayList<>();

    private ArrayList<String> IDCards = new ArrayList<>();

    public Wallet(double totalCash) {

        this.TotCash = totalCash;

    }

    public void AddCash(double cash) {

        TotCash += cash;

    }

    public void Purchasing(double pay) {

        Scanner key = new Scanner(System.in);

        System.out.println("1 Cash");

        System.out.println("2 Charge card");

        System.out.print("Choice: ");

        int select = key.nextInt();

        if(select == 1) {

            TotCash -= pay;

        }else {

            System.out.println("1 Debit card");

            System.out.println("2 Credit card");

            System.out.print("Choice: ");

            int choice = key.nextInt();

            if(choice == 1) {

                for (int i = 0 ; i < Cards.size(); i++) {

                    if(Cards.get(i).getClass().getSimpleName() == "DebitCard") {

                        System.out.println(i + Cards.get(i).toString());

                    }

                }

                System.out.print("Enter number card in list:");

                int number = key.nextInt();

                Cards.get(number).Purchasing(pay);

            }else {

                for (int i = 0 ; i < Cards.size(); i++) {

                    if(Cards.get(i).getClass().getSimpleName() == "CreditCard") {

                        System.out.println(i + Cards.get(i).toString());

                    }

                }

                System.out.print("Enter number card in list:");

                int num = key.nextInt();

                Cards.get(num).Purchasing(pay);

            }

        }

    }

    public double TotalCashOnHand() {

        double total = 0;

        for (int i = 0; i < Cards.size(); i++) {

            total += Cards.get(i).getBalance();

        }

        return total;

    }

    public double TotalCanSpend() {

        double total = 0;

        for (int i = 0; i < Cards.size(); i++) {

            total += Cards.get(i).getBalance();

        }

        return total;

    }

    public int AllCardsID() {

        return IDCards.size();

    }

    public int AllCards() {

        return Cards.size();

    }

    public void AddDebitCard() {

        Scanner key = new Scanner(System.in);

        String name;

        String cardNumber;

        System.out.print("Enter name:");

        name = key.nextLine();

        System.out.println("Enter card number");

        cardNumber = key.nextLine();

        Cards.add(new DebitCard(name, cardNumber));

    }

    public void AddCreditCard() {

        Scanner key = new Scanner(System.in);

        String name;

        String cardNum;

        System.out.print("Enter name:");

        name = key.nextLine();

        System.out.println("Enter card number");

        cardNum = key.nextLine();

        Cards.add(new CreditCard(name, cardNum));

    }

    public void AddCardID(String cardNumber) {

        IDCards.add(cardNumber);

    }

    public String toString() {

        String Info = "Cash:" + TotCash + "$ ";

        if(Cards.size() >= 1) {

            for (int i = 0; i < Cards.size(); i++) {

                Info += Cards.get(i).toString();

                Info += " ";

            }

        }

        return Info;

    }

}

Tester.java:

import java.util.Scanner;

public class Tester {

    public static void main(String[] args) {

        Wallet walt = new Wallet(1246);

        while (true) {

            System.out.println("Choose action");

            System.out.println("0 Exit");

            System.out.println("1 Print all information about Wallet.");

            System.out.println("2 Add a Credit Card.");

            System.out.println("3 Add a Debit Card.");

            System.out.println("4 Add an ID Card.");

            System.out.println("5 Add Cash.");

            System.out.println("6 Make a purchase");

            Scanner scan = new Scanner(System.in);

            int n = 0;

            try {

                n = scan.nextInt();

            } catch (Exception e) {

                System.out.println("Be careful with input");

                n = -1;

            }

            switch (n) {

                case 0:

                    System.exit(0);

                    break;

                case 1:

                    System.out.println(walt.toString());

                    break;

                case 2:

                    walt.AddCreditCard();

                    break;

                case 3:

                    walt.AddDebitCard();

                    break;

                case 4:

                    System.out.print("Enter card ID:");

                    String CardID = scan.nextLine();

                    walt.AddCardID(CardID);

                    break;

                case 5:

                    System.out.print("Enter add cash: ");

                    double Cash = scan.nextDouble();

                    walt.AddCash(Cash);

                    break;

                case 6:

                    System.out.println("Print purchase amount: ");

                    double Pay=scan.nextDouble();

                    walt.Purchasing(Pay);

                    break;

                default:

                    System.out.println("Please print correct number");

            }

        }

    }

}

DebitCard.java:

public class DebitCard extends ChargeCard {

    private double OvrdraftLimit;

    private double OvrdraftFee;

    private double FeesIncurred;

    DebitCard(String name, String cardNumber) {

        super(name, cardNumber);

        this.OvrdraftFee = 50;

        this.OvrdraftLimit = 100;

    }

   public double getFeesIncurred() {

        return FeesIncurred;

    }

    public double getOverdraftFee() {

        return OvrdraftFee;

    }

    public double getOverdraftLimit() {

        return OvrdraftLimit;

    }

    public void Purchasing(double pay) {

        if (pay <= balance)

            balance -= pay;

        else if (pay > balance) {

            if (pay <= (balance + OvrdraftLimit + OvrdraftFee))

                balance -= pay + OvrdraftFee;

        }

    }

    public void IncreaseOverdraftLimit() {

        OvrdraftLimit += 100;

    }

    public void DepositFunds(double deposit) {

        balance += deposit;

    }

    public void WithdrawFunds(double fund) {

        balance -= fund;

    }

    public void PayFees() {

        FeesIncurred = 0;

    }

    public String toString() {

        return super.toString() + " OverdraftLimit: " + OvrdraftLimit + "$" + " OverdraftFee: " + OvrdraftFee + "$"

                + " FeesIncurred: " + FeesIncurred + "$";

    }

}

CreditCard.java:

public class CreditCard extends ChargeCard{

    private double OvrdraftLimit;

    private double FeesIncurred;

    CreditCard(String nme, String cardNumber) {

        super(nme, cardNumber);

        balance = 1000;

    }

    public void Purchasing(double pay) {

        balance -= pay;

    }

    public void IncreaseOverdraftLimit() {

        OvrdraftLimit += 100;

    }

    public void DepositFunds(double deposit) {

        balance += deposit;

    }

    public void WithdrawFunds(double fund) {

        balance -= fund;

    }

    public void PayFees() {

        FeesIncurred = 0;

    }

    public String toString() {

        return super.toString() + " OverdraftLimit: " + OvrdraftLimit + "$" + " FeesIncurred: " + FeesIncurred + "$";

    }

    public double getOverdraftLimit() {

        return OvrdraftLimit;

    }

    public void setOverdraftLimit(double overdraftLimit) {

        this.OvrdraftLimit = overdraftLimit;

    }

}

ChargeCard.java:

public abstract class ChargeCard {

    protected String name;

    protected String cardNumber;

    protected double balance;

    ChargeCard(String name, String cardNumber) {

        this.name = name;

        this.cardNumber = cardNumber;

        this.balance = 0;

    }

    public String getName() {

        return name;

    }

    public String getCardNumber() {

        return cardNumber;

    }

    public double getBalance() {

        return balance;

    }

    public abstract void Purchasing(double pay);

    public abstract void IncreaseOverdraftLimit();

    public abstract void DepositFunds(double deposit);

    public abstract void WithdrawFunds(double fund);

    public abstract void PayFees();

    public String toString() {

        return "Name of card: " + name + " card number: " + cardNumber+ " balance: " + balance + "$";

    }

}