Starting from:

$25

CSE1141-Project 4 Solved

In this homework, you will write a program which will take an input string, if the word is either “exit” or “quit”, your program should terminate; if the word is “stat”, your program should print a two-line statistical report: the first line prints the total number of words the user has entered, and the second line prints the total number of alphabetic letters the user has entered. Note that we only count the 26 letters in the alphabet. For example, if a user has entered the following string, i.e. “We love CSE1141 course a lot!!”, the following should be printed to screen after the user types “stat”: 

The number of words: 6 

The number of alphabetic letters: 19 

 

If the word is not “stat”, “exit” or “quit”, then your program will ask to change the case of letters, count vowels and consonants, capitalizes the first letter of each word, and encrypt or decrypt the input string based on the user’s selection.  

 

To implement this program, you need to define following methods: 

•        public static void main(String[] args) 

o add two variables, both of type int, to the “main” method to store the total number of words and the total number of letters the user has entered since your program starts. You can create an infinite loop in the “main” method; in each iteration of the loop, first ask the user to enter an input string and then it will ask to select an option. You can invoke related methods based on the option selected. 

 

•        public static int updateLetterCount(int count, String str)  

o take as input the current count of the letters and the string the user has just entered. This method updates and returns the new letter count value. This method should be called each time the user enters a new string that is not “exit”, 

“quit”, or “stat”. 

 

•        public static void printStat (int wordCount, int letterCount) o takes as input the total word count and the total letter count, and prints the above-mentioned two-line statistical report on screen, with no return value. 

 

•        public static String changeCase (String str)  

o returns a new string in which the uppercase letters are changed to lowercase and lowercase letters are changed to uppercase. 

 

•        public static void countVC (String str)  

o displays the number of vowels and consonants in an input string. 

 

•        public static String capitalize (String str)  

o takes an input string and returns a new string in which the first letter of each word is capitalized. 

 

•        public static String encryptOrDecrypt (String str, int offset)  o encodes or decodes input string based on a shift offset.  o The method will take an input string, convert it into uppercase, then process it using the shift offset.  

o This method will take an integer offset and it will perform encryption if the value is positive and it will perform decryption if it is negative.  o The value of offset must be -25 to -1 (inclusive) and 1 to 25 (inclusive).  o Encoding/decoding scheme is given in the following figure. 

  

 

 

 

 

 

Example run: 

 

Please enter an input string: heLLo worLd 

1.  Change Case 

2.  Count vowels and consonants 

3.  Capitalize the first letter 

4.  Encrypt or Decrypt 

 

Please select an option: 1 

HEllO WORlD 

 

 

Please enter an input string: Welcome to JAVA! 

1.  Change Case 

2.  Count vowels and consonants 

3.  Capitalize the first letter 

4.  Encrypt or Decrypt 

 

Please select an option: 2 

The number of vowels is 6 

The number of consonants is 7 

 

 

Please enter an input string: welcome to marmara university! 

1.  Change Case 

2.  Count vowels and consonants 

3.  Capitalize the first letter 

4.  Encrypt or Decrypt 

 

Please select an option: 3 Welcome To Marmara University!  

 

 

Please enter an input string: We love CSE1141 course a lot!! 

1.  Change Case 

2.  Count vowels and consonants 

3.  Capitalize the first letter 

4.  Encrypt or Decrypt 

 

Please select an option: 4 

Enter an offset value: 3 

Source: WE LOVE CSE1141 COURSE A LOT!!  

Processed: ZH ORYH FVH1141 FRXUVH D ORW!!  

 

 

Please enter an input string: ZH ORYH FVH1141 FRXUVH D ORW!! 

1.  Change Case 

2.  Count vowels and consonants 

3.  Capitalize the first letter 

4.  Encrypt or Decrypt 

 

Please select an option: 4 

Enter an offset value: -3 

Source: ZH ORYH FVH1141 FRXUVH D ORW!! 

Processed: WE LOVE CSE1141 COURSE A LOT!! 

 

 

 

Please enter an input string: We love CSE1141 course a lot!! 

1.  Change Case 

2.  Count vowels and consonants 

3.  Capitalize the first letter 

4.  Encrypt or Decrypt 

 

Please select an option: 4 

Enter an offset value: -26 Invalid offset.  

 

 

Please enter an input string: stat 

The number of words: 27 

The number of alphabetic letters: 106 

 

 

Please enter an input string: exit 

Program ends. Bye 

 

More products