ComputerScienceExpert

(11)

$18/per page/

About ComputerScienceExpert

Levels Tought:
Elementary,Middle School,High School,College,University,PHD

Expertise:
Applied Sciences,Calculus See all
Applied Sciences,Calculus,Chemistry,Computer Science,Environmental science,Information Systems,Science Hide all
Teaching Since: Apr 2017
Last Sign in: 103 Weeks Ago, 3 Days Ago
Questions Answered: 4870
Tutorials Posted: 4863

Education

  • MBA IT, Mater in Science and Technology
    Devry
    Jul-1996 - Jul-2000

Experience

  • Professor
    Devry University
    Mar-2010 - Oct-2016

Category > Programming Posted 08 May 2017 My Price 9.00

COM S 207CountCharsADon't be daunted

This is java programming this is so difficult to me. Thank you 

 

COM S 207CountCharsADon't be daunted by this assignment. Note that each method consists of only afew lines of code. You have done a similar problem in CountUpperCase.ObjectiveWrite a program that reads in lines from the input.For every line, it counts each letter of the English alphabet. It also counts the number of vowels, consonants,and others. It then prints out this information.The important part of this assignment is tocode the methods given belowand to use them. You will need tocreate and use an array that keeps track of the count for each letter.InputThe input will be one or more lines of characters that have been typed in by the user.Assume that all the letters are all LOWERCASE.OutputThe output can be best described using some examples:Example output:Line 01: d=1 e=4 f=3 h=2 v=1 w=2 YES vowels=4 consonants=9 others=0The line number is followed by number of non-zero occurrences of each letter in the English alphabet. This isfollowed by a YES or NO based on if there were ANY vowels in the line. Next, it shows the number of vowels,followed by the number of consonants, followed by others (i.e. not a letter).Example output:Line 02: h=2 r=3 w=2 NO vowels=0 consonants=7 others=10Note that in this example, there are NO vowels.Note that the line number uses TWO spaces and that for ONE digit numbers, the left space has a ZERO.Thus, Line 9 will be printed asLine 09:but Line 99 will be printed asLine 99:Note that it prints the letter counts in alphabetical order.Sample Inputhevdhfewfewfehhwwrrr73##$6%&%7Sample OutputLine 01: d=1 e=4 f=3 h=2 v=1 w=2 YES vowels=4 consonants=9 others=0Line 02: h=2 r=3 w=2 NO vowels=0 consonants=7 others=10Now that you know what the program is to do, let us give specifics of what you areto do.

Page 2 of 3pages1.You will need to declare a staticint array variablethat will keep trackof the counts for each letter. This array should have length 26. ArrayIndex 0 will be used to store count for the letter 'a'. Array Index 1 willbe used to store count for the letter 'b'. Array Index 25 will be used tostore count for the letter 'z'.Suppose the array is named letterCountArray. Then to access the index forcharacter c, you will need to do c – 'a'. Thus, if c is 'm', your code willaccess index 'm' – 'a'- which is 12. Note that 'a' is 97 in Unicode (andascii).This array will need to zeroed out when you begin with a new line.This array should be declared as a CLASS variable (and not inside the mainmethod). This way, this variable can be used inside any method in the class.2.privatestaticvoidaddLetterCount(charc)This method is to add to the count for the letter indicated by the variable c.Basically, index into the array declared above and add to the count for the letter indicated by variable c.3.privatestaticvoidzeroLetterCount()Zero out all the elements of the array.4.privatestaticvoidprintLetterCounts()Loop over the array and print the counts for each letter (as indicated in the sample output). Thus, ifthere are only two counts that are not zero (say 'a' has count 5 and 'z' has count 10, then this methodwill print "a=5 z=10" (note the space after 10).5.privatestaticintcountVowels()This method returns the sum of the count of all the vowels (i.e. for 'a', 'e', 'i','o','u').6.privatestaticString anyVowels()This method returns the String "NO" if countVowels() returns 0. Otherwise, it returns the String "YES"7.privatestaticintcountConsonants()This method returns the sum of counts of all the consonants. (Just add all elements of the array andsubtract countVowels().

COM S 207CountCharsA8.privatestaticvoidcounts(intlineNum, String s)This method is the "workhorse" of the program. It is given a line number and the line as input.It first loops over each character of the line and adds to the appropriate array element if it is a letter.Otherwise, it adds to "Other".Then, it prints the information for the line as described earlier. To print the information, make use ofthe methods described earlier.Use printf with formal"Line %02d: "to be able to print the line number with LEADING zeroes.9.main method.In the main method, keep count of line number and make calls to "counts" method as needed.

Answers

(11)
Status NEW Posted 08 May 2017 03:05 AM My Price 9.00

-----------

Not Rated(0)