So this is a Java question and I don\'t know how to make it. It\'s on Chapter 4
ID: 3540901 • Letter: S
Question
So this is a Java question and I don't know how to make it. It's on Chapter 4 on Java Programming by Joyce Farrell
Using the Die class, write an application that randomly 'throws' five dice for the computer and five dice for the player. Display the values and then, by observing the results, decide who wins based on the following hierarchy for Die values. (The computer will not decide the winner; the player will determine the winner based on observation.) Any higher combination beats a lower one; for example, five of a kind beats four of a kind.
-Five of a kind
-fout of a kind
-three of a kind
-a pair
After you learn about decision making in the next chapter, you will be able to make the program determine whether you or the computer had the better roll, after you read the chapter Indoduction to Arrays, you will be able to make the determineation more efficient. For now, just observe how the values change as you execute the program multiple times. Save the application as FiveDice.Java
Explanation / Answer
Die.java
package xyz;
public class Die
{
public int randomValue;
public int[] randomArray=new int[5];
public Die()
{
//randomValue=((int)(Math.random()*100));
for(int i=0;i<5;i++)
{
randomArray[i]=((int)(Math.random()*100));
}
}
public int[] dieValue(){
for(int i=0;i<5;i++){
while(randomArray[i]>6)
{
randomArray[i]=(int)randomArray[i]/6;
}
}
return randomArray;
}
}
FiveDice.java
package xyz;
import java.util.Scanner;
public class FiveDice {
public static void main(String[] args)
{
Scanner in=new Scanner(System.in);
System.out.println("to throw dices for computer type 'y'");
String x=in.nextLine();
if(x.equals("y") || x.equals("Y")){
Die dice1=new Die();
System.out.println("Okay dices for computer has been thrown now to throw dices for you Please type 'y'");
x=in.nextLine();
if(x.equals("y")
|| x.equals("Y")){
Die dice2=new Die();
System.out.println("Okay dices for you also has been thrown");
System.out.println("dices for you "+"dices for computer ");
for(int i=0;i<5;i++)
{
System.out.println(dice2.dieValue()[i]+" "+dice1.dieValue()[i]+" ");
}
}
else
System.out.println("try again");
}
else
System.out.println("Try again");
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.