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
- Data Science
- Android
- AJAX
- ASP.net
- C
- C++
- C#
- Cocoa
- Cloud Computing
- HTML5
- Java
- Javascript
- JSF
- JSP
- J2ME
- Java Beans
- EJB
- JDBC
- Linux
- Mac OS X
- iPhone
- MySQL
- Office 365
- Perl
- PHP
- Python
- Ruby
- VB.net
- Hibernate
- Struts
- SAP
- Trends
- Tech Reviews
- WebServices
- XML
- Certification
- Interview
categories
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
Count number of vowels, consonants and digits in a String in Java
Student marks calculation program 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
Archived Comments
1. //Convert numbers to word as per Indian number sys
View Tutorial By: Abhishek at 2011-09-05 10:42:20
2. Hi,
I have loaded all 5 java classes and i
View Tutorial By: DurgaPrasad at 2011-11-24 06:02:19
3. Good examples. However... I am testing for a Hex v
View Tutorial By: Doug Whitehead at 2008-11-29 17:10:43
4. very useful...!
View Tutorial By: mahesh at 2012-01-06 09:55:59
5. Thanks for your tutorial.
View Tutorial By: pre pais at 2015-01-09 00:14:29
6. In this examples please create the output of the p
View Tutorial By: bheemesh at 2011-05-01 09:05:46
7. hi all !
This is the error im getti
View Tutorial By: Ajit at 2010-02-17 23:09:47
8. programming for java is excelent
View Tutorial By: roldan at 2010-07-19 00:22:52
9. how to run it on command prompt...i tried but it i
View Tutorial By: gk at 2013-11-15 15:54:51
10. Your Work is Good, But i want to ask if there is a
View Tutorial By: Good Muyis at 2011-01-08 09:47:14