Concept explainers
Can someone please help me with the following coding given based on the instructions (//*** in bold)? I am not sure on how to go about it here. Just as a side note, this is coding that is going to be used for a working Yahtzee program. I am also using the IntelliJ IDEA application for this code. Thanks for the help!
public static int calculateUpperSectionCategory(int dieNumber) {
int score = 0;
//***
//*** INSTRUCTIONS FOR CODE FOR YOU TO WRITE
//***
//*** 1) Replace these five if-statement structures with the code in Steps 2 & 3:
//***
//*** if (die1 == dieNumber)
//*** score += die1;
//***
//*** if (die2 == dieNumber)
//*** score += die2;
//***
//*** if (die3 == dieNumber)
//*** score += die3;
//***
//*** if (die4 == dieNumber)
//*** score += die4;
//***
//*** if (die5 == dieNumber)
//*** score += die5;
//***
//*** 2) In place of the code in Step 1, write a for-loop that iterates over every element in the array variable "dice".
//***
//*** 3) Code block for the for-loop in Step 2:
//*** A) Using the for-loop's control variable as an index into array variable "dice", write an if-statement that checks the value of each element in the array variable "dice" for "equality to" parameter variable "dienumber".
//*** B) If the condition in Step 3A evaluates to true, then accumulate the value of that die into variable "score".
//***
//*** NOTE: 1) Array variable "dice" replaces all of the individual die variables (e.g. die1, die2, etc).
//*** 2) You are replacing the five if-statement structures that use the individual die variables with a for-loop that contains a nested if-statement structure that references into array variable "dice".
//***
//*** This can be as few as three lines of code not including any curly braces.
//***
Trending nowThis is a popular solution!
Step by stepSolved in 4 steps with 2 images
- Accumulating Totals in a Loop Summary In this lab, you add a loop and the statements that make up the loop body to a Java program that is provided. When completed, the program should calculate two totals: the number of left-handed people and the number of right-handed people in your class. Your loop should execute until the user enters the character X instead of L for left-handed or R for right-handed. The inputs for this program are as follows: R, R, R, L, L, L, R, L, R, R, L, X Variables have been declared for you, and the input and output statements have been written. Instructions Ensure the file named LeftOrRight.java is open. Write a loop and a loop body that allows you to calculate a total of left-handed and right-handed people in your class. Execute the program by clicking Run and using the data listed above and verify that the output is correct.arrow_forwardJava, i have the RNG code already only the RandomNumberGenerator step that I need help with.arrow_forwardFinish the TestPlane class that contains a main method that instantiates at least two Planes. Add instructions to instantiate your favorite plane and invoke each of the methods with a variety of parameter values to test each option within each method. To be able to test the functionality of each phase, you will add instructions to the main method in each phase.arrow_forward
- I have the code for this one but I do seem to be missing something. This is the question - Modify the CountByFives application so that the user enters the value to count by. Start each new line after 10 values have been displayed. This is the code I have. I have got one check right but I can't get the other two - import java.util.*; public class CountByAnything { // Modify the code below public static void main (String args[]) { Scanner input = new Scanner(System.in); final int START; System.out.print("Please enter the value: "); START = input.nextInt(); final int STOP = 500; final int NUMBER_PER_LINE = 10; for(int i = START; i <= STOP; i += START) { System.out.print(i + " "); if(i % NUMBER_PER_LINE == 0) System.out.println(); } } }arrow_forwardActive buzzer project: Write an algorithm for the below code for all steps. Then write a conclusion (test&debug) for the code. Also, write comments for the code explaining each line.arrow_forwardPlease try to explain how to do it. Please in java file. Loops is the topic.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