UGH1: The BlackJack class
You have used Card class for a while. Please create a BlackJack which extends Card class. You want to override one method: getValue(). getValue will return 10 if the value of the card is greater than 10.
public class BlackJack extends Card {
public BlackJack(int s, int v) {
super(s, v);
}
public int getValue() {
if (super.getValue() > 10) { return 10; }
else return super.getValue();
}
}
UGH2: Use of sub class, BlackJack
Please write a BlackJackTest class to test your BlackJack class.
public class BlackJackTest {
Card mycard = new BlackJack(3,5); ....
... = mycard.getvalue();
}
UGH3: Compare your BlackJack class with the following class which uses composition instead of inheritance.
The difference is in style - and more robustness in the inheritance implementation.
public class BlackJackCom {
// an example to compare Inheritance and Composition
// we can still use Composition to reuse Card class
Card aCard;
public BlackJack(int v, int s) {
aCard = new Card(v,s);
}//constructor
public BlackJack(Card c) {
aCard = c;
}//constructor
public int getValue(){
int cardValue = aCard.getValue();
if (cardValue > 10)
cardValue = 10;
return cardValue;
} //getValue
// do I have to write this method?
public int getSuit(){
return aCard.getSuit();
} //getSuit
// do I have to write this method?
public String toString(){
return aCard.toString();
} //toString
} //BlackJackCom