What is Benford’s Law?
Benford’s Law involves looking at the first digit of a series of numbers. For example, suppose that you were to use a random number generator to generate integers in the range of 100 to 999 and you looked at how often the number begins with 1, how often it begins with 2, and so on. Any decent random number generator would spread the answers out evenly among the 9 regions, so we’d expect to see each digit about one-ninth of the time (11.1%). But with a lot of real-world data, we see a very different distribution.
The expected distribution under Benford’s Law is shown below:
1: 30.1%, 2: 17.6%, 3: 12.5%, 4: 9.7%, 5: 7.9%, 6: 6.7%, 7: 5.8%, 8: 5.1%, 9: 4.6%
You should use this distribution in your program. You are being provided with a text file giving population data for 247 countries and territories. Your program should read in the data in this file and extract the information needed to keep count of how often each first digit is found. It may be useful to know that the ASCII value for the character ‘1’ is 49.
For this assignment, you are to design a Java class named Benford that uses an ArrayList object to store counts of first digits. A Benford object will have only one field, the ArrayList object.
You will need the following class methods (at a minimum – you may add as many helper methods as you wish):
• A constructor to construct Benford objects
• A class method named readCounts() that takes a file name as a parameter and that reads
and stores data from a text file into a Benford object.
• A class method named benfordPercents() that uses the data in the Benford object to fill an array of double values giving the percentage counts for each initial digit based on the raw counts contained in the Benford object.
You are also to design a client class named BenfordPlot that displays the data in the Benford object graphically. The output should be similar to the examples shown below, except your plot should be titled “Population of Countries.” The “^” symbol in the plot below indicated the
expected Benford value. The second plot shown below displays a distribution that does NOT follow Benford’s Law
Please include the following files:
• Benford.java (your Benford class code)
• BenfordPlot.java (your client code that using the DrawingPanel code to produce a graphical display of the data contained in a Benford object).
• In a comment at the top of your client code (after your name, etc.), include your opinion as to whether or not the data follow Benford’s Law.
Design and implementation guidelines:
• Javadoc comment all class files and methods
• Use validation and generate and handle exceptions as appropriate
• Try to write well-structured code - use methods to eliminate redundancy and break large methods into smaller, logical subproblems
Trending nowThis is a popular solution!
Step by stepSolved in 3 steps with 2 images
- Write a program using Python to solve the locker riddle which reads as follows: Imagine 100 lockers numbered 1 to 100 with 100 students lined up in front of those 100lockers:The first student opens every locker.The second student closes every 2nd locker.The 3rd student changes every 3rd locker; if it’s closed, she opens it; if it’s open, she closes it.The 4th student changes every fourth locker (e.g., 4th, 8th, etc.).The 5th student changes every 5th locker (e.g., 5th, 10th, etc.).That same pattern continues for all 100 students. Which lockers are left open after all 100 students have walked the rowof lockers?arrow_forwardComputer Science You must count the number of strings of length 6 over the alphabet A = {x, y, z}. Any string of length 6 can be considered as a 6-tuple. For example, the string xyzy can be represented by the tuple (x,y,z,y). So the number of strings of length 6 over A equals the number of 6-tuples over A, which by product rule is N. Find N. (Use the following product rule for any finite set A and any natural number n : |A^n|=|A|^n)arrow_forwardWrite code using python or in python.arrow_forward
- A grid needs a system for numbering the tiles in order to allow random-access lookup.For instance, the rows and columns of a square grid provide a natural numbering for the tiles. Create plans for hexagonal and triangular grids. Create a rule for identifying the neighbourhood (i.e., nearby tiles) of a certain tile in the grid using the numbering scheme. For instance, the neighbourhood of tile I j in a four-connected square grid with indices of I for rows and j for columns may be described as neighbourhood(i, j) = I 1, j, I j 1.arrow_forwardImagine you have 331 sheep, and you are going to use primitive counting to write a tally stick for the King. Suppose you carry out the procedure as usual, filling the pens with sheep, and liberating the sheep from pen 2 (and any extra sheep); then doing it again, doing it again, etc., until you get down to one sheep.How many sheep will you have in the first pen After one round? After two rounds? After three rounds?arrow_forwardQ. Given a 2d grid map of '1's (land) and '0's (water),count the number of islands.An island is surrounded by water and is formed byconnecting adjacent lands horizontally or vertically.You may assume all four edges of the grid are all surrounded by water. Example 1: 11110110101100000000Answer: 1 Example 2: 11000110000010000011Answer: 3""" def num_islands(grid): count = 0 for i in range(len(grid)): for j, col in enumerate(grid[i]): if col == 1: dfs(grid, i, j) count += 1 Please code it. .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