Create Histogram That Allow To Visually Inspect Frequency Distribution Of A Set Of Values
Apr 4, 2014
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.
No input prompt
Terminate input by typing CTRL/Z (two keys typed at the same time) on a separate input line (use CTRL/D on Linux/UNIX systems)
Use hasNextInt() to terminate your input
Format as below (slightly different from the text example)
Z:dbraffittWeek10> javac Histogram.java
Z:dbraffittWeek10> java Histogram
[Code] ....
What I can not figure out is how to use hasNextInt() to terminate the loop. How to not have an input prompt. How to use ctrl z to terminate the input. Or to make it where it doesn't involve range values like -1.
import java.util.Scanner;
public class Histogram {
public static void main (String[] args) {
Scanner scan = new Scanner (System.in);
int [] nums = new int[101];
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.
No input prompt
Terminate input by typing CTRL/Z (two keys typed at the same time) on a separate input line (use CTRL/D on Linux/UNIX systems)
Use hasNextInt() to terminate your input
Format as below (slightly different from the text example)
Z:dbraffittWeek10> javac Histogram.java
Z:dbraffittWeek10> java Histogram
10 10 10 10 10 20 20 20 20 20 20
20 25 35 45 55 65 75 85 95
ctrl/z
1 - 10 | *****
11 - 20 | *******
21 - 30 | *
31 - 40 | *
41 - 50 | *
51 - 60 | *
61 - 70 | *
71 - 80 | *
81 - 90 | *
91 - 100 | *
What I can not figure out is how to use hasNextInt() to terminate the loop. How to not have an input prompt. How to use ctrl z to terminate the input. Or to make it where it doesn't involve range values like -1.
Java Code:
import java.util.Scanner; public class Histogram { public static void main (String[] args) { Scanner scan = new Scanner (System.in); int [] nums = new int[101];
I have loaded the combo box at starting of program.When i am adding the element to combo box through database it's not updating visually.But the inserted data is successfully loaded in List.
I heard one of the senior architects in my company before tell me to treat component distribution as a last resort. So if EJB were created for such, why were they created if component distribution is not encouraged anyway? just got confused here. I remembered this because I am currently in a dilemma of whether to redesign an app having performance problems. Options are either create EJBs for it and put them in another server or purchase another server to have a load balanced setup.
I recently switched some of code around to restructure how some things were working but now when I run the program I am getting a NullPointerException in multiple areas. I suspect it may have something to do with a constructor. I am very new to "object" - ish based programming.
I figured I should give a little background on the program, this program is reading from a text file of names and decade numbers(for each name) and storing each line into an object array. From there, there are menus and based on the users decision they can type a name and get a histogram, compare names with histograms, ect. Below this main method, I have provided the area where I have gotten the null pointer exception.
Here is the main method for the Client "nameApp"
Also excuse the formatting and curly braces for now!
And here is the method in the same Client that is getting the null pointer exception:
The pointer exception is on line 6 which is:
if (nameInput.equalsIgnoreCase(list[i].getName())){ private static int checkListArray(String nameInput, Name[] list){ int nameLocation = -1; int listLength = list.length;
I prompted the user to enter inches of rainfall for seven days and stored them in an array. Now, I am trying to display a histogram of this data using a nested loop, but for each inch, I have to display a * like this:
The only way I know how to display a number of *s according to user input is by an if statement. I copied and pasted from a similar class assignment I did, so what I have so far is pretty messy and nonsensical:
The following program should read in a file on my desktop (I have the path set in Netbeans to that location) and produce a Histogram. Instead I am receiving this error.
Exception in thread "main" javax.imageio.IIOException: Can't read input file! at javax.imageio.ImageIO.read(ImageIO.java:1301) at Histogram.main(Histogram.java:9) Java Result: 1 BUILD SUCCESSFUL (total time: 0 seconds)
Here is the code for the Histogram:
import java.awt.image.BufferedImage; import java.io.File; import javax.imageio.ImageIO; public class Histogram { public static void main(String[] args) throws Exception { int[][][] ch = new int[4][4][4];
I just recently started coding java and i have a problem.... So I was doing an exercise on LearnJavaOnline. The exercise was: Create all the the primitives with different values. Concatenate them into a string and print it to the screen so it will print: H3110 w0r1d 2.0 true.I attempted it and this is what i wrote
public static void main(String[] args) {
char H = 'h'; byte e = 3; short l = 1; int L = 1; long o = 0; char w = 'w';
[code]....
However it prints "109 w0r1d 2.0 true".But when i add 2 speech marks: String HelloWorld = H+""+e+l+L+o+" "+w+0+r+one+d+" "+two+" "+hi; It works perfectly.
I'm trying to write a program that counts the number of times each number in an array occurs. In theory I understand how it work, you take the first element in the array, compare it again the rest of the array and any time it occurs in the array you increment a counter by 1. Then move onto the next element A[1] and so on...
This is what I've done so far :
public static void main(String[] args) { int[] array = {5,6,2,5,2,2,0,1,6}; int count = 0; for(int i = 0; i <array.length; i++) { int val = array[i]; for(int j = i+1; j<array.length; j++)
[Code] .....
I think I'm on the right track as it correctly prints out the frequency of the first 3 elements, but I'm definitely going wrong somewhere as it just doesn't do it right after that!
I am trying to create an empty array that has no assigned length as the amount of elements it needs to hold will be dependent on another value. I then want to use a while loop to assign values to it. Here is an example of what im looking for it doesnt work. Iam trying to do:
int x = 12; int i = 1; int k = 0; int[] factors = {} while (i<x) { if (x%i==0) { factors[k] = i; k++; i++;
I have a source code here that counts the frequency of alphabetic characters and non-alphabetic characters (see the source code below).
import java.io.*;
public class letterfrequency { public static void main (String [] args) throws IOException { File file1 = new File ("letternumberfrequency.txt"); BufferedReader in = new BufferedReader (new FileReader (file1));
[Code] ....
But, let's just say that now I have the following characters in the text file, "letternumberfrequency.txt": 71 geese - 83 cars - 58 cows- 64 mooses- 100 ants- 69 bangles- 90 molehills - 87 noses
The numbers inside that text file would be considered as strings, am I right? But I want to extract the numbers so that I can also be able to count their frequency - not as individual digits but as whole numbers (that is how many "71", "83", "58", "64", etc. are there...). Would using "Double.parseDouble ()" work?
I have this code that outputs the tfidf for all words in each file in the directory. I'm trying to transfer this to a matrix where each row correspond to each file in the directory and each column to all words in the files and I have some difficulty in doing it . Here is my try
public class TestTF_IDF { public static void main(String[] args) throws UnsupportedEncodingException, FileNotFoundException{ //Test code for TfIdf TfIdf tf = new TfIdf("E:/Thesis/ThesisWork/data1"); //Contains file name being processed String file; tf.buildAllDocuments();
Started learning about Array's I'm doing an exercise where you create a for loop that randomly assigns values to each element within the array, but where is my code going wrong?
import java.util.Scanner; public class ArrayExamples{ public static void main(String[] args) { Scanner input = new Scanner(System.in); double exampleArray[] = new double[5]; System.out.print("Enter a Number: "); int num1 = input.nextInt();
I have built a binary tree, from a file. In each node, I am storing each word as a string, and an int frequency for each time the word occurs. For the assignment, I need to find how many words occur only once in the file. I wrote the program, but for some reason I am getting a number different from what my professor is expecting.
As far as I know, this file has loaded into the tree correctly, because all of my other answers in the assignment are correct. What am I doing wrong?
public void findUnique() { System.out.println("There are " + findUniqueWords(root, 0) + " unique words."); } private int findUniqueWords(Node subTree, int uniqueCount) { // Base Case: At the end of the branch if(subTree == null){ return uniqueCount;
I need a way to store the pixels values currently on the screen and compare them to the values on the first frame. Right now I'm using glreadpixels as follows:
currentBuffer= BufferTools.reserveByteData(mapSize); glReadPixels(mapStartX, mapStartY, mapWidth, mapHeight, GL_BLUE, GL_UNSIGNED_BYTE, currentBuffer); for (int i = 0; i < mapSize; i++) { if (currentBuffer.get(i) != baseBuffer.get(i)) { //Do nothing continue; } //Do something }
This works perfectly fine but turns out to be a real bottleneck, dropping the fps to a third of what it was. Is there any quicker way? All I'm after is speed, I don't even need to show it on the screen if the comparison is made "behind the scene".
I have a question in mind that this is my registration form. I am sending these values from HTML form to server and database. I have question that in my case if I click next to Add Another Mobile no in HTML.then a block is genereated and each time a new name is generated.
My Question is if I click 6 times then 6 name attribute are generated. How can I send and differentiate them on my server side.
Because at their I will use something request.getAttribute("Attr_Name");
I have a JScrollPane with two coulmns. In the first column I have an image pane JTable, and in the second a list with names of sections. This second column I try to divide in two columns, one (the second column) to display the names of the sections (each row contains one name), and in the other column (the third) I want to show some values for every section in the row respectively. But, instead of displaying the desired values in the third column, I get the same names of the sections as in the second column.
In the class below I'm trying to create a class that will accept dates in various formats and create a range. The first constructor is easy because I send it the begin date and end date as Date objects. Now I want to send a month(and year) in a constructor and derive the begin and end dates from it. In my constructor that accepts the month/year I need to put the this(startDate, endDate) at the top to be allowed, but the parameters are not built yet.
package com.scg.athrowaway; import java.util.Calendar; import java.util.Date; public class DateRange { private Date startDate; private Date endDate;
I'm having some difficulty with my bank account project. I'm supposed to create a menu where the user can create a new account, withdraw, deposit, view their balance, and exit. There's issues with the account creation.
Here's my necessitated class below: BankAccount, TestBankAccount, SavingsAccount, CurrentAccount, and Bank
I certify that this assignment is my own work and that I have not copied in part or whole or otherwise plagiarized the work of other students and/or persons.
I'm doing an aggregation exercise that's suppose to find the volume and surface area of a cylinder. What I'm trying to do is pass values from one class, to a second class, and that second class passes values to a third class.
This may be a clearer explanation: The first class is the main program which sends values to the second and third class. The second class is used do calculations for a circle (a pre-existing class from another assignment). The third class grabs the values that the second class calculated and calculates those values with the one that was passed from the first class to the third class. The first class then prints the outcome.
Problem is when the program gets to the third class, it just calculates the value from the first class with the default constructor from the second class. It's like the second class never received the values from the first class. I think I'm missing a step, but I don't what it is.
First Class:
package circle; import java.util.Scanner; public class CylinderInput { static Scanner in = new Scanner(System.in); public static void main(String[] args) { //user defined variable
I'm new to Java and I have an assignment to create a Sphere class that will allow you to create Sphere objects using the code below. Then create a program called SphereTester that prompts the user for the radii of two spheres in meters. The program should display which sphere is larger and by how many cubic meters and display only four digits after the decimal point. I have the sphere class given to us for the assignment which is this:
Java Code: public class Sphere { // instance variable (i.e., a field) private double radius; // constructor for the Sphere class public Sphere(double r) { radius = r;