how do you add swing features to this hurkle game code? [on hold]
up vote
-2
down vote
favorite
The given version of the program is a console-based version (meaning the inputs and outputs happen on the console display). Run this code for the game Hurkle to see how it executes. It works well in the console but your job is to convert it for running in SWING with more graphical feedback for the user.You job is to experiment with the given code, and then adapt it by incorporating SWING features, such that the inputs and outputs will be more GUI-oriented, rather than console oriented.
import java.util.Random;
import java.util.Scanner;
publicclass Hurkle
{
publicstaticvoid main(String args) {
// TODO Auto-generated method stub
// gets user input for the keyboard
Scanner input = new Scanner(System.in);
//Gets a random number between 0 and 1
Random ran = newRandom();
//variable to hold the users' guess
int usersAnswer;
finalint LIMIT = 10;
//variable to hold the system random number
int rGuess;
rGuess = ran.nextInt(LIMIT);
// Here we are creating an array of one character strings into a String variable named 'display'
String display ={"0","1","2","3","4","5","6","7","8","9","10"};
System.out.println("You get 3 tries to win!");
// Tell the user how many tries they will get
for(int tries = 0; tries < 3; tries++) {
//ask the user for a guess
System.out.println("What is your number guess?" + 'n');
//using the scanner class, get the user guess
usersAnswer = input.nextInt();
if(usersAnswer == rGuess){
System.out.print("Bingo, you win!" + 'n');
tries = 9999; // 9999 is used because it is so far out of bounds it has to get out of the game
} else if (usersAnswer < rGuess){
display[usersAnswer] = ">";
// replace the user guessed number with feedback: greater than, this is saving the feedback
} else{ // so it doesn't get lost for the user
display[usersAnswer ] = "<";
// replace the user guessed number with feedback: less than
}
// Display the number line with feedback
System.out.print("Feedback : ");
for(int i=0;i<display.length;i++){
System.out.print( display[i] + " " );
}
} // end of for loop for the game
System.out.println('n');
System.out.println( "Game Over, 3 tries you lose! The number was " + rGuess); // 3 tries you lose
}
}
swing
New contributor
put on hold as off-topic by IEatBagels, Sᴀᴍ Onᴇᴌᴀ, 200_success, Toby Speight, Malachi♦ 2 days ago
This question appears to be off-topic. The users who voted to close gave this specific reason:
- "Code not implemented or not working as intended: Code Review is a community where programmers peer-review your working code to address issues such as security, maintainability, performance, and scalability. We require that the code be working correctly, to the best of the author's knowledge, before proceeding with a review." – IEatBagels, Sᴀᴍ Onᴇᴌᴀ, 200_success, Toby Speight, Malachi
If this question can be reworded to fit the rules in the help center, please edit the question.
add a comment |
up vote
-2
down vote
favorite
The given version of the program is a console-based version (meaning the inputs and outputs happen on the console display). Run this code for the game Hurkle to see how it executes. It works well in the console but your job is to convert it for running in SWING with more graphical feedback for the user.You job is to experiment with the given code, and then adapt it by incorporating SWING features, such that the inputs and outputs will be more GUI-oriented, rather than console oriented.
import java.util.Random;
import java.util.Scanner;
publicclass Hurkle
{
publicstaticvoid main(String args) {
// TODO Auto-generated method stub
// gets user input for the keyboard
Scanner input = new Scanner(System.in);
//Gets a random number between 0 and 1
Random ran = newRandom();
//variable to hold the users' guess
int usersAnswer;
finalint LIMIT = 10;
//variable to hold the system random number
int rGuess;
rGuess = ran.nextInt(LIMIT);
// Here we are creating an array of one character strings into a String variable named 'display'
String display ={"0","1","2","3","4","5","6","7","8","9","10"};
System.out.println("You get 3 tries to win!");
// Tell the user how many tries they will get
for(int tries = 0; tries < 3; tries++) {
//ask the user for a guess
System.out.println("What is your number guess?" + 'n');
//using the scanner class, get the user guess
usersAnswer = input.nextInt();
if(usersAnswer == rGuess){
System.out.print("Bingo, you win!" + 'n');
tries = 9999; // 9999 is used because it is so far out of bounds it has to get out of the game
} else if (usersAnswer < rGuess){
display[usersAnswer] = ">";
// replace the user guessed number with feedback: greater than, this is saving the feedback
} else{ // so it doesn't get lost for the user
display[usersAnswer ] = "<";
// replace the user guessed number with feedback: less than
}
// Display the number line with feedback
System.out.print("Feedback : ");
for(int i=0;i<display.length;i++){
System.out.print( display[i] + " " );
}
} // end of for loop for the game
System.out.println('n');
System.out.println( "Game Over, 3 tries you lose! The number was " + rGuess); // 3 tries you lose
}
}
swing
New contributor
put on hold as off-topic by IEatBagels, Sᴀᴍ Onᴇᴌᴀ, 200_success, Toby Speight, Malachi♦ 2 days ago
This question appears to be off-topic. The users who voted to close gave this specific reason:
- "Code not implemented or not working as intended: Code Review is a community where programmers peer-review your working code to address issues such as security, maintainability, performance, and scalability. We require that the code be working correctly, to the best of the author's knowledge, before proceeding with a review." – IEatBagels, Sᴀᴍ Onᴇᴌᴀ, 200_success, Toby Speight, Malachi
If this question can be reworded to fit the rules in the help center, please edit the question.
3
Hi, I'm afraid this might not be on topic for Code Review. We can review your working code, but it's not our job to add features to your code.
– IEatBagels
2 days ago
add a comment |
up vote
-2
down vote
favorite
up vote
-2
down vote
favorite
The given version of the program is a console-based version (meaning the inputs and outputs happen on the console display). Run this code for the game Hurkle to see how it executes. It works well in the console but your job is to convert it for running in SWING with more graphical feedback for the user.You job is to experiment with the given code, and then adapt it by incorporating SWING features, such that the inputs and outputs will be more GUI-oriented, rather than console oriented.
import java.util.Random;
import java.util.Scanner;
publicclass Hurkle
{
publicstaticvoid main(String args) {
// TODO Auto-generated method stub
// gets user input for the keyboard
Scanner input = new Scanner(System.in);
//Gets a random number between 0 and 1
Random ran = newRandom();
//variable to hold the users' guess
int usersAnswer;
finalint LIMIT = 10;
//variable to hold the system random number
int rGuess;
rGuess = ran.nextInt(LIMIT);
// Here we are creating an array of one character strings into a String variable named 'display'
String display ={"0","1","2","3","4","5","6","7","8","9","10"};
System.out.println("You get 3 tries to win!");
// Tell the user how many tries they will get
for(int tries = 0; tries < 3; tries++) {
//ask the user for a guess
System.out.println("What is your number guess?" + 'n');
//using the scanner class, get the user guess
usersAnswer = input.nextInt();
if(usersAnswer == rGuess){
System.out.print("Bingo, you win!" + 'n');
tries = 9999; // 9999 is used because it is so far out of bounds it has to get out of the game
} else if (usersAnswer < rGuess){
display[usersAnswer] = ">";
// replace the user guessed number with feedback: greater than, this is saving the feedback
} else{ // so it doesn't get lost for the user
display[usersAnswer ] = "<";
// replace the user guessed number with feedback: less than
}
// Display the number line with feedback
System.out.print("Feedback : ");
for(int i=0;i<display.length;i++){
System.out.print( display[i] + " " );
}
} // end of for loop for the game
System.out.println('n');
System.out.println( "Game Over, 3 tries you lose! The number was " + rGuess); // 3 tries you lose
}
}
swing
New contributor
The given version of the program is a console-based version (meaning the inputs and outputs happen on the console display). Run this code for the game Hurkle to see how it executes. It works well in the console but your job is to convert it for running in SWING with more graphical feedback for the user.You job is to experiment with the given code, and then adapt it by incorporating SWING features, such that the inputs and outputs will be more GUI-oriented, rather than console oriented.
import java.util.Random;
import java.util.Scanner;
publicclass Hurkle
{
publicstaticvoid main(String args) {
// TODO Auto-generated method stub
// gets user input for the keyboard
Scanner input = new Scanner(System.in);
//Gets a random number between 0 and 1
Random ran = newRandom();
//variable to hold the users' guess
int usersAnswer;
finalint LIMIT = 10;
//variable to hold the system random number
int rGuess;
rGuess = ran.nextInt(LIMIT);
// Here we are creating an array of one character strings into a String variable named 'display'
String display ={"0","1","2","3","4","5","6","7","8","9","10"};
System.out.println("You get 3 tries to win!");
// Tell the user how many tries they will get
for(int tries = 0; tries < 3; tries++) {
//ask the user for a guess
System.out.println("What is your number guess?" + 'n');
//using the scanner class, get the user guess
usersAnswer = input.nextInt();
if(usersAnswer == rGuess){
System.out.print("Bingo, you win!" + 'n');
tries = 9999; // 9999 is used because it is so far out of bounds it has to get out of the game
} else if (usersAnswer < rGuess){
display[usersAnswer] = ">";
// replace the user guessed number with feedback: greater than, this is saving the feedback
} else{ // so it doesn't get lost for the user
display[usersAnswer ] = "<";
// replace the user guessed number with feedback: less than
}
// Display the number line with feedback
System.out.print("Feedback : ");
for(int i=0;i<display.length;i++){
System.out.print( display[i] + " " );
}
} // end of for loop for the game
System.out.println('n');
System.out.println( "Game Over, 3 tries you lose! The number was " + rGuess); // 3 tries you lose
}
}
swing
swing
New contributor
New contributor
New contributor
asked 2 days ago
The Number Four
1
1
New contributor
New contributor
put on hold as off-topic by IEatBagels, Sᴀᴍ Onᴇᴌᴀ, 200_success, Toby Speight, Malachi♦ 2 days ago
This question appears to be off-topic. The users who voted to close gave this specific reason:
- "Code not implemented or not working as intended: Code Review is a community where programmers peer-review your working code to address issues such as security, maintainability, performance, and scalability. We require that the code be working correctly, to the best of the author's knowledge, before proceeding with a review." – IEatBagels, Sᴀᴍ Onᴇᴌᴀ, 200_success, Toby Speight, Malachi
If this question can be reworded to fit the rules in the help center, please edit the question.
put on hold as off-topic by IEatBagels, Sᴀᴍ Onᴇᴌᴀ, 200_success, Toby Speight, Malachi♦ 2 days ago
This question appears to be off-topic. The users who voted to close gave this specific reason:
- "Code not implemented or not working as intended: Code Review is a community where programmers peer-review your working code to address issues such as security, maintainability, performance, and scalability. We require that the code be working correctly, to the best of the author's knowledge, before proceeding with a review." – IEatBagels, Sᴀᴍ Onᴇᴌᴀ, 200_success, Toby Speight, Malachi
If this question can be reworded to fit the rules in the help center, please edit the question.
3
Hi, I'm afraid this might not be on topic for Code Review. We can review your working code, but it's not our job to add features to your code.
– IEatBagels
2 days ago
add a comment |
3
Hi, I'm afraid this might not be on topic for Code Review. We can review your working code, but it's not our job to add features to your code.
– IEatBagels
2 days ago
3
3
Hi, I'm afraid this might not be on topic for Code Review. We can review your working code, but it's not our job to add features to your code.
– IEatBagels
2 days ago
Hi, I'm afraid this might not be on topic for Code Review. We can review your working code, but it's not our job to add features to your code.
– IEatBagels
2 days ago
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
3
Hi, I'm afraid this might not be on topic for Code Review. We can review your working code, but it's not our job to add features to your code.
– IEatBagels
2 days ago