Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

The main goal of this first homework is to complete a relatively straightforward Java program by taking advantage of your Java knowledge. Problem description: Given

The main goal of this first homework is to complete a relatively straightforward Java program by taking advantage of your Java knowledge.

Problem description: Given a string variable String s; , initialize s such that it contains a paragraph in English text. You can do so within your program by reading the initial value from the keyboard by using the Scanner class. Furthermore, this paragraph consists of no more than 100 tokens. Tokens are sequences of contiguous characters separated by any of the specified delimiters (e.g., white spaces, commas(,) and period(.)). Please implement a Java program to perform the following two tasks on s:

Implement the function void getLetterFreq(string s); to identify the frequency of each unique letter ('a'-'z', case insensitive) in s. This function will call the System.out.println statement(s) to print out each letter frequencies in the string on the screen.

Implement the function void StrToTokens(string s); to identify and print all the tokens contained in s on the standard output . For this assignment, only white spaces, commas and periods will be considered as delimiters. For instance, the string Hi, welcome to CSC 220.It is your first assignment" contains Ten tokens Hi, welcome, to, CSC, 220, It, is, your, first, assignment. You are not allowed to call existing library methods for this task. Specifically, you are required to loop through the input string one character at a time to separate the input string to different tokens. Please store the tokens in an array (such as ArrayList) before printing out all the tokens.

Implement the main() method that (1) declares and initializes the string s, and (2) calls the above two methods.

Example input and output:

Suppose s="Always remember that you are unique. Just like everyone else." The method getLetterFreq(s) will print out the following information (yours might be in a different format):

{'a': 4, 'b': 1, 'e': 11, 'i': 2, 'h': 1, 'k': 1, 'j': 1, 'm': 2, 'l': 3, 'o': 2, 'n': 2, 'q': 1, 's': 3, 'r': 4, 'u': 4, 't': 3, 'w': 1, 'v': 1, 'y': 3}

The output of StrToTokens(s); will be 'Always', 'remember', 'that', 'you', 'are', 'unique.', 'Just', 'like', 'everyone', 'else.'

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Concepts

Authors: David Kroenke, David J. Auer

3rd Edition

0131986252, 978-0131986251

More Books

Students also viewed these Databases questions