Comment on Tutorial - Using substring( ) in Java By Fazal



Comment Added by : Ridge Fernandes

Comment Added at : 2012-01-19 04:09:45

Comment on Tutorial : Using substring( ) in Java By Fazal
Hey guys, can u help me out over here..
this is a game called wheel of fortune..
nd waht i need to do is replace dashes with the letter for example ..
if the word is fr example "APPLE" ..
nd the user enters "P" .. then the dash at the position where P should be should get replaced by the letter..so sumting like this "_ PP_ _

but i cant seem to get it to work ..nd i need to do this wid substring and charAt..plzzzz HELP ME !:(

HERE'S MY CODE ...PLZ HELP ASAP ..THNKS :)

/*
* Ridge Fernandes
* WheelOfFortuneCulminating.java
* The game wheel of Fortune which is a two player game.The players enter letters, or vowels and try their best to solve the puzzle so they can win the game.
* ICS 3U1
* December.29,2011
*/
/*START
*Display "/////////////////////////////////////
*\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
*\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\"
* WW WW HH HH EEEEEE EEEEEE LL
* WW WW HH HH EE EE LL
* WW WW WW HHHHHHH EEEEEE EEEEEE LL
* WW WW WW HH HH EE EE LL
* WW WW HH HH EEEEEE EEEEEE LLLLLL
*
* OOOOOO FFFFFF
* OO OO FF
* OO OO FFFFFF
* OO OO FF
* OOOOOO FF
*
* FFFFFF OOOOOO RRRRRR TTTTTT UU UU NNNN NN EEEEEE
* FF OO OO RR RR TT UU UU NN NN NN EE
* FFFFFF OO OO RRRRRR TT UU UU NN NN NN EEEEEE
* FF OO OO RR RR TT UU UU NN NN NN EE
* FF OOOOOO RR RR TT UUUUUU NN NNNNN EEEEEE
*Display "/////////////////////////////////////
*\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
*\\\\\\\\\\\\\\\\\\\\\\\\\\\\"
*
*player <-- " "
*player1
*player2
*playerSpin1 <-- 0
*playerSpin2 <-- 0
*player1money1 <-- 0
*player2money2 <-- 0
*money <-- 0
*selection
*choice
*word
*
*Display "Enter the first player's name "
*get player1
*Display "Enter the second player's name "
*get player2
*selection <= (2 x Math.random() plus 1) // a switch statement is used here, this selects the player that gets to play first by randomizing the selection
*case 1: Display "The player ", player1, " gets to play first "
*case 2: Display "The player ", player2, " gets to play first "
*
*Display ("1) Play the game: ")
*Display ("2) Instructions of wheel of fortune: ")
*Display ("3) Quit: ")
*get choice
*
*if (choice becomes 1)
*Display ("You have started the game wheel of fortune")
*spin <-- (13 x Math.random() plus 1) // this is used to spin the wheel of fortune by randomizing each time it is spun
*
*case 1: Display ("You have landed on Lose a turn"),money <-- -15
case 2: Display ("You have landed on $300"),money<-- 300
case 3: Display("You have landed on $400"),money<-- 400
case 4: Display("You have landed on $800"),money<-- 800
case 5: Display("You have landed on $1000"),money<-- 1000
case 6: Display("You have landed on $1500"),money<-- 1500
case 7: Display("You have landed on $2000"),money<-- 2000
case 8: Display("You have landed on BANKRUPTCY"),money<-- -5
case 9: Display("You have landed on $3000"),money<-- 3000
case 10: Display("You have landed on $3500"),money<-- 3500
case 11: Display("You have landed on $4000"),money<-- 4000
case 12: Display("You have landed on $4500"),money<-- 4500
case 13: Display("You have landed on BONUS: $5000"),money<-- 5000
*
*if (player.equals(player1))
* {
*/


import java.util.Scanner;
public class WheelOfFortuneCulminating{
public static void main(String[] args){
Scanner in = new Scanner(System.in);

System.out.print("//////////////////////////////////////");
System.out.println("\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ ");
System.out.println("\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ ");
System.out.println(" WW WW HH HH EEEEEEE EEEEEEE LL ");
System.out.println(" WW WW HH HH EE EE LL ");
System.out.println(" WW WW WW HHHHHHHH EEEEEEE EEEEEEE LL ");
System.out.println(" WW WW WW HH HH EE EE LL ");
System.out.println(" WWW WWW HH HH EEEEEEE EEEEEEE LLLLLLL ");
System.out.println();
System.out.println(" OOOOOOO FFFFFFF ");
System.out.println(" OO OO FF ");
System.out.println(" OO OO FFFFFFF ");
System.out.println(" OO OO FF ");
System.out.println(" OOOOOOO FF ");
System.out.println();
System.out.println(" FFFFFFF OOOOOOO RRRRRRR TTTTTTTT UU UU NNN NN EEEEEEE ");
System.out.println(" FF OO OO RR RR TT UU UU NN NN NN EE ");
System.out.println(" FFFFFFF OO OO RRRRRRR TT UU UU NN NN NN EEEEEEE ");
System.out.println(" FF OO OO RR RR TT UU UU NN NN NN EE ");
System.out.println(" FF OOOOOOO RR RR TT UUUUUUU NN NNNN EEEEEEE ");
System.out.println("/////////////////////////////////////");
System.out.println("\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ ");
System.out.println("\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\"\n" );


String player1;
String answer = "";
String letter = " ";
String dash = " _ ";
String ansOut = " _ ";
String vowels;
int player = 0;
int mainFunctions;
int playerSpin1 = 0;
int player1money1 = 0;
int money = 0;
int selection;
int choice;
int choice2 = 0;



System.out.println("Enter the first player's name");
player1 = in.nextLine();

System.out.println("The first player " + player1 + " gets to play first");


System.out.println();
System.out.println("1. Play the game:");
System.out.println("2. Instructions of wheel of fortune:");
System.out.println("3. Quit:");
choice = in.nextInt();
System.out.println();

if (choice == 1)
{
System.out.println("You have started the game wheel of fortune: ");//

int spin;
spin = (int) (13* Math.random() + 1);

switch(spin)
{

//case 1: System.out.println("You have landed on Lose a turn");money = -15;break;
case 2: System.out.println("You have landed on $300");money = 300;break;
case 3: System.out.println("You have landed on $400");money = 400;break;
case 4: System.out.println("You have landed on $800");money = 800;break;
case 5: System.out.println("You have landed on $1000");money = 1000;break;
case 6: System.out.println("You have landed on $1500");money = 1500;break;
case 7: System.out.println("You have landed on $2000");money = 2000;break;
case 8: System.out.println("You have landed on BANKRUPTCY");money = -1;break;
case 9: System.out.println("You have landed on $3000");money = 3000;break;
case 10: System.out.println("You have landed on $3500");money = 3500;break;
case 11: System.out.println("You have landed on $4000");money = 4000;break;
case 12: System.out.println("You have landed on $4500");money = 4500;break;
case 13: System.out.println("You have landed on BONUS: $5000");money = 5000;break;
// return (spin)
}

if (money != -1)
{
player1money1 += money;
}
else if (money == -1)
{

//player1money1 = 0;
}

}

System.out.println ("\n" + player1 + " = " + "$" + money );

int randomWord;
randomWord = (int) (5 * Math.random() + 1);

if (randomWord == 1)
{
answer = "APPLE"; ansOut = " _ _ _ _ _ ";
}
else if (randomWord == 2)
{
answer = "PSYCHOLOGY"; ansOut = " _ _ _ _ _ _ _ _ _ _ ";
}
else if (randomWord == 3)
{
answer = "BIRD"; ansOut = " _ _ _ _ ";
}
else if (randomWord == 4)
{
answer = "SURGEON"; ansOut = " _ _ _ _ _ _ _ ";
}
else if (randomWord == 5)
{
answer = "PIGEON"; ansOut = " _ _ _ _ _ _ ";
}


System.out.println("\nThe secret word to guess is: ");

for (int i = 0; i < answer.length(); i++)
{
if (letter.charAt(0) == answer.charAt(i))
{
ansOut = ansOut.substring(0,i) + letter.charAt(i) + ansOut.substring(i);
}
}System.out.print(ansOut);



System.out.println("\n \n What would you like to do ?");
System.out.println("1) Enter a letter: ");
System.out.println("2) Purchase a vowel($250): ");
System.out.println("3) Solve the puzzle ");
choice2 = in.nextInt();

if (choice2 == 1)
{
System.out.println("Enter your letter: ");
letter = in.nextLine();
letter = in.nextLine();

for (int i = 0; i < answer.length(); i++)
{
if ( letter.charAt(i) == answer.charAt(0))
{
ansOut = letter.substring(0,i) + letter.charAt(i) + ansOut.substring(i);
}
}
System.out.print(ansOut);

}












else if ( choice == 2)
{

System.out.println("The instructions is as follows: ");
System.out.println("1) This is a two player game and is also based on a hangman kind of a game. This game starts when the players enter their name and begin to start the game. The game continues until the puzzle is solved by any one of the contestants. And the game continues until the person with the highest cash value wins. At the end, the announced winner gets to go into the bonus round where he/she can be able to win a car or a prize from $10,000 to $20,000");
System.out.println();
System.out.println("2) The current player should enter the letter. Once the word is correct, the player gets 1000 dollars to the players account");
System.out.println();
System.out.println("3) Once this is done, the player is asked to spin the wheel and depending on that it might end up on Bankruptcy or a dollar value which can range from $100 to $5000.If they get a letter that appears 3 times in the puzzle for example, then the value on the wheel is multiplied by the number of letters that are required to solve the puzzle");
System.out.println("4) In terms of chances, if a player ends up on Bankruptcy, then the turn automatically get shifted to the next player. Each game features a number of 2 Toss-Up puzzles, which reveal the puzzle one letter at a time and award cash to whoever rings in with the right answer. The player must have atleast 250 dollars to guess a vowel and if the player does not have 250 dollars, the player will have to choose a option again.");
}

else if (choice == 3)
{

}
}
}


View Tutorial



Ask a Question

Subscribe to Tutorials

Related Tutorials

Program using concept of byte long short and int in java

Update contents of a file within a jar file

Tomcat and httpd configured in port 8080 and 80

Java File

Java String

Count number of vowels, consonants and digits in a String in Java

Reverse a number in Java

Student marks calculation program in Java

Handling Fractions in Java

Calculate gross salary in Java

Calculate average sale of the week in Java

Vector in Java - Sample Program

MultiLevel Inheritance sample in Java

Multiple Inheritance sample in Java

Java program using Method Overriding

Archived Comments

1. Hi guys
i am a beginer in java.. pls help

View Tutorial          By: Jeevan at 2009-12-19 09:35:06

2. Thanks for the syntax, this has really helped me u
View Tutorial          By: Ketobbey at 2010-04-30 19:01:29

3. hi i am new in java please send me basic programs
View Tutorial          By: Ganesh kumar at 2013-02-26 03:31:54

4. How can i add all the values of an multidimensiona
View Tutorial          By: jolly at 2015-04-11 11:54:47

5. i want simple program of function used in recursio
View Tutorial          By: manish at 2009-05-19 01:03:19

6. hi! we tried using the 5 java files...we build the
View Tutorial          By: anne226 at 2009-02-10 23:58:46

7. thanks for this pertinent remark.
View Tutorial          By: mohammed at 2009-02-21 05:43:11

8. Good job. Very clear and concise and a great help.
View Tutorial          By: Eduardo at 2012-02-08 19:18:50

9. Hi, i am new java, and i want to become gud develo
View Tutorial          By: reuben at 2012-12-20 14:27:08

10. iam getting intrest to watch this site
View Tutorial          By: monika at 2013-02-15 15:48:57