Question

In: Computer Science

In Statistics, a histogram is a graphical representation of data using bars of different heights. In...

In Statistics, a histogram is a graphical representation of data using bars of different heights. In a histogram, each bar groups numbers into ranges. Taller bars show that more data falls in that range. A histogram displays the shape and spread of continuous or discrete sample data.

In this project, you will write a program that creates a histogram that allows users to visually inspect the frequency distribution of a set of values.

REQUIREMENTS:

* Read from the data file the values in the range of 1-100 inclusive.

* Produce a histogram as shown in the expected output below to indicate how many input values fell in the range 1 to 10, 11 to 20, and so on.

EXPECTED OUTPUT:

run:

1-10 I*****

11-20 I******

21-30 I**

31-40 I*

41-50 I***********

51-60 I******

61-70 I********

71-80 I***

81-90 I****

91-100 I****

DATA FILE

51 68 42 61 23 50 79 9 12 9 67 85 64 97 41 13 66 47 54 2 46 48 11 52 79 48 73 48 51 15 44 97 19 48 53 13 58 47 95 2 1 65 84 28 89 99 70 67 84 36

Solutions

Expert Solution


import java.io.File;
import java.util.Scanner;

public class Histogram {
   public static void main(String[] args) throws Exception{
       int arr[]=new int[10];
       Scanner sc = new Scanner(new File("histogram.txt"));
       int n;
       while(sc.hasNext()) {
           n=sc.nextInt();
           if(n==100)
               arr[9]++;
           else
               arr[n/10]++;
       }
       String l[]= {"1-10|","11-20|","21-30|","31-40|","41-50|","51-60|","61-70|","71-80|","81-90|","91-100|"};
      
       for(int i=0;i<arr.length;i++) {
           System.out.print(l[i]+" ");
           for(int j=0;j<arr[i];j++) {
               System.out.print("*");
           }
           System.out.println();
       }
   }
}

Note : Please comment below if you have concerns. I am here to help you

If you like my answer please rate and help me it is very Imp for me


Related Solutions

Construct a histogram of your empirical data using eight bars and then five bars. For consistency's...
Construct a histogram of your empirical data using eight bars and then five bars. For consistency's sake, for eight bars use the class width of 0.125. So, your first bar will be 0.000-0.124, your next bar will be 0.125 - 0.249, etc. For five bars, use the class width of 0.2. So, your first bar will be 0.00-0.19, your next bar will be 0.2-0.39, etc. Upload both pictures of your histograms. ***Below are my 50 random numbers. What do I...
1. Using a graphical representation and analytical explanation developed by you, generate a budgetary constraint model...
1. Using a graphical representation and analytical explanation developed by you, generate a budgetary constraint model that shows the movement on the curve for different situations (income exceeds cost of items, income doesn't exceed cost of items etc). In addition, link the model developed back to its impact on choice and preferences. 2. Using a graphical representation and analytical explanation developed by you using a real world example as your point of reference, describe the theory of ordinal utility and...
A _______________ is a graphical representation of how much of a good or service households will...
A _______________ is a graphical representation of how much of a good or service households will want to buy at different prices. A _______________ is a graphical representation of how much of a good or service a firm is willing to sell at some specific price. The intersection of the demand and supply curve is called _______________. This is where the quantity demanded is equalto the quantity supplied. There is a _______________ of a good or service when the quantity...
QUESTION BASED ON URBAN ECONOMICS. Using utility theory for transportation give a graphical representation when number...
QUESTION BASED ON URBAN ECONOMICS. Using utility theory for transportation give a graphical representation when number of vehicles on roads in a city stays fixed when there is an imposition of a congestion tax during peak period travel.
Explain, with the aid of a graphical representation, how the coefficient of determination (R2) is derived
Explain, with the aid of a graphical representation, how the coefficient of determination (R2) is derived
2. According to survey data collected from 500 students in a recent Statistics class, the histogram...
2. According to survey data collected from 500 students in a recent Statistics class, the histogram for the number of hours of sleep they typically got per night is close to the normal curve with an average of 6.5 hours and a SD of 1.4 hours. a) Find percentage of students who sleep between 7 and 8 hours b) A student who sleeps 7 hours per night is at the _______th percentile of the score distribution c) Find the first...
1.which of the following are false? a.The bars of ranges of a Histogram are called classes....
1.which of the following are false? a.The bars of ranges of a Histogram are called classes. b.A Histogram has no or small gaps between bars. c.A Histogram can be used when data is numerical or identifiers. d.A Histogram is similar to a bar chart. 2.Which of the following are true? a.In a Scatter diagram, data is sorted into range. b.A Scatter diagram can compare variables that are not related. c.In a Scatter diagram, all trendlines slope upward. d.A Scatted diagram...
Conceptual Questions:- 1.If the bars of a histogram are all the same height, what is one...
Conceptual Questions:- 1.If the bars of a histogram are all the same height, what is one observation you could make about the distribution of the sample presented in the histogram? 2.   A statistician computes a 95% confidence interval for the number of prior arrests of those convicted of violent crimes. The interval ranged from 1.6 to 3.6 prior arrests. Given these data, what is the probability that the population mean is greater than 3.6 prior arrests? Why? 3.         Why is the...
In a bimodal histogram, the two highest bars will have the same height. True or False
In a bimodal histogram, the two highest bars will have the same height. True or False
python3 Design a class named Histogram to display a histogram of data. The Histogram class contains...
python3 Design a class named Histogram to display a histogram of data. The Histogram class contains the following A number of instance variables/fields to store a histogram of data. You can design them by your own. A constructor that creates a histogram with the following a list of data. It may have more than 2 columns. x_width: the width of the 1st column in the horizontal histogram. The default value is 5. y_width: the width of the 2nd column in...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT