Hi here is my task.
1. Design and implement an applicaton 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 1000 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 | *
I have coded this:
package componentsandservices; import java.util.Scanner; public class Histogram { public static void main(String[] args) { Scanner Keyboard = new Scanner(System.in); int n, nextt, ix; // how many numbers to read? do { System.out.print("Please type the number of numbers:"); n = Keyboard.nextInt(); } while (n < 0); int[] numbers = new int[n]; //read in the numbers for (ix = 0; ix < n; ix++) { // the number must be between 1 and 100 do { System.out.println((ix + 1) + ") Please type a new number in the range 1 and 100:"); nextt = Keyboard.nextInt(); } while (nextt < 1 || nextt > 100); numbers[ix] = nextt; } // create the histogram values String[] stars = {" 1-10 |", "11- 20 | ", "21- 30 | ", "31- 40 | ", "41- 50 | ", "51- 60 | ", "61- 70 | ", "71- 80 | ", "81- 90 | ", "91-100 | "}; //10 strings for (ix = 0; ix < n; ix++) { nextt = numbers[ix]; if (nextt < 11) { stars[0] += "*"; } else if (nextt < 21) { stars[1] += "*"; } else if (nextt < 31) { stars[2] += "*"; } else if (nextt < 41) { stars[3] += "*"; } else if (nextt < 51) { stars[4] += "*"; } else if (nextt < 61) { stars[5] += "*"; } else if (nextt < 71) { stars[6] += "*"; } else if (nextt < 81) { stars[7] += "*"; } else if (nextt < 91) { stars[8] += "*"; } else { stars[9] += "*"; } } for (ix = 0; ix < 10; ix++) { System.out.println(stars[ix]); } } }
And i am getting the following output:
run: java.lang.NoClassDefFoundError: componentsandservices/Main Caused by: java.lang.ClassNotFoundException: componentsandservices.Main at java.net.URLClassLoader$1.run(URLClassLoader.java:202) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:190) at java.lang.ClassLoader.loadClass(ClassLoader.java:307) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301) at java.lang.ClassLoader.loadClass(ClassLoader.java:248) Could not find the main class: componentsandservices.Main. Program will exit. Exception in thread "main" Java Result: 1 BUILD SUCCESSFUL (total time: 0 seconds)
Please does anyone know whats wrong?