Question

In: Computer Science

java 8.3: Histogram Design and implement an application that creates a histogram that allows you to...

java

8.3: Histogram
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 - 10 | *****
   11 - 20 | ****
   21 - 30 | *********
   31 - 40 | **
   41 - 50 | **************
   51 - 60 | ******
   61 - 70 | ****
   71 - 80 | ********
   81 - 90 | *
  91 - 100 | ***

Solutions

Expert Solution

import java.util.*;

public class Sample{

public static void main(String args[]){

Scanner input=new Scanner(System.in);

int[] inner_limit=new int[]{1,11,21,31,41,51,61,71,81,91};

int[] outer_limit=new int[]{10,20,30,40,50,60,70,80,90,100};

int[] frq_cnt=new int[]{0,0,0,0,0,0,0,0,0,0};

System.out.println("Enter -1 for exit:");

int element;

while(true){

element=input.nextInt();

if(element==-1){break;}

for(int i=0;i<10;i++){

if(element>=inner_limit[i] && element<=outer_limit[i]){

frq_cnt[i]=frq_cnt[i]+1;

break;

}

}

}

for(int i=0;i<10;i++){

System.out.print(inner_limit[i]+" - "+outer_limit[i]+" | ");

for(int j=0;j<frq_cnt[i];j++){

System.out.print("*");

}System.out.println("");

}

}

}

#output:


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 -...
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...
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.
The answer should be in JAVA. You will design and implement two classes to support a...
The answer should be in JAVA. You will design and implement two classes to support a client program, RockPaperScissorsGame.java, to simulate Rock-Paper-Scissors game. Read and understand the client program to find out the requirements for the HandShape and Player classes. The rules of the Rock-Paper-Scissors game are:     Scissors✌️ beats Paper✋ that beats Rock✊ that beats Scissors✌️ Additionally, to simplify the game logic (and complexify a little bit the HandSahpe class) , two players cannot show the same hand shape....
The answer should be in JAVA. You will design and implement two classes to support a...
The answer should be in JAVA. You will design and implement two classes to support a client program, RockPaperScissorsGame.java, to simulate Rock-Paper-Scissors game. Read and understand the client program to find out the requirements for the HandShape and Player classes. The rules of the Rock-Paper-Scissors game are:     Scissors✌️ beats Paper✋ that beats Rock✊ that beats Scissors✌️ Additionally, to simplify the game logic (and complexify a little bit the HandSahpe class) , two players cannot show the same hand shape....
Assignment 4: Objects that contain objects In this assignment, you will implement a Java application, called...
Assignment 4: Objects that contain objects In this assignment, you will implement a Java application, called BankApplication, that can be used to manage bank accounts. The application is to be implemented using three classes, called Account, Customer, and BankDriver. The description of these classes is below. Problem Description class Account The Account class keeps track of the balance in a bank account with a varying annual interest rate. The Account class is identified as follows: • two double instance variables,...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT