Question2

Page 1 of 1

1 Replies - 150 Views - Last Post: 29 November 2012 - 04:24 PM Rate Topic: -----

#1 bhagy2010  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 28-November 12

Question2

Posted 29 November 2012 - 04:19 PM

Still it does not show the high score. Can you please tell me where the error is ??
See my code below:


[public class NumberGuessingGame/]
{
[public static void main (String[] args)/]
{
[Console c = new Console ("Number Guessing Game");/]

// Open a text file "input.txt" for input.
// Refer to this file using the object named inFile.
// The first line of the fle is: 88 word 6.725
TextInputFile inFile = new TextInputFile ("input.txt");
String highScoreName = inFile.readLine (); // read from file
int highScore = inFile.readInt (); // read from file
// We should close any open files when we're done with them.
inFile.close ();


// for testing
//c.println ("The file input.txt contains:");
//c.println (first + " " + name + " " + second);

// Write the items read from "input.txt" in REVERSE ORDER into the output file
//c.println("\nNow writing contents of file input.txt into file output.txt (in reverse order)");


char option = 'Y';

while (option != 'N' && option != 'n')
{

int secretNumber = (int) (Math.random () * 100);
//we also declare each new variable as needed
//int secretNumber =
int guessNumber = 0;
int guessTaken = 0;
int highestScore = 0;
int score = 0;

//Input the information from the keyboard

c.setTextBackgroundColor (Color.PINK);
c.setTextColor (Color.BLUE);
c.println ("\t NUMBER GUESSING GAME");
c.println ("");
c.println ("Please enter your name: ");
String name = c.readLine ();

//c.println ("Secret number is: " + secretNumber);
c.println ("Hello " + name);

while (guessNumber != secretNumber)
{
c.println ("Please enter the guessing number: ");
guessNumber = c.readInt ();

guessTaken++;

if (guessNumber < secretNumber)
{
c.println ("Your guessing number is too law! Try again");
}
else if (guessNumber > secretNumber)
{
c.println ("Your guessing number is too high! Try again");

}
else
{
c.setTextBackgroundColor (Color.MAGENTA);
c.println ("");
c.println ("Congratulations " + name + " !!!");
c.println ("Number of guesses taken: " + guessTaken);
}

[ }
do
{
c.println ("Do you like to play again ? Y/N)");
option = c.readChar ();
if (option != 'y' && option != 'Y' && option != 'N' && option != 'n')
{
c.println ("Invalid option.");
//break;
}
}
while (option != 'y' && option != 'Y' && option != 'N' && option != 'n');
{
if (guessTaken >= highScore )
{
c.println ("Your High Score is: " + highScore + name);
highScore = c.readInt ();
}
}
}
c.println ("Thank you for playing the game !!! ");
c.println ("Have a nice day");/]

This assignment needs to show high score and the name of the high score player.
This is a number guessing game. Thanks !

Is This A Good Question/Topic? 0
  • +

Replies To: Question2

#2 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8324
  • View blog
  • Posts: 31,857
  • Joined: 06-March 08

Re: Question2

Posted 29 November 2012 - 04:24 PM

You already have a thread with the same subject:
http://www.dreaminco...1&#entry1756853

Please avoid double posting
And :code:
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1