Programming Tutorials

Comment on Tutorial - substring() in Java By Fazal



Comment Added by : Ridge Fernandes

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

Comment on Tutorial : 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