Question
This assignment involves reading a line of text from the keyboard, and generating a histogram of letters* that occur in the text. You will edit
This assignment involves reading a line of text from the keyboard, and generating a histogram of letters* that occur in the text. You will edit the program supplied above, adding the code to generate the histogram. You should not change the class name, method names and method signatures.
*The letters in the histogram should be the first 5 unique letters in your own name. your program should count the number of times the following letters appear in the user's ,phrase and print a histogram using asterisks like the example below. If your name is John Smith, the histogram should include letters: h, j, n, o, s.
You must write the code to generate the histogram in the printHistogram method (not in the main method).
Call printHistogram from the main method, passing the text (entered by the user) as an argument.
Do not use arrays, or any other concepts not yet covered in the course.
Add an extra method "printVerticalHistogram" to the class A9, to print the histogram in the following orientation
* * * * * * j o h n y
Call both methods, printHistogram and printVerticalHistogram, from your main, to show both orientations in the output.
import java.util.Scanner; public class A9 { public static String getPhrase () { Scanner input = new Scanner(System.in); System.out.print ("Enter a phrase: "); String phrase = input.nextLine(); return phrase; } public static void reportPhrase (String phrase) { System.out.println (phrase); } public static void printHistogram (String phrase) { // Your code here } public static void main(String args[]) { String phrase; phrase = getPhrase (); reportPhrase (phrase); // Call the method printHistogram here } }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started