Question

In: Computer Science

Java - Design and implement an application that creates a histogram that allows you to visually...

Java - Design and implement an application 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, and so on. Print one asterisk for each value entered.

Sample Output:

1 - 10 | *****
11 - 20 | *******
21 - 30 | *
31 - 40 | *
41 - 50 | *
51 - 60 | *
61 - 70 | *
71 - 80 | *
81 - 90 | *
91 - 100 | *

Thank you!

Solutions

Expert Solution

import java.util.*;

public class Main
{
   public static void main(String[] args)
   {
   //Scanner
   Scanner input = new Scanner(System.in);
  
   //array declaration
   int values[] = new int[100];
  
   //variable declaration
   int size=0, num;
  
   //while loop
   while(true)
   {
   //get user input
       System.out.print("Enter a number(1:100 and 0 for Exit): ");
   num = input.nextInt();
   if(num<1 || num>100)
   break;
   else
   values[size++] = num;
   }
  
   //display the histogram
   System.out.println("\nThe histogram is given below: ");
   for(int i=1; i<100; i=i+10)
   {
   System.out.print("\n"+i+" - "+(i+9)+" | ");
   for(int j=0; j<size; j++)
   {
   if(values[j]>=i && values[j]<=(i+9))
   System.out.print("*");
   }
   }
   }
}

OUTPUT:

Enter a number(1:100 and 0 for Exit): 5
Enter a number(1:100 and 0 for Exit): 18
Enter a number(1:100 and 0 for Exit): 6
Enter a number(1:100 and 0 for Exit): 13
Enter a number(1:100 and 0 for Exit): 7
Enter a number(1:100 and 0 for Exit): 6
Enter a number(1:100 and 0 for Exit): 9
Enter a number(1:100 and 0 for Exit): 15
Enter a number(1:100 and 0 for Exit): 16
Enter a number(1:100 and 0 for Exit): 18
Enter a number(1:100 and 0 for Exit): 14
Enter a number(1:100 and 0 for Exit): 13
Enter a number(1:100 and 0 for Exit): 56
Enter a number(1:100 and 0 for Exit): 36
Enter a number(1:100 and 0 for Exit): 25
Enter a number(1:100 and 0 for Exit): 45
Enter a number(1:100 and 0 for Exit): 34
Enter a number(1:100 and 0 for Exit): 55
Enter a number(1:100 and 0 for Exit): 66
Enter a number(1:100 and 0 for Exit): 77
Enter a number(1:100 and 0 for Exit): 88
Enter a number(1:100 and 0 for Exit): 99
Enter a number(1:100 and 0 for Exit): 0

The histogram is given below:

1 - 10 | *****
11 - 20 | *******
21 - 30 | *
31 - 40 | **
41 - 50 | *
51 - 60 | **
61 - 70 | *
71 - 80 | *
81 - 90 | *
91 - 100 | *


Related Solutions

8.3) Design and implement an application that creates a histogram that allows you to visually inspect...
8.3) Design and implement an application 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, and so on. Print one asterisk for each value entered. 1 -...
Design and implement a Java program that creates a GUI that will allow a customer to...
Design and implement a Java program that creates a GUI that will allow a customer to order pizza and other items from a Pizza Paarlor. The customer should be able to order a variety of items which are listed below. The GUI should allow the customer (viaJavaFX UI Controls - text areas, buttons, checkbox, radio button, etc.) to input the following information: Name of the customer First Name Last Name Phone number of the customer Type of food being order...
programing language JAVA: Design and implement an application that reads a sentence from the user, then...
programing language JAVA: Design and implement an application that reads a sentence from the user, then counts all the vowels(a, e, i, o, u) in the entire sentence, and prints the number of vowels in the sentence. vowels may be upercase
JAVA : Design and implement an application that plays the Rock-Paper-Scissors game against the computer. When...
JAVA : Design and implement an application that plays the Rock-Paper-Scissors game against the computer. When played between two people, each person picks one of three options (usually shown by a hand gesture) at the same time, and a winner is determined. In the game, Rock beats Scissors, Scissors beats Paper, and Paper beats Rock. The program should randomly choose one of the three options (without revealing it) and then prompt for the user’s selection. At that point, the program...
Please implement the java method addInOrder() that allows you to create and maintain the lists in...
Please implement the java method addInOrder() that allows you to create and maintain the lists in the order required. The addInOrder method must work with different external Comparator objects. (Hint: Consider creating and using a private compare method and a private Comparator reference as members of your SLL class. If your SLL is constructed without any parameter, then you should initialize the internal Comparator object reference to null. Otherwise, you should initialize it to the external Comparator object passed as...
Design a program in JAVA that allows you to experiment with different sort algorithms. The algorithms...
Design a program in JAVA that allows you to experiment with different sort algorithms. The algorithms are shell sort and quick sort. Assume that input data is stored in a text file. Experimenting with a prototype data (integers from 1 to 10) to ensure that your implementation works correctly and the results match expectations. The program will sort what is in the text file and print the amount of comparisons and exchanges for both algorithms.
using Java Your mission in this exercise is to implement a very simple Java painting application....
using Java Your mission in this exercise is to implement a very simple Java painting application. Rapid Prototyping The JFrame is an example that can support the following functions: 1. Draw curves, specified by a mouse drag. 2. Draw filled rectangles or ovals, specified by a mouse drag (don't worry about dynamically drawing the shape during the drag - just draw the final shape indicated). 3. Shape selection (line, rectangle or oval) selected by a combo box OR menu. 4....
Android Studio. Java. Please create an application that -> An activity that allows user to enter...
Android Studio. Java. Please create an application that -> An activity that allows user to enter name, gender, date of birth, state of residence (selected from a pre-defined list: CA, AZ, NV, OR), email address and favorite website. This activity has a button "Show Data" that displays detail entered
Implement and test a TaskList application in Java that will allow a client to manage information...
Implement and test a TaskList application in Java that will allow a client to manage information about daily tasks.  A task has a task name, is scheduled on a specific day of the week and can have a comment attached to it. Together, the task name and day uniquely identify a task. There may be tasks with the same name scheduled for different days of the week. The application should allow the client to start with an empty TaskList and then...
Purpose: To write an Object-Oriented application that creates a Java class with several instance variables, a...
Purpose: To write an Object-Oriented application that creates a Java class with several instance variables, a constructor to initialize the instance variables, several methods to access and update the instance variables’ values, along with other methods to perform calculations. Also, write a test class that instantiates the first class and tests the class’s constructor and methods. Details: Create a class called Rectangle containing the following: Two instance variables, An instance variable of type double used to hold the rectangle’s width....
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT