Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Okay so the problem i received was: Write a game program that throws a die (sing

ID: 3640799 • Letter: O

Question

Okay so the problem i received was:

Write a game program that throws a die (singular for dice) until a certain number appears a given number of times in a row. The game should first prompt the client for a die face number he would like to appear in a row. The game then throws the dice until that die face number appears that many times in a row. Allow client to repeat the game as many times as they want. Use at least 3 methods: one for input, one for processing, and one for output.

So I wrote out:

import java.util.Scanner;

public class getNumberofDiesInARow {


public static void main(String [] args)
{
getNumberofDiesInARow game = new getNumberofDiesInARow();
game.input();
game.process();
game.output();
}

Scanner input = new Scanner (System.in);
public int dieFaceNumber;
public int numberOfRow;
public double howManyThrows;
public int dieFaceNumber1;
public int numberOfRow1;

public void input()
{
System.out.println("This game throws a die until a certain dice face number appears in a row a certain number of times.");
System.out.println("Please enter the dice face number that you would like to be repeated:");


int dieFaceNumber = input.nextInt();

System.out.println("Please enter the number of times you would like " + dieFaceNumber + " to appear in a row:");

int numberOfRow = input.nextInt();
}

public void process()
{
dieFaceNumber = dieFaceNumber1;
numberOfRow = numberOfRow1;
while(dieFaceNumber > 0)
{
double howManyThrows = (int)(Math.random() *6 + 1);
if (howManyThrows == dieFaceNumber1)
numberOfRow1++;
else if (howManyThrows != dieFaceNumber1)
numberOfRow1 = 0;
}
return;

}
public void output()
{
System.out.println("It took " + howManyThrows + " throws to get the number " + dieFaceNumber + " to appear " + numberOfRow + " in a row.");
System.out.println("Would you like to play the game again?");
System.out.println("Please enter (yes/no)");

String string1= input.next();

if (string1 == "yes");

}

}

And Now my question is:

1) It always gives out a zero for number of throws it took to get that certain number. Its either the problem with the (int)(Math.random() *6 +1); OR i just have the if else statement wrong... How exactly would i fix that because i tried removing the whole else if statement and that still doesn't work. It still outputs a 0.

2) When it outputs the line "System.out.println("It took " + howManyThrows + " throws to get the number " + dieFaceNumber + " to appear " + numberOfRow + " in a row."); " it gives numberOfRow and dieFaceNumber the value of 0... How do i give it the original value that the user input in the public void input()???

3) And how exactly do i do the end part:
System.out.println("Please enter (yes/no)");

String string1= input.next();

if (string1 == "yes");

If they say yes, how do i make the game repeat itself? I was thinking maybe this was a loop too, but isn't there a way you can just call for the public class again? If so, how?

Thanks A LOT! for helping! I've tried asking my teacher several times but he is either too busy or doesn't help at all.

Explanation / Answer

please rate I have made few small modifications and have completely changed process method. Also i have changed some naming conventions like getNumberofDiesInARow to DiceGame because getNumberofDiesInARow is to be given to a function name. import java.util.Scanner; import java.util.Random; public class DiceGame { public int dieFaceNumber; public int numberOfRow; public long howManyThrows; public DiceGame() { input(); process(); output(); } public static void main(String [] args) { DiceGame game = new DiceGame(); } public void input() { Scanner getInput = new Scanner(System.in); System.out.println("This game throws a die until a certain dice face number appears in a row a certain number of times."); System.out.println("Please enter the dice face number that you would like to be repeated (1-6):"); dieFaceNumber = getInput.nextInt(); System.out.println("Please enter the number of times you would like " + dieFaceNumber + " to appear in a row:"); numberOfRow = getInput.nextInt(); } public void process() { int count = 0; long seed = 19580427; Random generator = new Random( seed ); while(count
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote