This week's book giveaway is in the Kotlin forum.
We're giving away four copies of Kotlin in Action and have Dmitry Jemerov & Svetlana Isakova on-line!
See this thread for details.
Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Java help. could someone tell me if I am on the right track?  RSS feed

 
Chris thomspon
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I need help with the second part of my Java. I think I am on the right track but I still get error messages. Please help

// 4. The action() Method
// ------------------------------------------------------
public boolean action(Event ev, Object o)
{
System.out.println("action() method called.");

// a. Handle the newPlayer Button
// If the newPlayer button was pressed
// Then call the newPlayer methodpublic boolean action(Event ev, Object O){

if(ev.target==newPlayer)
newPlayer();

// b. Handle thePlayer TextField
// If thePlayer TextField generated the event
// Then call the addPlayer() method

else if(ev.target==newPlayer)
addPlayer();

// c. Handle the newNumber Button
// If the newNumber button was pressed
// Call the newGame() method
// Enable theGuess component
// Set focus to theGuess textfield
// Set background color of theGuess to yellow

if(ev.target==newNbr)
{
newGame();
theGuess.setEnabled(true);
theGuess.requestFocus();
theGuess.setBackground(Color.YELLOW);
}

// d. Handle theGuess TextField
// If this TextField theGuess generated the event
// Call the newGuess() method

if(ev.target==theGuess)
newGuess();

return true;

// COMPILE CHECK # 4 HERE

}

// ------------------------------------------------------
// 5. The addPlayer() Method
// ------------------------------------------------------
private void addPlayer()
{
System.out.println("addPlayer() method called.");

// a. Retrieve text from thePlayer, store in playerName

getText.playername ="";

// b. Check to see if playerName is ""
// If it is, then:
// Print error message to theOutput

if (playerName = "");
else if(errormsg = "theOutput");

// If not then:
// 1. Set the amount remaining to 100
// 2. Set the number of games played to 0
// 3. Call the newGame() method

setamtRemaining = 100;
setNbrgames = 0;
newGame();

//4. Call the updateScore() method

updateScore();

//5. Disable thePlayer TextField. Set its
// background color to white

thePlayer.setEnabled(false);
thePlayer.setBackground(Color.WHITE);

//6. Enable all other components.

theOutput.setEnabled(true);
theGuess.setEnabled(true);
newPlayer.setEnabled(true);
newNbr.setEnabled(true);

//7. Set focus to theGuess textfield

theGuess.requestFocus();

//8. Set background color of theGuess to yellow

theGuess.setBackground(Color.YELLOW);

// COMPILE CHECK # 5 HERE
}

// ------------------------------------------------------
// 6. The newGame() Method
// ------------------------------------------------------
private void newGame()
{
System.out.println("newGame() method called");

// a. Increment the number of games played [numGames]

numGames();
// b. Calculate a random number between 0 and 100
// Store the random number in the field theNumber
// Use your Random object [randomizer] to generate
// the number, using the instructions from class

theNbr(random(0,100));

// c. Set the number of tries to 0 [numTries]
nbrtries=0;

// d. Call the displayInstructions() method
displayInstructions();

// COMPILE CHECK # 6 HERE
}


// ------------------------------------------------------
// 7. The displayInstructions() Method
// ------------------------------------------------------
private void displayInstructions()
{
System.out.println("displayInstructions() method called");

// a. Run the sample applet and read instructions
// displayed on the screen after name is typed
System.out.print(Read Instructions displayed after name is typed);
// b. Use the necessary TextArea methods to display
// those instructions in the center of the screen
TextArea instructions = TextArea (TextArea.CENTER);

// COMPILE CHECK # 7 HERE
}

// ------------------------------------------------------
// 8. The updateScore() Method
// ------------------------------------------------------
private void updateScore()
{
System.out.println("updateScore() method called");

// a. Set the text in thePlayer textfield to the
// player's name [playerName], along with the
// the number of the current game [numGames]

setText.thePlayer();
updatescore();


// b. Set the text in the bankRoll Label to the
// amount remaining in the player's account
// amtRemaining
bankRoll.setText(amtRemaining);

// COMPILE CHECK # 8 HERE
}

