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

7.1 Consider using the following Card class. Use this class as a superclass to i

ID: 3765712 • Letter: 7

Question

7.1 Consider using the following Card class.

Use this class as a superclass to implement a hierarchy of related classes:

Class:

Data:

IDCard

ID number

CallingCard

Card number, PIN

DriverLicense

Expiration year

Write declarations for each of the subclasses. For each subclass, supply private instance variables. Leave the bodies of the constructors and the format methods blank for now.

7.2 Implement constructors for each of the three subclasses. Each constructor should call the superclass constructor to set the name. Here is one example:

7.3 Replace the implementation of the format method for the three subclasses. The methods should produce a formatted description of the card details. The subclass methods should call the superclass format method to get the formatted name of the cardholder.

7.4 Devise another class, Billfold, which contains slots for two cards, card1 and card2, a method void addCard(Card) and a method String formatCards().

The addCard method checks whether card1 is null. If so, it sets card1 to the new card. If not, it checks card2. If both cards are set already, the method has no effect.

Of course, formatCards invokes the format method on each non-null card and produces a string with the format

[card1|card2]

What is your Billfold class?

7.2 Write a tester program that adds two objects of different subclasses of Card to a Billfold object. Test the results of the formatCards methods.

What is the code for your BillfoldTester class?

Class:

Data:

IDCard

ID number

CallingCard

Card number, PIN

DriverLicense

Expiration year

Explanation / Answer

Answer:

Note: I solved the first part

IDCard:

public class IDCard extends Card

{

   //variable

   private String IDNumber;

   //constructor

public IDCard(String n1, String idNumber)

   {

       super(n1);

       IDNumber = idNumber;

   }

   //method format

   public String format()

   {

       return super.format() + " IDCardNumber: " + IDNumber;

   }

DebitCard

public class DebitCard extends Card

{

   //variable

   private String cardNumber;

   private String pin;

   //constructor

   public DebitCard(String n1, String cardNum, String pinVal)

   {

       //super methof

       super(n1);

     this.cardNumber = cardNum;

       this.pin = pinVal;

   }

   //string format

   public String format()

   {

       return super.format() + " NUMBER OF CARD: " +

cardNumber + " PinVALUE: " + pin;

   }

}

}

DriverLicense class

//driverclass

public class DriverLicense extends Card

{

     //variable declarations

private int expirationYear;

//constructors

   public DriverLicense(String n1, int expirationYearOF)

{

       super(n1);

       this.expirationYear = expirationYearOF;

   }

   //method format

   public String format()

{

       return super.format() + " Year Of Expiration: " +

     expirationYear;

   }

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote