The Artima Developer Community
Sponsored Link

Java Answers Forum
using "super" and extending other classes

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
jake

Posts: 83
Nickname: onorok
Registered: May, 2002

using "super" and extending other classes Posted: Jun 4, 2002 6:49 PM
Reply to this message Reply
Advertisement
I was wondering if anyone could simply explane how this works. I have these two programs and I am having trouble understanding them.
My hand class makes a hand of cards:

import Card;
import DeckOfCards;
import java.util.Vector;

public class Hand
{
public Vector Handofcards;

public Hand(Vector v)
{
Handofcards=v;
}


//Displays a hand of cards.
public void displayHand()
{
System.out.println(Handofcards);
System.out.println();
}


//Takes a card out of the hand, tells you what card was removed,
//then prints the hand without the card.
public Card disCard(int index)
{
Card temp=(Card)Handofcards.remove(0);
return temp;

}


public void addCard(Card c)
{
Handofcards.addElement(c);

}


//Displays the number of cards you have in your hand.
public int getNumCards()
{
System.out.println("Number of cards in hand");
return Handofcards.size();
}

}

My blackjack has these two methods that just get the score of the hand.

public class Blackjack extends Hand
{
//--------------------------------------------------------------------
//Holds the score keeping class for the BlackJack game
//--------------------------------------------------------------------
public Blackjack()
{
super();
}

public int score()
{
int scoretotal=0;
int face=10;
int ace=11;
for(int count=0;count<Handofcards.size();count++)
{
Card temp=(Card)Handofcards.elementAt(count);
if(temp.value==10)
{
scoretotal+=face;
}
else if(temp.value==1)
{
scoretotal+=ace;
}
else
scoretotal+=temp.value;
}
return scoretotal;
}

public boolean isBusted()
{
if(score()>21)
return true;
else
return false;
}
}

Any help would be appreciated
thank you.

Topic: Generate Number And Character Previous Topic   Next Topic Topic: drag and drop in applets

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use