Question
1.5. Write a tester programthat adds two objects of different subclasses of Card to a Billfold object. Test the results of the formatCards methods. What
1.5. Write a tester programthat 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?
1.6. Explain why the output of your BillfoldTester program demonstrates polymorphism.
1.7 The Card superclass defines a method isExpired, which always returns false. This method was overridden in DriverLicense with an identical body, but the method is not appropriate for the driver license. Supply a method body for DriverLicense.isExpired() that checks whether the driver license is already expired (i.e., the expiration year is less than the current year).
To work with dates, you can use the methods and constants supplied in abstract class Calendar which are inherited by the concrete class GregorianCalendar. You create a Calendar as follows:
GregorianCalendar calendar = new GregorianCalendar();
Then, you can obtain the current year using the constant Calendar.YEAR and method get in GregorianCalendar. The constant indicates that the method should return the current year. By comparing the returned value with the expYear field in DriverLicense, you can determine if the card is expired. The code below will retrieve the current year.
calendar.get(Calendar.YEAR)
1.8. Add a method getExpiredCardCount, which counts the number of expired cards in the billfold, to the Billfold class.
1.10. Write a BillfoldTester class that populates a billfold with a phone card and an expired driver license. Then call the getExpiredCardCount method. Run your tester to verify that your method works correctly.
What is your tester class?
1.11. Implement toString methods for the Card class and its three subclasses. The methods should print:
the name of the class
the values of all instance variables (including inherited instance variables)
Typical formats are:
Card[name=Edsger W. Dijkstra]
CallingCard[name=Bjarne Stroustrup][number=4156646425,pin=2234]
Write the code for your toString methods.
1.12. Implement equals methods for the Card class and its three subclasses. Cards are the same if the objects belong to the same class, and if the names and other information (such as the expiration year for
driver licenses) match.
Give the code for your equals methods.
1.13. Change the Card class and give protected access to name. Would that change simplify the toString method of the CallingCard class? How?
Is this change advisable?
1. Have the exercise above required you to implement a software design specification for an
appropriate development environment.
a. True
b. False
2. Have the lab exercises provided you to acquire instruction on the proper documentation of
source code?
a. True
b. False (If not do you think that you need to provide documentation for any
implementation & design of any software.)
3. Provide a detail example that you have acquired the knowledge (it means: please provide
step by step processes that you take) to design and apply relevant software testing procedures.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started