Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

IN JAVA Design and implement a program that creates a histogram that allows you to visually inspect the frequency distribution of a set of values.

IN JAVA

Design and implement a program that creates a histogram that allows you to visually inspect the frequency distribution of a set of values. The program should read in an arbitrary number of integers that are in the range 1 to 100 inclusive; then produce a chart similar to the one below that indicates how many input values fell in the range 1 to 10, 11 to 20, 21 to 30, and so on. Print one asterisk for each value entered.

Use the following:

System.out.print("1- 10\t |");

...

System.out.print("91-100\t |");

Do not change anything in the main method.

The program will terminate if a number that's too small or too large is entered.

Starter code

import java.util.ArrayList; import java.util.Scanner;

/** * * @author dfreer */ public class Histogram {

public void addValue(int i){ }

public void viewHistogram(){ System.out.print("1- 10\t |"); System.out.print("11-20\t |"); System.out.print("21-30\t |"); System.out.print("31-40\t |"); System.out.print("41-50\t |"); System.out.print("51-60\t |"); System.out.print("61-70\t |"); System.out.print("71-80\t |"); System.out.print("81-90\t |"); System.out.print("91-100\t |"); }

/** * @param args the command line arguments */ public static void main(String[] args) { // TODO code application logic here Scanner scanner = new Scanner(System.in); Histogram h = new Histogram(); int curNumber = 0; while(curNumber >= 0 && curNumber <= 100){ while(!scanner.hasNextInt()) scanner.next(); curNumber = scanner.nextInt(); h.addValue(curNumber); } h.viewHistogram();

}

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Beginning C# 5.0 Databases

Authors: Vidya Vrat Agarwal

2nd Edition

1430242604, 978-1430242604

More Books

Students also viewed these Databases questions

Question

How wide are Salary Structure Ranges?

Answered: 1 week ago