// ------------------------------------------------------
// 9. The newGuess() Method
// ------------------------------------------------------
private void newGuess()
{
System.out.println("newGuess() method called.");

// a. Retrieve the text from theGuess

getText theGuess;
return playerName;

// b. Convert the text to a local int [curGuess]

// c. Increment the number of tries
// d. Print the number of guesses and the current guess
// to theOutput

// e. Test to see if curGuess is equal to theNumber
// If so, then:
// Call the method gameWon()
// Otherwise:
// Test to see if curGuess is greater than theNumber.
// If so then
// Print "Sorry, too high. Try lower"
// Otherwise
// Print "Sorry, too low. Try higher"

String command = evt.getActionCommand();
if (command.equals("Sorry, too high. Try lower "))
dolower();
else if (command.equals("Sorry, to low. Try higher"))
dohigher();

}
// end actionPerformed()
// Set the focus to theGuess text field
// Set the background color of the field to yellow
// Select all of the text in the text field

theGuess.requestFocus
theGuess.setBackground(Color.YELLOW);
void selectall();
// COMPILE CHECK # 9 HERE
}
// ------------------------------------------------------
// 10. The gameWon() Method
// ------------------------------------------------------

private void gameWon()
{
System.out.println("gameWon() method called");

// a. Print "************** WINNER ***************"
// Clear the screen when this is printed.
Clearall
// b. Print out the amount wagered (always 1 Zipoid)
// and the number of tries

// c. Calculate the current winnings using a switch
// statment. Use the field numTries in your
// switch statement. If numTries is 1, then the
// current winnings is 2, if 2 the 1.75, etc. Store
// the current winnings in a local variable

if(curwin 1 == 2)
else if(curwin 2==1.75)


// d. Print the current winnings on theOutput
theOutput = currwin;
// e. Add the current winnings to the amount remaining.
// Store the result back in amtRemaining.
amtRemaining(amtRemaining + winnings);
// f. Print the player name + the amount left to output

// g. Instruct the player to press the New Number button
}
// h. Call the updateScore() method
updateScore();

// i. Clear theGuess textfield, disable it, set its
// background to white, and set focus to the
// newNumber button.


public void clear theGuess()

theGuess.setEnabled(false);
theGuess.setBackground(Color.WHITE);
newNumber.requestFocus();
// COMPILE CHECK # 10 HERE
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to JavaRanch!

That's a lot of code to decipher. Can you tell us what the error messages are? And what lines are causing them?
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
this sorta stands out at the top, but I don't know if it's the problem you're referring to



both are testing for newPlayer, meaning addPlayer() can never be called
 
Chris thomspon
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have tried different things to try and correct this but it has not happened.


GOM.java".")" expected at line 258, column 29

// a. Run the sample applet and read instructions
// displayed on the screen after name is typed
System.out.print(Read Instructions displayed after name is typed);

"," expected at line 330, column 17
// end actionPerformed()
// Set the focus to theGuess text field
// Set the background color of the field to yellow
// Select all of the text in the text field

theGuess.requestFocus
theGuess.setBackground(Color.YELLOW);
void selectall();



i. Clear theGuess textfield, disable it, set its
// background to white, and set focus to the
// newNumber button.





'class' or 'interface' expected at line 338, column 11
private void gameWon()

line 375 column 16
public void clear theGuess()




Line 378, column 9
theGuess.setBackground.Color.WHITE);

line 379, column 9

newNumber.requestFocus();


these are the lines that are causing my errors. I have tried different
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
is this an assignment in debugging?

> System.out.print(Read Instructions displayed after name is typed);
what are strings enclosed in?

> theGuess.requestFocus
what is at the end of a method name?

> public void clear theGuess()
go to the hardware store for a tube of 'no more gaps'

> theGuess.setBackground.Color.WHITE);
are the parentheses matched?

> newNumber.requestFocus();
what is newNumber? can it receive focus?
possibly the error is related to the prior line - fix prior line before
making changes to this line.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!