ok, so we're to right this program(in bluej) that consists of a few classes that will ultimately simulate a simple billfold(consis ting of credit cards) a main card class, a drivers license, an id card, and a calling card. Now, i'm not coming to you guys to finish my program, i'm coming to you guys so i can understand it(as it is my major, as of 2 days ago)
sorry for all the code, i thought i might as well post it all, the problem is the isExpired class(as far as i know) I want to overwrite the method from card with the one in driversLicense, but to no avail have i succeeded in getting any result other than false... am i going about this all wrong? this whole inheritance is quite confusing and my teacher keeps postponing his office hours. any and all help i get is greatly appreciated, i just beg you to keep in mind, I have had 1 beginning computer course(bits bytes and all that crap) and am(as for this semester) in 2 intro classes(object oriented java) and intro 2 computing c++(object oriented also.) so my knowledge isn't what you could call vast by any means. thank you for your help
Code:
class Card
{ public String name;
public Card()
{ name = "";}
public Card(String n)
{ name = n;}
public boolean isExpired()
{ return false;}
public void print()
{ System.out.println("Card holder: " + name);}
public String toString()
{ String temp = "Card[name=" + name + "]";
return temp;}
public boolean equals(Card x)
{ if(this.name == x.name)
{ return true;}
else if(this.name != x.name)
{ return false;}
else
{ System.out.println("Error, Card.equals(method)");
return false;}}
public Card Clone()
{ Card x = new Card(this.name);
return x;}
}
Code:
class Billfold extends Card
{ Card card1;
Card card2;
public void addCard(Card x)
{ if(card1 == null)
{ card1 = new Card(x.name);}
else if(card1 != null)
{ if(card2 == null)
{ card2 = new Card(x.name);}}}
public void printCards()
{ if(card1 != null)
{ if(card2 != null)
{ card1.print();
card2.print();}
else
{ card1.print();}}
else
{ return;}}
public void printExpiredCards()
{ if(card1 != null && card2 != null)
{ if(card1.isExpired() == true && card2.isExpired() == false)
{ System.out.println("Card 1 has expired, but Card 2 has not.");}
else if(card1.isExpired() == false && card2.isExpired() == false)
{ System.out.println("Neither Card has expired.");}
else if(card1.isExpired() == false && card2.isExpired() == true)
{ System.out.println("Card 1 has not expired, but Card 2 has.");}
else if(card1.isExpired() == true && card2.isExpired() == true)
{ System.out.println("Both Cards have expired.");}
else
{ System.out.println("Error");}}
else if(card1 != null && card2 == null)
{ if(card1.isExpired() == true)
{ System.out.println("Card 1 has expired.");}
else if(card1.isExpired() == false)
{ System.out.println("Card 1 has not expired.");}
else
{ System.out.println("Error");}}
else if(card1 == null)
{ System.out.println("No cards available.");}
else
{ System.out.println("Error");}}
}
Code:
class driversLicense extends Card
{ private int expYear;
driversLicense(String name, int exp)
{ super(name);
expYear = exp;}
public boolean isExpired()
{ if(expYear >= 2006)
{ return false;}
else
return true;}
}
Code:
class CallingCard extends Card
{ private int cardNumber;
private int PIN;
CallingCard(String name, int cn, int pin)
{ super(name);
cardNumber = cn;
PIN = pin;}
}
Code:
class IDCard extends Card
{ private int idNumber;
IDCard(String name, int id)
{ super(name);
idNumber = id;}
}
Code:
class BillfoldTester
{ public static void main(String[] args)
{ Billfold b1 = new Billfold();
Card dl = new driversLicense("Bryan", 2005);
Card idc = new IDCard("Dwayne", 6404);
Card cc = new CallingCard("Meghan", 12, 21);
b1.addCard(cc);
b1.addCard(idc);
b1.addCard(dl);
b1.printExpiredCards();
b1.printCards();
Card x = dl.Clone();
x.print();
System.out.println("Is dl = x? " +dl.equals(x));
System.out.println(dl.toString());}
}
Comment