Concept explainers
//you haven't mentioned the language, I have done in java, if u need in other languages please //comment
public class Die {
//method return values from 1to6
int roll()
{
return (int)(Math.random()*6+1);
}
public static void main(String args[])
{
//part 1
Die comp=new Die();
Die user=new Die();
 Â
int comp_win=0,user_win=0,tie=0;
int comp_roll=0,user_roll=0;
//part 2
for(int i=0;i<10;i++)
{
comp_roll=comp.roll();
user_roll=user.roll();
if(comp_roll>user_roll)
comp_win++;
else if(comp_roll<user_roll)
user_win++;
else
tie++;
System.out.println("***At iteration"+(i+1));
System.out.println("Computer rolled:"+comp_roll);
System.out.println("User rolled:"+user_roll);
System.out.println("currently Computer score:"+comp_win+" User score"+user_win);
}
if(comp_win>user_win)
{ System.out.println("The Grand winner is Computer.");
System.out.println("Total Computer score:"+comp_win+" User score"+user_win+" no.of ties:"+tie);
}
else if(comp_win<user_win)
{ System.out.println("The Grand winner is User.");
System.out.println("Total Computer score:"+comp_win+" User score"+user_win+" no.of ties:"+tie);
}
else
{ System.out.println("Its overall Tie");
System.out.println("Total Computer score:"+comp_win+" User score"+user_win+" no.of ties:"+tie);
}
Trending nowThis is a popular solution!
Step by stepSolved in 2 steps with 1 images
- how to assign a student an ID number and print it when asked in JAVA can you give me an example if there are several students and I enter a specific student ID it shows me their first name last name and agearrow_forwardJAVA PROGRAMMING LANGUAGE PLEASE. Convert the following UML to code in the image given below.arrow_forwardJava requires its method arguments to be sent in as values, not references. And what, precisely, does it entail?arrow_forward
- How to count the number of digits in a number in java?arrow_forwardHow can you generate random numbers in Java?arrow_forwardFIX THE CODE PROVIDED BELOW Part 2 - Syntax Errors and Troubleshooting The code below has many syntax (and other) errors. Tasks:Compile the code and fix the errors one at a time. // Lab1a.java // This short class has several bugs for practice. // Authors: Carol Zander, Rob Nash, Clark Olson, you public class Lab1a { public static void main(String[] args) { compareNumbers(); calculateDist(); } publicstatic void compareNumbers() { int firstNum = 5; int secondNum; System.out.println( "Sum is: + firstNum + secondNum ); System.out.println( "Difference is: " + (firstNum - secondNum ); System.out.println( "Product is: " + firstNun * secondNum ); } public static void calculateDistance() { int velocity = 10; //miles-per-hour int time = 2, //hoursint distance = velocity * timeSystem.out.println( "Total distance is: " distanace); } } Part 3 - Print Statements and Simple Methods Use "print" and "println" statements, but use method calls to reduce the number of repeated "print"and "println"…arrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education