Penn foster Graded Project 1 Number Guessing Game Java

$ 20

Penn foster Graded Project Number Guessing Game Java

For your first project, you’ll create a simple number guessing game. The game will use a for statement to ask for three guesses and an if statement to determine if the answer is right.

1. In NetBeans, create a new Java Application project named NumberGuess. Review Activity 2 for details.

2. In the main() method, add the following code to generate a random number. Note that the fourth and fifth lines of code should all go on one single line.
int randNum, guessNum, attemptNum;
//Generates a random number from 1 to 10
randNum = new java.util.Random().nextInt(10) + 1;
System.out.println(“I am thinking of a number from 1 to 10”);

3. Using a for loop, ask for three guesses, using the attemptNum variable. See pages 23–24 in the textbook for more details. You can use the following code to ask for a guess:
System.out.print(“Guess? “);
//Wraps the default input in a simple parser
called Scanner
java.util.Scanner scan = new
java.util.Scanner(System.in);
guessNum = scan.nextInt(); //Reads the next command-line int
System.out.println(“You guessed ” + guessNum);

4. Using an if statement in the for block, determine whether randNum and guessNum are equal. See pages 21–23 for in the textbook for more details. You can use the following code if randNum and guessNum are equal:
System.out.println(“You guessed it!”);
break;

5. When you’re finished, the contents of the main() method should resemble the following:
int randNum, guessNum, attemptNum
//Generates a random number from 1 to 10
randNum = new java.util.Random().nextInt(10) + 1;
System.out.println(“I am thinking of random number from 1 to 10”);
for (/* Figure this part out yourself */) {
System.out.print(“Guess? “);
java.util.Scanner scan = new
java.util.Scanner(System.in);
guessNum = scan.nextInt();
System.out.println(“You guessed ” + guessNum);
if (/* Figure this part out yourself */) {
System.out.println(“You guessed it!”);
break;
}
}

6. Compile and run the project to ensure it works as expected. To type input, make sure you click in the Output panel; otherwise, you’ll modify code.

74 in stock

SKU: PENNJAVA1 Category:

Description

Penn foster Graded Project Number Guessing Game Java

For your first project, you’ll create a simple number guessing game. The game will use a for statement to ask for three guesses and an if statement to determine if the answer is right.

1. In NetBeans, create a new Java Application project named NumberGuess. Review Activity 2 for details.

2. In the main() method, add the following code to generate a random number. Note that the fourth and fifth lines of code should all go on one single line.
int randNum, guessNum, attemptNum;
//Generates a random number from 1 to 10
randNum = new java.util.Random().nextInt(10) + 1;
System.out.println(“I am thinking of a number from 1 to 10”);

3. Using a for loop, ask for three guesses, using the attemptNum variable. See pages 23–24 in the textbook for more details. You can use the following code to ask for a guess:
System.out.print(“Guess? “);
//Wraps the default input in a simple parser
called Scanner
java.util.Scanner scan = new
java.util.Scanner(System.in);
guessNum = scan.nextInt(); //Reads the next command-line int
System.out.println(“You guessed ” + guessNum);

4. Using an if statement in the for block, determine whether randNum and guessNum are equal. See pages 21–23 for in the textbook for more details. You can use the following code if randNum and guessNum are equal:
System.out.println(“You guessed it!”);
break;

5. When you’re finished, the contents of the main() method should resemble the following:
int randNum, guessNum, attemptNum
//Generates a random number from 1 to 10
randNum = new java.util.Random().nextInt(10) + 1;
System.out.println(“I am thinking of random number from 1 to 10”);
for (/* Figure this part out yourself */) {
System.out.print(“Guess? “);
java.util.Scanner scan = new
java.util.Scanner(System.in);
guessNum = scan.nextInt();
System.out.println(“You guessed ” + guessNum);
if (/* Figure this part out yourself */) {
System.out.println(“You guessed it!”);
break;
}
}

6. Compile and run the project to ensure it works as expected. To type input, make sure you click in the Output panel; otherwise, you’ll modify code.

Reviews

There are no reviews yet.

Only logged in customers who have purchased this product may leave a review.