Last week, we had the author of TDD for a Shopping Website LiveProject. Friday at 11am Ranch time, Steven Solomon will be hosting a live TDD session just for us. See for the agenda and registration link
Last week, we had the author of TDD for a Shopping Website LiveProject. Friday at 11am Ranch time, Steven Solomon will be hosting a live TDD session just for us. See for the agenda and registration link

# Lisa Smith

Ranch Hand
since Sep 24, 2002
Cows and Likes
Cows
0
In last 30 days
0
Total given
0
Likes
0
0
Total given
0
Given in last 30 days
0
Scavenger Hunt
Ranch Hand Scavenger Hunt
Greenhorn Scavenger Hunt

## Recent posts by Lisa Smith

That was the 1st thing I thought of and I stil got the same error. Any other suggestions ?
18 years ago
THIS IS DECK
public class BlackjackHand extends Hand {

public int getBlackjackValue() {
// Returns the value of this hand for the
// game of Blackjack.
int val; // The value computed for the hand.
boolean ace; // This will be set to true if the
// hand contains an ace.
int cards; // Number of cards in the hand.
val = 0;
ace = false;
cards = getCardCount();
for ( int i = 0; i < cards; i++ ) {
// Add the value of the i-th card in the hand.
Card card; // The i-th card;
int cardVal; // The blackjack value of the i-th card.
card = getCard(i);
cardVal = card.getValue(); // The normal value, 1 to 13.
if (cardVal > 10) {
cardVal = 10; // For a Jack, Queen, or King.
}
if (cardVal == 1) {
ace = true; // There is at least one ace.
}
val = val + cardVal;
}
// Now, val is the value of the hand, counting any ace as 1.
// If there is an ace, and if changing its value from 1 to
// 11 would leave the score less than or equal to 21,
// then do so by adding the extra 10 points to val.
if ( ace == true && val + 10 <= 21 )
val = val + 10;
return val;
} // end getBlackjackValue()

} // end class BlackjackHand
also card

18 years ago
I don't get it. Should I write this code within the class and where or is used at the command line?
18 years ago
what is a stack trace and how would i use it?
18 years ago
Exception in thread "main" java.lang.NoSuchMethodError: main
I cannot figure out wht this is not working.
Above is the error below is the code. It compiles but I get this error
18 years ago
Thanks
18 years ago
I am writing he shoe, deck and card class for blackjack. I am in a slum trying to test the code. i have written a testclass but I am not getting any ouput.I was wondering if you could look at my classes and tell me what I am doing wrong.

public class Card {
public final static int SPADES = 0,
HEARTS = 1,
DIAMONDS = 2,
CLUBS = 3;

public final static int ACE = 1,
JACK = 11,
QUEEN = 12,
KING = 13;

private final int suit;

private final int value;

public Card(int theValue, int theSuit) {

value = theValue;
suit = theSuit;
}

public int getSuit() {

return suit;
}

public int getValue() {

return value;
}

public String SuittoString() {

switch ( suit ) {
case HEARTS: return "Hearts";
case DIAMONDS: return "Diamonds";
case CLUBS: return "Clubs";
default: return "Invalid?";
}
}

public String getSValue() {

// If the card's value is invalid, "Invalid?" is returned.
switch ( value ) {
case 1: return "Ace";
case 2: return "2";
case 3: return "3";
case 4: return "4";
case 5: return "5";
case 6: return "6";
case 7: return "7";
case 8: return "8";
case 9: return "9";
case 10: return "10";
case 11: return "Jack";
case 12: return "Queen";
case 13: return "King";
default: return "Invalid?";
}
}

public String toString() {
// Return a String representation of this card, such as
// "10 of Hearts" or "Queen of Spades".
return getSValue() + " of " + SuittoString();
}

} // end class Card

Shoe class

public class CardTest {

//public static void main(String[] args) {

// A card dealt from the deck.

CardTest deck = new CardTest(); // Create the deck.

deck.shuffle();
deck.drawCard();

System.println("Deck contains:");
for ( int i = 0; i <= deck; i++ ) {
// Get a card from the deck, print it out,

card = Card.getValue();

System.println(" " + card);
}

}
}
[CODE]
If you could give me some insight on what i am doing wrong I would be truly grateful.
18 years ago
Thanks I get what you are saying about that. Now my problem is implementing it in StudentTest. Here are my errors
StudentTest.java:42: cannot resolve symbol
symbol : method insertStudent ()
location: class StudentRecord
stud.insertStudent();
^
StudentTest.java:43: cannot resolve symbol
symbol : method insertStudent ()
location: class StudentRecord
stud1.insertStudent();
^
StudentTest.java:44: cannot resolve symbol
symbol : method insertStudent ()
location: class StudentRecord
stud2.insertStudent();
^
StudentTest.java:47: cannot resolve symbol
symbol : variable sort
location: class StudentTest
sort.table();
^
StudentTest.java:49: cannot resolve symbol
symbol : variable table
location: class StudentTest
table.print();
^
I know it has something to do with the methods that I have created, I just don't know what.
My code again

