Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search Coderanch
Advance search
Google search
Register / Login
Tanjid Islam
Greenhorn
+ Follow
1
Posts
1
Threads
0
Cows
since Dec 11, 2009
Merit badge:
grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
Ranch Hand Scavenger Hunt
Number Posts (1/100)
Number Threads Started (1/100)
Number Cows Received (0/5)
Number Likes Received (0/10)
Number Likes Granted (0/20)
Set bumper stickers in profile (0/3)
Report a post to the moderators (0/1)
Edit a wiki page (0/1)
Create a post with an image (0/2)
Greenhorn Scavenger Hunt
First Post
Number Posts (1/10)
Number Threads Started (1/10)
Number Likes Received (0/3)
Number Likes Granted (0/3)
Set bumper stickers in profile (0/1)
Set signature in profile
Search for a post/thread (0/3)
Set a watch on a thread
Save thread as a bookmark
Create a post with an image (0/1)
Recent posts by Tanjid Islam
Need help at converting java program to pseudo code
//Import Scanner from util package import java.util.Scanner; //Import Math from lang package import java.lang.Math; public class RollDice { public static void main(String[] args) { //Let the user input variables or string Scanner input = new Scanner (System.in) ; //Declare variables String name; int begin; int rollDie; int timeRoll = 0; int game; int diceNroll; int diceNrollResult=0; int rollAll; int rollAllResult=0; int rollLuck; int rollLuckResult=0; int choice; //Ask & Let the user input his/her name System.out.println ("Enter your name to start the game: "); name = input.next(); System.out.println(""); //Displays the introduction System.out.println ("Welcome " + name + ", let's start the game!"); System.out.println ("Roll Dice The Legend of Games!"); System.out.println(""); //Ask user either to start a new game or exit System.out.println ("1. New Game"); System.out.println ("2. Exit"); begin = input.nextInt(); System.out.println(""); //Game begins switch (begin){ case 1: System.out.println ("Let's start!"); //Give user the choice to play any of the game System.out.println ("Which game do you want to play?"); System.out.println("1. Play Dice n Roll."); System.out.println("2. Play Roll all the way."); System.out.println("3. Play Roll Your Luck."); game= input.nextInt(); System.out.println(""); switch(game){ case 1: //Give user the choice to play or quit System.out.println ("Welcome "+name+" to Dice n Roll!"); System.out.println ("1. Roll the dice"); System.out.println ("2. Exit"); diceNroll= input.nextInt(); System.out.println(""); switch (diceNroll){ case 1: //User rolls dice randomly diceNrollResult = rollDie(); //Display the result System.out.println ("You rolled "+ diceNrollResult + " points!"); break; } System.out.println(""); System.out.println ("What do you want to do now?"); System.out.println("1. Continue to the next game."); System.out.println ("2. Exit"); choice = input.nextInt(); switch (choice){ //Exit case 2: System.exit(0); } case 2: //Give user the choice to play or quit System.out.println ("Welcome "+name+" to Roll all the way!"); System.out.println ("1. Roll the dice"); System.out.println ("2. Exit"); rollAll = input.nextInt(); System.out.println(""); switch (rollAll){ case 1: //User chooses the number of times he wants to roll the dice System.out.println ("Write the number of times you want to roll the dice: "); int roll = input.nextInt(); System.out.println(""); //Display the result rollAllResult = rollDie (roll); System.out.println ("You rolled "+ rollAllResult+" points!"); break; } System.out.println(""); System.out.println ("What do you want to do now?"); System.out.println("1. Continue to the next game."); System.out.println ("2. Exit"); choice = input.nextInt(); switch (choice){ //Exit case 2: System.exit(0); } case 3: //Give user the choice to play or quit System.out.println ("Welcome "+name+ " to Roll Your Luck!"); System.out.println ("1. Roll the dice"); System.out.println ("2. Exit"); rollLuck = input.nextInt(); System.out.println(""); switch (rollLuck){ case 1: //User chooses the number of times he wants to roll the dice System.out.println ("Write the number of times you want to roll the dice: "); int roll = input.nextInt(); System.out.println(""); //User chooses to number of faces of the dice System.out.println ("Write the number of faces you want to roll the dice: "); int face = input.nextInt(); System.out.println(""); //Display the result rollLuckResult = rollDie (face, roll); System.out.println ("You rolled: " + rollLuckResult); break; } } } } // generates a random number between 1 and 6 public static int rollDie(){ //Declare the variable int rollDie = 0; rollDie = (int)(6*Math.random()+1); //Return to the main method return rollDie; } // generates a random number between 1 and 6 the number of times specified by rolls public static int rollDie(int roll){ //Declare the variable int timeRoll=0; int rollDie=0; for (int i=0; i < roll; i++){ //Generate Random Number rollDie = (int)(6*Math.random()+1); timeRoll+= rollDie; } //Return to the main method return timeRoll; } // generates a random number between 1 and the number specified by faces, and does this // the number of times specified by rolls public static int rollDie(int roll, int face){ //Declare the variable int timeRoll = 0; for (int a=0; a<roll; a++){ //Generate Random Number timeRoll+=(int)(face*Math.random()+1); } //Return to the main method return timeRoll; } }
show more
14 years ago
Beginning Java