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

Part A Include an equals method in both the CreditCard and DebitCard classes to

ID: 3906114 • Letter: P

Question

Part A Include an equals method in both the CreditCard and DebitCard 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 value 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. It’s up to you how to store this information.

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.]

  

Part D

Use an ArrayList to store the sets of ChargeCards and ID cards in the Wallet. Incorporate these changes in your menu-driven program so that the user can store an unlimited number of cards in the Wallet.

Part E

The debit and credit cards should implement the Comparable interface. This way the list of cards can be sorted before they are displayed to the user. You can use the Collections.sort method to sort an ArrayList.

It is up to you to decide how the objects should be compared. The two fields that seem meaningful for ordering objects are ID number and current balance. It is up to you to decide whether the interface should be implemented in the ChargeCard class or in each of the subclasses.

Extra credit:

1. Add additional functionality to your main program so that the user can remove an ID card or debit / credit card from the Wallet. Let the user select the card he would like to remove. This is possible since they are stored in ArrayLists and an ArrayList can grow and shrink as necessary.

2. Design a GiftCard class that also extends ChargeCard and integrate it in the Wallet class. Gift cards come preloaded with a specific amount of money and the user can never spend more than that predetermined amount.

Explanation / Answer

solution:

Tester.java
---------------------------------------------
import java.util.Scanner;
public class Tester {
public static void main(String[] args) {
Wallet wallet = 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(wallet.toString());
break;
case 2:
wallet.addCreditCard();
break;
case 3:
wallet.addDebitCard();
break;
case 4:
System.out.print("Enter card ID:");
String cardID = scan.nextLine();
wallet.addCardID(cardID);
break;
case 5:
System.out.print("Enter add cash: ");
double cash = scan.nextDouble();
wallet.addCash(cash);
break;
case 6:
System.out.println("Print purchase amount: ");
double pay=scan.nextDouble();
wallet.purchase(pay);
break;
default:
System.out.println("Please print correct number");
}
}
}
}
--------------------------------------------------------------------------------------
Wallet.java
------------------------------------
import java.util.ArrayList;
import java.util.Scanner;
public class Wallet {
private double totalCash;
private ArrayList<ChargeCard> cards = new ArrayList<>();
private ArrayList<String> idCards = new ArrayList<>();
public Wallet(double totalCash) {
this.totalCash = totalCash;
}
public void addCash(double cash) {
totalCash += cash;
}
public void purchase(double pay) {
Scanner sc = new Scanner(System.in);
System.out.println("1 Cash");
System.out.println("2 Charge card");
System.out.print("Choice: ");
int choice = sc.nextInt();
if(choice == 1) {
totalCash -= pay;
}else {
System.out.println("1 Debit card");
System.out.println("2 Credit card");
System.out.print("Choice: ");
int choiceCard = sc.nextInt();
if(choiceCard == 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 = sc.nextInt();
cards.get(number).purchase(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 number = sc.nextInt();
cards.get(number).purchase(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 sc = new Scanner(System.in);
String name;
String cardNumber;
System.out.print("Enter name:");
name = sc.nextLine();
System.out.println("Enter card number");
cardNumber = sc.nextLine();
cards.add(new DebitCard(name, cardNumber));
}
public void addCreditCard() {
Scanner sc = new Scanner(System.in);
String name;
String cardNumber;
System.out.print("Enter name:");
name = sc.nextLine();
System.out.println("Enter card number");
cardNumber = sc.nextLine();
cards.add(new CreditCard(name, cardNumber));
}
public void addCardID(String cardNumber) {
idCards.add(cardNumber);
}
public String toString() {
String allInfo = "Cash:" + totalCash + "$ ";
if(cards.size() >= 1) {
for (int i = 0; i < cards.size(); i++) {
allInfo += cards.get(i).toString();
allInfo += " ";
}
}
return allInfo;
}
}
----------------------------------------------------------------------------------
CreditCard.java
----------------------------------------------
public class CreditCard extends ChargeCard{
private double overdraftLimit;
private double feesIncurred;
CreditCard(String name, String cardNumber) {
super(name, cardNumber);
balance = 1000;
}
public void purchase(double pay) {
balance -= pay;
}
public void increaseOverdraftLimit() {
overdraftLimit += 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: " + overdraftLimit + "$" + " feesIncurred: " + feesIncurred + "$";
}
public double getOverdraftLimit() {
return overdraftLimit;
}
public void setOverdraftLimit(double overdraftLimit) {
this.overdraftLimit = overdraftLimit;
}
}
-----------------------------------------------------------------------------------------
DebitCard.java
----------------------------
public class DebitCard extends ChargeCard {
private double overdraftLimit;
private double overdraftFee;
private double feesIncurred;
DebitCard(String name, String cardNumber) {
super(name, cardNumber);
this.overdraftFee = 50;
this.overdraftLimit = 100;
}
public double getFeesIncurred() {
return feesIncurred;
}
public double getOverdraftFee() {
return overdraftFee;
}
public double getOverdraftLimit() {
return overdraftLimit;
}
public void purchase(double pay) {
if (pay <= balance)
balance -= pay;
else if (pay > balance) {
if (pay <= (balance + overdraftLimit + overdraftFee))
balance -= pay + overdraftFee;
}
}
public void increaseOverdraftLimit() {
overdraftLimit += 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: " + overdraftLimit + "$" + " overdraftFee: " + overdraftFee + "$"
+ " feesIncurred: " + feesIncurred + "$";
}
}
---------------------------------------------------------------------------------------
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 purchase(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 + "$";
}
}

Thankyou,please like it.