Let the player roll 5 normal 6 sided die. 2 The player gets to choose which of t
ID: 3624632 • Letter: L
Question
Let the player roll 5 normal 6 sided die.
2 The player gets to choose which of the die to keep or which to reroll - that is your design system, but explain it in messages to the player.
3 Reroll the selected die not kept
4 Repeast step 2 and 3
Multiply any duplicated die together. Add the total. Display the result.
Example: I roll a 53325.
I keep the fives and reroll the rest.
I get 5 3 2
I keep the fives and reroll
I get 2 2
The score then is 5*5*5+2*2 or 129
Remember to have some way for them to quit the game or to keep all 5 after a roll.
Don't forget user interface and documentation both internal and external.
Explanation / Answer
please rate - thanks
sorry it took so long-it's been a busy week
import java.util.*;
public class dice
{public static void main(String [] args)
{Scanner in=new Scanner(System.in);
int[] die=new int[5];
int i,change;
for(i=0;i<5;i++)
die[i]=roll();
report(die);
System.out.print("How many die do you wish to reroll (0-5)? ");
change=in.nextInt();
while(change>0)
{getnew(die,change,in);
report(die);
System.out.print("How many die do you wish to reroll (0-5)? ");
change=in.nextInt();
}
score(die);
}
public static void getnew(int die[],int change,Scanner in)
{int []dupe=new int[6];
int [] changed=new int[6];
int i,n,j,k;
for(i=0;i<5;i++)
dupe[die[i]-1]++;
System.out.println("What numbers do you want to change: ");
for(i=0;i<change;i++)
{System.out.print("Enter # "+(i+1)+" to change: ");
n=in.nextInt();
for(j=0;j<5;j++)
{if(die[j]==n)
if(changed[j]==0)
{die[j]=roll();
changed[j]=1;
}
}
}
}
public static int roll()
{int n=(int)(Math.random()*6)+1;
return n;
}
public static void score(int die[])
{int i,value=0;
int []dupe=new int[6];
for(i=0;i<5;i++)
dupe[die[i]-1]++;
for(i=0;i<6;i++)
if(dupe[i]>1)
value+=Math.pow(i+1,dupe[i]);
System.out.println("Your score is "+value);
}
public static void report(int die[])
{int i;
System.out.print("I roll a: ");
for(i=0;i<5;i++)
System.out.print(die[i]);
System.out.println();
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.