/**
*
*
*
*
*/
public class StudentRecord
{

final int arraySize = 25;
// Private instance varibles
private final String name; // student name
int Count; // number of grades per student
// Constructor
{
throw new IllegalArgumentException("Grade array exceeds fixed size");
}
name = studentName ;
} StudentRecord(String studentName)
{
//Call the two arg constructor with an empty grade array
this(studentName, new int[0]); }
public int compareTo(Object obj)
{
return this.name.compareTo(((StudentRecord) obj).name);
}
public void print ()
{
System.out.println ( "Name: " + name );
for ( int j=0; j < Count ; j++ )
System.out.println ( " grade " + j + ": " + grades[ j ] );
}
{
if ( Count < arraySize )
Count ++ ;
}
public int average ( )
{
int sum = 0 ;
for ( int j=0; j < Count; j++ )
sum += grades[ j ] ;
return sum / Count ;
}

}
Student Test

[CODE]
class StudentTest
{
public static void main ( String[] args )
{
// create a student object
StudentRecord stud = new StudentRecord( "Nate" ) ;
StudentRecord stud1 = new StudentRecord( "Yvette" ) ;
StudentRecord stud2 = new StudentRecord( "Maria" ) ;

stud.print() ;
stud1.print() ;
stud2.print() ;

stud.insertStudent();
stud1.insertStudent();
stud2.insertStudent();

sort.table();
table.print();
System.out.println( "Average grade: " + stud.average() );
}
}
How can I print this alphabetically after they are averaged?
[CODE]
18 years ago
I have Student record working again and gradebook compiled. Can you look at grade book and let me know if the Studentrecord is going there. If so how do I sort it alphabetically and print it out?
I tried using util-array sort but I get an error. Should I use a compare method before call array sort.
18 years ago
So should I put the same constructor in gradebook?
18 years ago
I di exactly what you recommended but when I used my test class i recieved this error.
C:\javas>java StudentTest
Exception in thread "main" java.lang.NoSuchMethodError: StudentRecord.<init>(Lja
va/lang/String V
at StudentTest.main(StudentTest.java:7)
Here are my changes!

This is my test code:

It worked before and know I don't understand why it is not working.
18 years ago
I am trying to create two classes, 1 called Student record and 1 called grade book. In student record I am collecting tha name and grades of the student . In gradebook I'm computing the average and sorting names alphabetically.I have computed the average in Student record because I cannot get gradebook to work. I will cut and paste the code when I get gradebook to work. I am trying to compile grade book but I get this error
symbol : constructor StudentRecord (java.lang.String,int[])
location: class StudentRecord
^
1 error

This is studentrecord
18 years ago
I tried that but i got an error. This is what wrote:
g.drawstring("Yvette Hobbs" x-4, y-4, 50,50);
Is this the proper syntax?
19 years ago
I thought I needed the coordinates of where the mouse was clicked, so x and y would be set to the event. What should I use?
19 years ago
Here are my requirements:
Create a wrapper HTML file that opens up a 300 x 200 window.
The applet window should have a black background. Initially, the window contains a String representing your name printed at position (50, 50) of the window. [For example, my program would print Amber Settle at position (50, 50)]. Your name should be displayed in cyan when the window first appears.
When the user clicks the mouse anywhere in the applet window, your name is redrawn at that position in the window.
The first time the name is redrawn it should be displayed in pink. The second time is is redrawn it should be displayed in cyan again. This alternation of colors should continue indefinitely. [In particular, every nth time it is redrawn, where n is odd, it should appear in pink. Every nth time it is redrawn, where n is even, it should appear in cyan].
To achieve this behavior, you will have to write a listener class that implements MouseListener. Within the listener's mouseClicked method, use the getX() and getY() methods of the event to determine where the click occurred. You should then reset the instance variables representing the current position in the window to those values. To alternate colors you should have an instance variable that indicates the number of times the name has been redrawn. Set it to 0 initially. Whenever the mouse is clicked, it should be incremented. Whenever the number of times it has been redrawn is even, display the name in cyan. If it is odd, display it in pink.
When I open the Applet it opens in pink and when i click it won't move. can you give me some advice?
19 years ago