Consider using the following Card class that represents a general type of member
ID: 653430 • Letter: C
Question
Consider using the following Card class that represents a general type of membership card.
public class Card{
private String name;
public Card(){
name = "";
}
public Card(String n) {
name = n;
}
public String getName(){
return name;
}
public boolean isExpired(){
return false;
}
public String format(){
return "Card holder: " + name;
}
}
Use the Card class as a superclass to implement this hierarchy of related classes:
Write declarations for each of the subclasses. Note that IDCard and DebitCard are subclasses of Card, and DriverLicense is a subclass of IDCard.
Class
Data
IDCard
ID number
DebitCard
Card number, PIN
DriverLicense
Expiration year
For each subclass, supply private instance variables as listed in the table shown above. Implement constructors for each of the three subclasses. Each constructor should call the superclass constructor to set the name. Here is one example:
public IDCard(String n, String id){
super(n);
idNumber = id;
}
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.
Upload the files from this assignment - IDCard.java, DebitCard.java, and DriverLicense.java .
Class
Data
IDCard
ID number
DebitCard
Card number, PIN
DriverLicense
Expiration year
Explanation / Answer
1) IDCard.java
package chegg;
public class IDCard extends Card {
private String IDNumber;
public IDCard(String n, String iDNumber) {
super(n);
IDNumber = iDNumber;
}
public String format() {
return super.format() + " IDNumber: " + IDNumber;
}
2) DebitCard.java
package chegg;
public class DebitCard extends Card {
private String cardNumber;
private String pin;
public DebitCard(String n, String cardNumber, String pin) {
super(n);
this.cardNumber = cardNumber;
this.pin = pin;
}
public String format() {
return super.format() + " CardNumber: " + cardNumber + " Pin: " + pin;
}
}
}
3) DriverLicense.java
package chegg;
public class DriverLicense extends Card {
private int expirationYear;
public DriverLicense(String n, int expirationYear) {
super(n);
this.expirationYear = expirationYear;
}
public String format() {
return super.format() + " ExpirationYear: " + expirationYear;
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.