Java Dice Roller Loops -


so having issue figuring out how create loop , bring class on in dice game application have create school project. game has keep user score each round 18 max score , if user rolls on 10 in 1 round points lost , starts next round @ 1 point. game has validate when user enters y roll or r stop. on appreciated. im having problems setting loop in continue game after y entered or tell user game has stopped after r entered. after y entered loop print out "round1" roll:6 [y or r], user entered y, print out "round 2" , on , dont know how validate user input.

import java.util.scanner; import java.util.random; import java.lang.boolean;  public class player {     public static void main(string[] args){         string player;         string playeranswer;         boolean answer = true;         int roundscore;         int totalscore;         int playerscore;         int round;         scanner user = new scanner(system.in);         system.out.println("enter first name play!");         player = user.nextline();         playeranswer = user.nextline();         {             system.out.println("your name:" + "" + player);             system.out.println("welcome" + "" + player + "" + "to dice game");             system.out.println("enter y roll or r stop:[y or r]" + "" + playeranswer.touppercase());         }     } }    package project4; import java.util.random; import java.util.scanner;  public class dice{     public static void main(string[] args){          random dice = new random();         int number = 0;         for(int counter = 1; counter <= 1; counter++)             number = 1 + dice.nextint(18);         system.out.println(number + "");     } } 

something note don't think there's (1) die can roll 18. range 3 dice should 3 - 18 instead of 1 - 18.

number = 3 + dice.nextint(16); 

for loop issue use while loop, , assign variable , noticed how playeranswer should under system.out.println.

int rounds = 1;  {  // codes want loop system.out.println("welcome" + "" + player + "" + "to dice game"); system.out.println("round " + rounds); // annouce number of rounds system.out.println("enter y roll or r stop:[y or r]") playeranswer = user.nextline(); rounds++;  } while (playeranswer.equalsignorecase("y"); 

also, don't think can have 2 main method here you're creating "an" application, not 2 different application. suggest create sub method using

public static void rolldice() {     // codes rolling dice  } 

and call rolldice method

rolldice();

however, application you're creating seems small , doing dice roll, if wouldn't need create method it.

you trying learn how create class. seeing codes, seems aren't great in java yet. suggest re-start learning java basics. think need pay more attention in school class.


Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -