Write a program that will analyze a string by counting the number of each alphabetic letter in the string and then printing a vertical histogram showing the frequency of the letters in the string. For example, if text = "I love problem-solving.", your program should plot when the histogram is printed: * * * * * * * * * * * * * * * * * * * --------------------------------------------------- a b c d e f g h i j k l m n o p q r s t u v w x y z Note that all special characters including blanks are ignored and alphabet letters are caseinsensitive. Create your source code file named Lab10FirstnameLastname.java in NetBeans and add the following menu to the main method in the Lab10FirstnameLastname class. T: Enter a text string P: Plot alphabetic frequencies in the string Q: Quit Select an option: Add the following Histogram class to your source code file and complete the setText(String t) and drawHistogram() methods to do the work for options T and P in your main menu. The setText(String t)method changes the string stored in text to equal t. The drawHistogram() method counts each alphabetic letter occurrence, a to z, in the string text and then stores the count of each letter in an int array of size 26 since there are 26 letters in the alphabet. For example, the number of a’s in text would be stored in the 0 index position of your int array. As stated before, the counts are case-insensitive meaning both uppercase I and lowercase i count as an occurrence of the letter i. Last, use the contents in the int array, to output the vertical histogram to the user using nested For loops and printf(). class Histogram{ //class variables (aka data members) String text; //constructor Histogram(){ text = "I love problem-solving!"; } //additional class methods you are to complete //this method changes the string stored in text to the value //passed by the caller through parameter t void setText(String t){ //your goes code here } //This method creates an array to hold the letter frequencies //and outputs the vertical histogram based on the array contents //Use nested For loops and printf() to output the histogram void drawHistogram(){ //your goes code here } } 1. You must use printf() and nested For loops to output the histogram in this lab. 2. You must use an int array to store the counts of occurrences of each letter. 3. The only built-in String methods you can use are lowercase(), length() and charAt(). 4. If appropriate for this algorithm, you should validate any input from the user to make sure the data input is an appropriate value to work in your program’s logic. You don’t have to worry about validating that it is the correct data type. For now, assume the user is only giving you the correct data type and just worry about validating the value given is usable in your program
Write a program that will analyze a string by counting the number of each alphabetic letter in the string
and then printing a vertical histogram showing the frequency of the letters in the string.
For example, if text = "I love problem-solving.", your program should plot when the
histogram is printed:
* *
* * * * *
* * * * * * * * * * * *
---------------------------------------------------
a b c d e f g h i j k l m n o p q r s t u v w x y z
Note that all special characters including blanks are ignored and alphabet letters are caseinsensitive.
Create your source code file named Lab10FirstnameLastname.java in NetBeans and add the
following menu to the main method in the Lab10FirstnameLastname class.
T: Enter a text string
P: Plot alphabetic frequencies in the string
Q: Quit
Select an option:
Add the following Histogram class to your source code file and complete the setText(String
t) and drawHistogram() methods to do the work for options T and P in your main menu.
The setText(String t)method changes the string stored in text to equal t.
The drawHistogram() method counts each alphabetic letter occurrence, a to z, in the string
text and then stores the count of each letter in an int array of size 26 since there are 26 letters in the alphabet. For example, the number of a’s in text would be stored in the 0 index
position of your int array. As stated before, the counts are case-insensitive meaning both
uppercase I and lowercase i count as an occurrence of the letter i. Last, use the contents in the
int array, to output the vertical histogram to the user using nested For loops and printf().
class Histogram{
//class variables (aka data members)
String text;
//constructor
Histogram(){
text = "I love problem-solving!";
}
//additional class methods you are to complete
//this method changes the string stored in text to the value
//passed by the caller through parameter t
void setText(String t){
//your goes code here
}
//This method creates an array to hold the letter frequencies
//and outputs the vertical histogram based on the array contents
//Use nested For loops and printf() to output the histogram
void drawHistogram(){
//your goes code here
}
}
1. You must use printf() and nested For loops to output the histogram in this lab.
2. You must use an int array to store the counts of occurrences of each letter.
3. The only built-in String methods you can use are lowercase(), length() and charAt().
4. If appropriate for this
sure the data input is an appropriate value to work in your program’s logic. You don’t
have to worry about validating that it is the correct data type. For now, assume the user
is only giving you the correct data type and just worry about validating the value given is
usable in your program
Trending now
This is a popular solution!
Step by step
Solved in 4 steps with 3 images