Question

In: Computer Science

Assignment 7 Preparation This assignment will focus on the use of loops, random numbers, named constants,...

Assignment 7 Preparation

This assignment will focus on the use of loops, random numbers, named constants, and arrays.

Assignment 7
Assignment 7 Submission


Follow the directions below to submit Assignment 7:

  1. Create a Java program.
  2. The class name for the program should be 'RandomDistributionCheck'.
  3. In the main method you should perform the following:
    • You should generate 10,000,000 random numbers between 0 - 19.
    • You should use an array to hold the number of times each random number is generated.
    • When you are done, generating random numbers, you should output the random number, the number of times it occurred, and the percentage of all occurrences. The output should be displayed using one line for each random number.
    • Use named constants for the number of iterations (10,000,000) and a second named constant for the number of unique random numbers to be generated (20).

Grading criteria:

Solutions

Expert Solution

Thanks for the question, here is the Java class

==========================================================================

import java.util.Random;

public class RandomDistributionCheck {


    public static void main(String[] args) {


        Random random = new Random();
        final int ITERATION_COUNT = 10000000; // constant
        final int UNIQUE_NUMBERS = 20; // constant

        int numberOccurences[] = new int[UNIQUE_NUMBERS]; // array to store the count

        for (int count = 1; count <= ITERATION_COUNT; count++)
            numberOccurences[random.nextInt(UNIQUE_NUMBERS)]++;

// print header
        System.out.printf("%-8s %18s %22s\n", "Number", "Occurrences", "Percentage(%)");
        for (int index = 0; index < UNIQUE_NUMBERS; index++) {

// print the number the occurence count and percentage
            System.out.printf("%-8d %15d %18.2f\n", index, numberOccurences[index], numberOccurences[index] * 100.0 / ITERATION_COUNT);
        }
    }
}

================================================================


Related Solutions

Assignment 7 Preparation This assignment will focus on the use of loops, random numbers, named constants,...
Assignment 7 Preparation This assignment will focus on the use of loops, random numbers, named constants, and arrays. Assignment 7 Assignment 7 Submission Follow the directions below to submit Assignment 7: Create a Java program. The class name for the program should be 'RandomDistributionCheck'. In the main method you should perform the following: You should generate 10,000,000 random numbers between 0 - 19. You should use an array to hold the number of times each random number is generated. When...
Assignment Description This assignment focuses on programming basics; expressions, variables, constants, methods, selection and loops. Danny...
Assignment Description This assignment focuses on programming basics; expressions, variables, constants, methods, selection and loops. Danny runs an ice cream shop in the inner suburbs of Melbourne. Due to the growing number of customers, Danny has decided to take on extra casual employees. In order to manage payroll for his employees, Danny has decided to develop an employee payroll management system. Details of each employee to be maintained in the system will include; employee id, name, gender (M or F),...
This assignment will acquaint you with the use of while loops and boolean expressions. You will...
This assignment will acquaint you with the use of while loops and boolean expressions. You will create a program that acts as a score keeper of a racquet ball game between two players. The program will continually ask the user who the winner of every point is as the game is played. It will maintain the scores and declare the match is over, using these rules: (1) A game is over when a. one of the players wins 7 points...
This assignment is about creating a online movie rental store. Use arrays and loops for this...
This assignment is about creating a online movie rental store. Use arrays and loops for this assignment. 1) Create a web page containing a list of movie names available for rent (at least 10 movies), so that each time you visit the home page, you see a different order of movies in the list. The movie names are required, all other information is optional.) 2) The rental price for each movie ranges between $1.99 to $7.99.             • Create an...
C++ Please Do not use loops!! Assignment : Dice Roll Redux In "Dungeons & Dragons" and...
C++ Please Do not use loops!! Assignment : Dice Roll Redux In "Dungeons & Dragons" and similar role-playing games, dice with different numbers of sides are used to determine the outcomes of events throughout the game. There are different dice for different occasions: 4-sided, 6-, 8-, 10-, 12-, and 20-sided dice are common. A required roll is typically designated <n>d<s> where <n> is the number of dice to throw and <s> is the number of sides on those dice. For...
Exp 7. Preparation of Copper (I) Chloride Name ________________________ Experiment replacement assignment. The process of preparing...
Exp 7. Preparation of Copper (I) Chloride Name ________________________ Experiment replacement assignment. The process of preparing copper (I) chloride, CuCl, from metallic copper consists of the reactions listed below: Rxn 1. Cu (s) + 4H+ (aq) + 2NO3 – (aq) --> Cu2+ (aq) + 2NO2 (g) + 2H2O(l) Rxn 2. omitted, as it does not involve copper Rxn 3. Cu2+ (aq) + CO3 2- (aq) ---> CuCO3 (s) Rxn.4 CuCO3 (s) + 2H+ (aq) + 4Cl– (aq) ---> CuCl4 2-...
Write a well-commented java program that demonstrates the use of loops, and generation of random integers...
Write a well-commented java program that demonstrates the use of loops, and generation of random integers (Code will be written in Dr. Java) You are taking some time off from your paint business and currently are on vacation in Bahamas. You decide to write a Java program that generates 10 random numbers between 1 and 20 (all integers). You cannot use arrays (even if you know what they are) to store these numbers. It then picks up the largest number...
JAVA Lab Assignment #13:  Looping Lab with both types of loops. This lab demonstrates the use of...
JAVA Lab Assignment #13:  Looping Lab with both types of loops. This lab demonstrates the use of the While Loop and the Do While Loop as error checking mechanisms. You will be using each of these loops to solve the same problem. Please put them both in the same program. When you test the code, you will not see a difference in the way they execute - but there will be a difference in the logic when writing the code. You...
c programing language This assignment, which introduces the use of loops, solves the following problem: given...
c programing language This assignment, which introduces the use of loops, solves the following problem: given a starting location in a city, how long does it take a “drunken sailor” who randomly chooses his direction at each intersection to reach the city’s border? You will read input values to set up the problem parameters, run several trials to determine an average number of steps for the sailor to reach the border, and output the results. This problem is an example...
For this assignment, write a program that will generate three randomly sized sets of random numbers...
For this assignment, write a program that will generate three randomly sized sets of random numbers using DEV C++ To use the random number generator, first add a #include statement for the cstdlib library to the top of the program: #include <cstdlib> Next, initialize the random number generator. This is done by calling the srand function and passing in an integer value (known as a seed value). This should only be done ONE time and it MUST be done before...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT