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

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
Bank Accounts in Java! Design and implement a Java program that does the following: 1) reads...
Bank Accounts in Java! Design and implement a Java program that does the following: 1) reads in the principle 2) reads in additional money deposited each year (treat this as a constant) 3) reads in years to grow, and 4) reads in interest rate And then finally prints out how much money they would have each year. See below for formatting. Enter the principle: XX Enter the annual addition: XX Enter the number of years to grow: XX Enter the...
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....
Create a Java application that creates a window in which multiple bouncing balls can be animated....
Create a Java application that creates a window in which multiple bouncing balls can be animated. have attached a text file of the source found on that site. You can paste the entire application into an Eclipse source file named BounceThread.java and it will compile and run. Optionally, you may prefer to put some or all of the classes into separate files to organize your work. Your task is to add the following capability to the application: (5%)    Increase the...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT