import java.util.Scanner; // for reading input data /** Java application that simulates the rolling of a die. ** ** The user enters, in response to a prompt, the number of times that the ** die is to be rolled. The die is rolled that many times, with each ** roll's result being reported (by the display of a number between 1 and 6). ** The program then displays a message indicating the percentage of rolls ** that resulted in and odd value, and a message indicating the percentage ** of rolls that resulted in an even value. */ public class DieApplication { public static void main(String[] args) { // Establish Scanner object to interpret input entered at keyboard. Scanner keyboard = new Scanner(System.in); // Prompt user to enter input regarding # of rolls to make System.out.print("Enter # times to roll: "); // Read user's response and store in a variable int numRolls = keyboard.nextInt(); // Create a Die object and store a reference to it in a variable. /* code needed here */ // Display message introducing output describing rolls of die. System.out.print("Results: "); // Roll the die object the # of times specified by the user, // reporting the result of each roll. for (int i=0; i != numRolls; i=i+1) { // Roll the die. /* code needed here */ // Display the result. /* code needed here; modify the following statement */ System.out.print("?"); } // Skip to next line; System.out.println(); // Calculate and report percentage of rolls that resulted in an odd number /* code needed here */ // Calculate and report percentage of rolls that resulted in an odd number /* code needed here */ } }
↧
Rolling a Die and giving percent of odd and even with user input
↧