By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,784 Members | 1,307 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,784 IT Pros & Developers. It's quick & easy.

Need help with a Inheritance, Billfold program

P: 1
Hello
I'm having a little trouble with a programming assignment for a class. Everything compiles fine but I'm not getting the output that I want. It seems that my tester class is calling the format() from my Card class, however I want it to call the format() from the IDCard, CallingCard, and DriverLicense classes. I included all of my code below. I've read that there are better ways to write this program by making the Card class abstract, but this class was provided by my instructor and should remain the same. Any help is appreciated. Thank you.

Expand|Select|Wrap|Line Numbers
  1. public class Card
  2. {
  3. private String name;
  4. public Card()
  5. {
  6. name = "";
  7. }
  8. public Card(String n)
  9. {
  10. name = n;
  11. }
  12. public String getName()
  13. {
  14. return name;
  15. }
  16. public boolean isExpired()
  17. {
  18. return false;
  19. }
  20. public String format()
  21. {
  22. return "Card holder: " + name;
  23. }
  24. }
Expand|Select|Wrap|Line Numbers
  1. public class Card
  2. {
  3. private String name;
  4. public Card()
  5. {
  6. name = "";
  7. }
  8. public Card(String n)
  9. {
  10. name = n;
  11. }
  12. public String getName()
  13. {
  14. return name;
  15. }
  16. public boolean isExpired()
  17. {
  18. return false;
  19. }
  20. public String format()
  21. {
  22. return "Card holder: " + name;
  23. }
  24. }
Expand|Select|Wrap|Line Numbers
  1. public class Card
  2. {
  3. private String name;
  4. public Card()
  5. {
  6. name = "";
  7. }
  8. public Card(String n)
  9. {
  10. name = n;
  11. }
  12. public String getName()
  13. {
  14. return name;
  15. }
  16. public boolean isExpired()
  17. {
  18. return false;
  19. }
  20. public String format()
  21. {
  22. return "Card holder: " + name;
  23. }
  24. }
Expand|Select|Wrap|Line Numbers
  1. public class IDCard extends Card
  2. {
  3.     private int idNumber;
  4.  
  5.     public IDCard(String n, int id)
  6.     {   super(n);
  7.         idNumber = id;
  8.     }
  9.  
  10.     public String format()
  11.     {
  12.         return "Card holder: " + idNumber;
  13.     }
  14.  
  15. }
  16.  
Expand|Select|Wrap|Line Numbers
  1. public class IDCard extends Card
  2. {
  3.     private int idNumber;
  4.  
  5.     public IDCard(String n, int id)
  6.     {   super(n);
  7.         idNumber = id;
  8.     }
  9.  
  10.     public String format()
  11.     {
  12.         return "Card holder: " + idNumber;
  13.     }
  14.  
  15. }
  16.  
Expand|Select|Wrap|Line Numbers
  1. public class BillfoldTester
  2. {   
  3.     public static void main(String[] args)
  4.     {   
  5.         Billfold b1 = new Billfold();
  6.         Card cc = new CallingCard("Jennifer", 11, 24);
  7.         Card dl = new DriverLicense("Tom", 2004);
  8.         Card idc = new IDCard("Mark", 832);
  9.  
  10.         b1.addCard(dl);
  11.         b1.addCard(idc);
  12.         b1.addCard(cc);
  13.  
  14.         System.out.println(b1.formatCards());
  15.     }
  16. }
  17.  
Mar 1 '13 #1
Share this Question
Share on Google+
1 Reply


10K+
P: 13,264
What does the formatCards method do?
Mar 6 '13 #2

Post your reply

Sign in to post your reply or Sign up for a free account.