Question: For this question, there are CreditCard and DriversLicense objects which inherit from a generic Card class. Complete the following: /** * A class for id-type

For this question, there are CreditCard and DriversLicense objects which inherit from a generic Card class. Complete the following:

/** * A class for id-type cards. Complete the following tasks: * * - Add accessor methods for each of the instance variables */ public class Card { private String name; private String id; private int expiryYear; public Card(String name, String id, int expiryYear) { this.name = name; this.id = id; this.expiryYear = expiryYear; } // Add accessor methods called getName, getID, getExpiryYear //-----------Start below here. To do: approximate lines of code = 6 // //-----------------End here. Please do not remove this comment. Reminder: no changes outside the todo regions. } 

_______________________________________________

/** * A class for a credit card which extends Card. Complete the following tasks * * - The constructor * - Complete the purchase method to remove the given amount * - Complete the payOffBalance method to reset the balance * - Complete the balance accessor method */ public class CreditCard extends Card { private double limit; private double balance; // Complete the constructor to call the parent constructor using super and // set the limit and balance // The balance should be initialized to the limit public CreditCard(String name, String id, int expiryYear, double limit) { //-----------Start below here. To do: approximate lines of code = 3 // //-----------------End here. Please do not remove this comment. Reminder: no changes outside the todo regions. } // Decrease the given amount from the balance. If the amount exceeds the balance, // the balance should not be changed and "Insufficient funds remaining" should // be printed. public void purchase(double amount) { //-----------Start below here. To do: approximate lines of code = 4 // //-----------------End here. Please do not remove this comment. Reminder: no changes outside the todo regions. } // Rest the balance to the credit card limit public void payOffBalance() { //-----------Start below here. To do: approximate lines of code = 1 // //-----------------End here. Please do not remove this comment. Reminder: no changes outside the todo regions. } // Gets the current balance public double getBalance() { //-----------Start below here. To do: approximate lines of code = 1 // //-----------------End here. Please do not remove this comment. Reminder: no changes outside the todo regions. } } 

____________________________________________

/** * A class for a driver's license. Complete the following tasks * * - An accessor for the license type * - A method that updates the license type */ public class DriversLicense extends Card { public enum LicenseType { G1, G2, G} private LicenseType type; public DriversLicense(String name, String id, int expiryYear, LicenseType type) { super(name, id, expiryYear); this.type = type; } // Add an accessor method called getLicenseType //-----------Start below here. To do: approximate lines of code = 2 // //-----------------End here. Please do not remove this comment. Reminder: no changes outside the todo regions. // Add a method called updateLicenseType which takes in a license type and stores it //-----------Start below here. To do: approximate lines of code = 2 // //-----------------End here. Please do not remove this comment. Reminder: no changes outside the todo regions. } 

____________________________________________

/** * Tests the card class. Complete the two getCardInfo methods, one that returns * a String representation of a CreditCard and one that returns a String * representation of a Driver's License. */ public class CardTester { // For a given credit card, returns a string of the form // // "Name: Tom Jones, ID: 123, Expiry: 2025, Balance: 5000" public static String getCardInfo(CreditCard card) { //-----------Start below here. To do: approximate lines of code = 2 // //-----------------End here. Please do not remove this comment. Reminder: no changes outside the todo regions. } // For a given driver's license, returns a string of the form // // "Name: Tom Jones, ID: 123, Expiry: 2025, Type: G" // // HINT: Remember to handle the different license types with different strings public static String getCardInfo(DriversLicense card) { //-----------Start below here. To do: approximate lines of code = 9 // //-----------------End here. Please do not remove this comment. Reminder: no changes outside the todo regions. } public static void main(String[] args) { CreditCard credit = new CreditCard("Bob Turner", "1023431", 2023, 15000.0); DriversLicense license = new DriversLicense("Tim Jones", "V54 98H 763", 2024, DriversLicense.LicenseType.G1); // Test constructor and getCardInfo methods System.out.println(getCardInfo(credit)); System.out.println("Expected: Name: Bob Turner, ID: 1023431, Expiry: 2023, Balance: 15000.0"); System.out.println(getCardInfo(license)); System.out.println("Expected: Name: Tim Jones, ID: V54 98H 763, Expiry: 2024, Type: G1"); // Test updateLicenseType license.updateLicenseType(DriversLicense.LicenseType.G2); System.out.println(getCardInfo(license)); System.out.println("Expected: Name: Tim Jones, ID: V54 98H 763, Expiry: 2024, Type: G2"); // Test purchase credit.purchase(10000); System.out.println(getCardInfo(credit)); System.out.println("Expected: Name: Bob Turner, ID: 1023431, Expiry: 2023, Balance: 5000.0"); // Test purchase overdraft credit.purchase(10000); System.out.println("Expected: Insufficient funds remaining"); System.out.println(getCardInfo(credit)); System.out.println("Expected: Name: Bob Turner, ID: 1023431, Expiry: 2023, Balance: 5000.0"); // Test pay off balance credit.payOffBalance(); System.out.println(getCardInfo(credit)); System.out.println("Expected: Name: Bob Turner, ID: 1023431, Expiry: 2023, Balance: 15000.0"); } } 

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!