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

please add comments CSC 201 Computer Science I Inheritance Lab Create a class Ca

ID: 3713845 • Letter: P

Question

please add comments

CSC 201 Computer Science I Inheritance Lab Create a class Card" that represents a general type of membership card. The "Card" class will have one instance variable called name which will be of type String. Write a default constructor which sets name to (an empty String): Write a parameterized constructor which receives a single String parameter and sets name to this given parameter. The "Card" class must also implement the following methods which always returns false which returns the value stored in the name instance variable. And which returns the String "Card Holder: "concatenated with the name instance variable. public boolean isExpired DI public String getName ) f public String cardTostring ) ( Create a class "DebitCard" which subclasses the "Card" class. The "DebitCard" class will have two instance variables of type int: cardNumber & pin Write a default constructor which calls the constructor of its superclass, passing it the string 'Jane Doe" The default constructor must also initialize cardNumber to 00000000 and pin to 0 Write a parameterized constructor which takes three parameters: A String for the card name, an int for the cardNumber, and an int for the card pin. The parameterized constructor calls the constructor of its superclass, passing it the name parameter. The parameterized constructor must also initialize cardNumber and pin instance variables using the passed parameters. The "DebitCard" class must also implement the following methods: A getter for the cardNumber instance variable A function isPin which takes a single int parameter and returns true (a Boolean value if the passed int parameter is equal to the pin instance variable and false if it is not .A cardToString method which calls the super class's cardToString method and concatenates it with" Card Number: "and the value of the cardNumber instance variable. Create a class IDCard" which subclasses the "Card" class. The "IDCard" class will have one instance variable called "IDNumber" which will be of type int. Write a default constructor which passes the String "Jane Smith" to the superclass constructor and sets IDNumber to 0 Write a parameterized constructor which takes a String for name and an int for anlDNumber, passing the superclass constructor the name parameter and initalizing the IDNumber instance variable using the passed anIDNumber parameter Write a getter method for IDNumber Write a cardToString method which calls the super class's cardToString method and . . concatenates it with " ID Number: "and the value of the IDNumber instance variable

Explanation / Answer


//Card class
public class Card
{
//String instance variable
String name;
//default constructor
public Card()
{
//Initialize the name with ""
name = "";
}
//Parameterized constructor
public Card(String name)
{
//initialize name with passed name
this.name = name;
}
//method which always return false
public boolean isExpired()
{
return false;
}
//getter method which returns name
public String getName()
{
return name;
}
//cardToString which append cardHolder and name
public String cardToString()
{
return "Card Holder"+name;
}
  
}
//DebitCard class which extends the Card class
class DebitCard extends Card
{
//instance variables
int cardNumber;
int pin;
//default constructor
public DebitCard()
{
//invoke super class constructor
super("Jane Doe");
cardNumber = 00000000;
pin = 0;
}
//parameterized constructor
public DebitCard(String name,int cardNumber,int pin)
{
//invoke super class constructor
super(name);
this.cardNumber = cardNumber;
this.pin = pin;
}
//method returns cardnumber
public int getCardNumber()
{
return cardNumber;
}
//method returns boolean based n provided pin is correct or not
public boolean pinCheck(int pin)
{
return (this.pin == pin);
}
//cardToString which append super class string with card Number
public String cardToString()
{
return super.cardToString()+"Card Number "+cardNumber;
}
  
}
//IDCard class which extends Card
class IDCard extends Card
{
int IDNumber;
//default constructor
public IDCard()
{
//call super class constructor
super("Jane Smith");
IDNumber = 0;
}
//parameterized constructor
public IDCard(String name,int IDNumber)
{
//call super class constructor
super(name);
this.IDNumber = IDNumber;
}
//method which returns IDnumber
public int getIDNumber()
{
return IDNumber;
}
//method which concat super class string with IDnumber
public String cardToString()
{
return super.cardToString()+"ID Number "+IDNumber;
}
  
}
//DriversLicense class which extends IDCard
class DriversLicense extends IDCard
{
int expirationYear;
//default constructor
public DriversLicense()
{
super();
expirationYear = 1969;
}
//parameterized constructor
public DriversLicense(int year,String name,int IDNumber)
{
//call super class constructor
super(name,IDNumber);
expirationYear = year;
}
//method which return expirationYear
public int getExpirationYear()
{
return expirationYear;
}
//method returns boolean based on the expire date is greater than or equals 2018
public boolean isExpired()
{
return expirationYear >= 2018;
}
//method which concat super class string with expirationYear
public String cardToString()
{
return super.cardToString()+"Expiration Year "+expirationYear;
}
}