question about writing a toString method
I need to write the following program and It seems to be moving along nicely, although for some reason i dont understand what is needed from me on the line "Write a toString method in each class that prints out the name of the subclass using the getClass() method of class Object followed by the instance variables, each preceded by a description."
i have read about a toString method and understand more or less what it is, but i dont really get how i need to incorporate that into my program.
just in case attaching the FULL (its a bit of a read) assignment (NOTE: i dont need help with the entire assignment, i am doing it well on my own, but the toString method i do need help with, so if you have comments I would greatly appreciate them)
Write a toString method in each class that prints out the name of the subclass using the getClass() method of class Object followed by the instance variables, each preceded by a description.
Create a class named MetroCard that can keep track of its balance and expiration date. Each MetroCard has a unique serial number.
* There are different types of metro cards:
o Pay-per ride
o Unlimited Ride
o Reduced Fare (half fare) for senior citizens or disabled individuals, stores the owner's name
* All metro cards have common characteristics. They should inherit from a common base class. Should the base class be an interface or abstract since if only specialized versions exist?
Create a class that represents the card reader. It can deduct one fare from the MetroCard. Consider:
* What if there is an unexpired transfer that can be used? (Remember: transfers are only valid on a different route within a specified amount of time.)
* What if the balance is insufficient?
* Plan for rate changes. Should the fare be a literal or a variable?
Create another class that represents the metro card vending machine. It should have the capacity to create new MetroCards and refill existing cards.
* New cards can have a choice of dollar amounts ($4, $10, $20, etc.). The amount paid is not necessarily the same as the initial balance of the MetroCard (i.e., $10 might give you $12).
* When refilling an old card, the user can either enter an arbitrary amount OR choose from a list of dollar amounts. If the user enters a dollar amount not on the list, the card's balance is increased by the amount paid. If the user chooses an amount from the list, he might receive a bonus (as in a new card).
* Remember that the rates change periodically. Develop the class in a way that supports this feature.