Question

In: Computer Science

Based upon the following code (or writing your own from scratch) Do either of the following...


Based upon the following code (or writing your own from scratch)

Do either of the following two: Moderately Detailed or Bare-Bones

MODERATELY DETAILED

BARE-BONES

import java.util.Random;

import java.util.Scanner;

//end goal/aim/ask; WAP high and low game

//user choice H or L; and

//single round

//dice roll: generate a random number 0 and 20

//high is 11 to 20 and low is 1 to 10

public class Main {

  public static void main( String[] args ) {

    int score = 0;

    score += playRound();

    gameResult( score );

  }

  

  public static int playRound() {

    // Create instance of Random class

    Random randGenerator = new Random();

  

    // Generate random integers in range 1 to 20

    int diceRoll = <TODO>;

    // Create a Scanner object

    Scanner myInput = new Scanner(System.in);

    //Acquire user input

    <TODO>;

    // Compare random number to user input

    // If the user won

    if( <TODO> ) {

      System.out.println( "Point awarded!" );

      return 1;

    }

    // Otherwise

    else {

      System.out.println( "No point awarded..." );

      return 0;

    }

  }

  

  public static void gameResult( int score ) {

    // <TODO> - Report result based on user's score

  }

}

public class Main {

  public static void main( String[] args ) {

    // Play a round of the dice game

    <TODO>

    // Report the results

    <TODO>

  }

  

  public static int playRound() {

    // Generate a random number

    <TODO>

    //Acquire user input

    <TODO>;

    // Compare random number to user input

    <TODO>

    // Return a score

    <TODO>

  }

}

Finalize the game logic to generate a working game.

Paste your code below:

Paste your output after playing 5 rounds:

Solutions

Expert Solution

//MODERATELY DETAILED

public class Main()
{
public static void main(String[] args) {
// TODO code application logic here
int i=0;
int score=0;
while(i<5)//for playing 5 time or you take input from user too for how many times the //want to play
{
  

score += playRound();
i++;
}

gameResult( score );
}
public static int playRound() {
Random randGenerator=new Random();
int diceRoll =randGenerator.nextInt(20-1+1)+1;//random.nextInt(max-min+1)+min(for generating random number
//System.out.println(diceRoll);
Scanner myInput =new Scanner(System.in);
char ch;
System.out.print("Please enter you choice H for high L for low ");
ch=myInput.next().charAt(0);//taking input from user whether high or low

//check if ch is Low and diceRoll value is low or not not.

//if ch is High whether diceRoll is high or not
if((ch=='L'&&diceRoll>=1&&diceRoll<=10)||(ch=='H'&&diceRoll>=11&&diceRoll<=20))
{System.out.println("Points awarded!");
return 1;
}
else
{
System.out.println("No points awarded!");
  
return 0;
}
  
  
  
}
public static void gameResult(int score)
{
System.out.println("Your score is "+score);
  
}
  
}

//Hope you like my answer please leave good rating thank you


Related Solutions

how to implement your own filter and zip functions for a stream in scala from scratch?...
how to implement your own filter and zip functions for a stream in scala from scratch? can someone provide an example code please? Will Rate! Thanks
Based upon your learning in this course and your own personal and professional experiences with healthcare,...
Based upon your learning in this course and your own personal and professional experiences with healthcare, what do you feel needs to happen in our healthcare delivery system to achieve better access and higher quality care for all Americans?
1. Read each question. 2. Answer based upon your knowledge of the chapter and your own...
1. Read each question. 2. Answer based upon your knowledge of the chapter and your own experience. 3. Indicate by number (1 or 2) which question you are answering first. 4. Proofread your answer--demonstrate your best writing ability. CHAPTER 12 Effective Business Presentations 1. What role do visuals play in business presentations? 2. The four Ps: Planning, preparing, practicing, and presenting, are very important to presentations. Explain how you understand each of them. Is one more important than the others?
Reflect on a strategy that was poorly executed either from your own organization or from a...
Reflect on a strategy that was poorly executed either from your own organization or from a researched example. Why did the implementation of strategy fail? What could have been done differently to produce more successful execution? Using this same organization, discuss the best method for entering a foreign market and explain your reasoning. If your company is already operating internationally, discuss its global strategy and how they successfully expanded. Also consider, if there are additional markets they should expand into...
Writing your own shell in Linux with execvp Only code void cmdToArray() Program should be able...
Writing your own shell in Linux with execvp Only code void cmdToArray() Program should be able to execute ls -l. #include <stdio.h> #include <string,h>// strcmp #include <stdlib.h>// exit #include <unistd.h>// fork, exec #include <sys/wait.h>// wait #define MAXARGS 20 #define ARGLEN 256 void execute(char *cmd, char *arglist[]); void cmdToArray(char *cmd, char *arglist); int main(void) { int pid; char *arglist[MAXARGS+1]; // array of pointers char cmd[ARGLEN]; // read stuff here while (1) { printf("cmd> "); fgets(cmd, ARGLEN, stdin); // remove newline from...
What concept best explains why you wouldn’t want to make your own clothes completely from scratch...
What concept best explains why you wouldn’t want to make your own clothes completely from scratch and instead will normally prefer to buy them from a retailer? Barville is a country that produces either all dumbbells or all sandals or a combination of two. (30 points total) Draw a production possibilities frontier and label the x and y axes appropriately. Place a point that shows where the country would be operating if a recession hits and companies are laying off...
Create a 50+ word ethics code for your small business based upon the information provided below....
Create a 50+ word ethics code for your small business based upon the information provided below. You may want to search for various codes of conduct/code of ethics to see how these are typically written for a business. You are the owner of a new pet grooming boutique called Cats Rule-Dogs Obey. You will need to hire three groomers. In addition to grooming cats and dogs, the groomers will be responsible for scheduling appointments, keeping the boutique clean and stock...
Your responses are to be based on your own experiences and insights. Do not use materials...
Your responses are to be based on your own experiences and insights. Do not use materials and examples from other sources, including the Internet. Students have used examples from outside sources in the past and have failed this final assessment and in some cases, failed the course due to evidence of plagiarism. Describe how you could use hypothesis testing to help make a decision in your current job, a past job, or a life situation. Include a description of the...
TASK: Based upon the following code: import java.util.Scanner; // Import the Scanner class public class Main...
TASK: Based upon the following code: import java.util.Scanner; // Import the Scanner class public class Main {   public static void main( String[] args ) {     Scanner myInput = new Scanner(System.in); // Create a Scanner object     System.out.println("Enter (3) digits: ");     int W = myInput.nextInt();     int X = myInput.nextInt();     int Y = myInput.nextInt();      } } Use the tools described thus far to create additional code that will sort the integers in either monotonic ascending or descending order. Copy your code and...
Upon the successful completion of this module, you should understand the following concepts: IN YOUR OWN...
Upon the successful completion of this module, you should understand the following concepts: IN YOUR OWN WORDS AND SHOULD BE AT LEAST 100 WORDS 1- Networking 2- Negotiations process 3- Ethics and influencing
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT