Description
1 Background
• In this assignment, you are going to implement some methods to manipulate Strings.
• Recap from the lecture: Why support a built-in String class?
– Popularity – String processing is common. (e.g., Reports, Financial information,
and Documents)
– String processing and I/O are incredibly important.
– String class in Java provides a uniform and efficient implementation to process
strings.
• You might need to refer to String API to complete this lab.
• Also, try to appreciate the difference between String, StringBuffer and StringBuilder
class.
2 Problem Description
Download the skeleton which is a simple program allowing users to process the string input.
There are five options in the program:
1 of 4
Assignment 2: String Processing System
COMP 3021: Java Programming
2022 Spring
• Split the String.
• Remove a substring from the string.
• Shift the string.
• Count the number of vowels.
• Caesar cipher.
When you start the program, you can see the following output in the console:
Welcome to the String Handling System!
Please input a string you want to process: Hello World!
=========== Options ============
1: Split the string
2: Remove all substring from string
3: Shift the string
4: Count number of vowels
5: Ceaser cipher
================================
Please choose an option (type in Q if you want to quit):
You are expected to finish the implementation of the functions processing each of the five
options.
2.1 TODO 1: Split
In split(), you need to split the string whenever there is a delimiter, then output each substring
in a seperate line. For example, if the original string is “Hello,Hello,Hello” and the delimiter
is “e”, the result will be “H”, “llo,H”, “llo,H”, “llo”.
Welcome to the String Handling System!
Please input a string you want to process: Hello World!!
=========== Options ============
1: Split the string
2: Remove all substring from string
3: Shift the string
4: Count number of vowels
5: Ceaser cipher
================================
Please choose an option (type in Q if you want to quit):
1
Please input a delimiter: e
H
llo World!!
2 of 4
Assignment 2: String Processing System
COMP 3021: Java Programming
2022 Spring
2.2 TODO 2: Remove Substring
You need to find whether the target substring is in the original string. If it exists, remove it;
if it does not exist, output “it is not found.” For example, when original text is “Hello”, if
we search for “el”, we should have an output: “Hlo”; if we search for “r”, we should have
an output: “target is not found”. Particularly, you only need to remove the first occurrence
of the substring if it occurs multiple times in the string. If there exists the substring in the
modified string, you are not expected to remove it again.
Please choose an option (type in Q if you want to quit):
2
Please input string to remove: el
String before removing ’el’: Hello Hello World!!
String after removing ’el’: Hlo Hello World!!
Please choose an option (type in Q if you want to quit):
2
Please input string to remove: ha
String before removing ’ha’: hhaa!!
String after removing ’ha’: ha!!
Please choose an option (type in Q if you want to quit):
2
Please input string to remove: u
String before removing ’u’: Hello World!!
target is not found
2.3 TODO 3: Shift String
You need to shift characters to the right by the amount specified by shiftAmount. The shift is
the cyclic, i.e., the overflow characters are pushed to the beginning of the string. For example,
if the original string is “Hello World” and the shiftAmount is 3, the result will be “rldHello
Wo”.
Please choose an option (type in Q if you want to quit):
3
Please input amount of shift: 3
After shifting “Hello World” by 3: “rldHello Wo”
2.4 TODO 4: Count Vowels
. You need to count the number of vowels in the String. A, E, I, O, U, a, e, i, o, and u.
3 of 4
Assignment 2: String Processing System
COMP 3021: Java Programming
2022 Spring
Please choose an option (type in Q if you want to quit):
4
number of vowels in “Hello World!”: 3
2.5 TODO 5: Ceaser Cipher
In this task, you need to implement a simple version of ceaser cipher that encrypts the English
characters by shifting the each character. You can find the details in here: wikipedia Caesar
Cipher(https://en.wikipedia.org/wiki/Caesar_cipher).
You should ignore any spaces and special character and number digits (only encrypt the
English characters a-z and A-Z), the output should be all in capital letters. For example, if
the original string is “Hello World!! 123”, then after entering 4 as the amount of shift, each
character will be shifted by exactly 4 characters and the result will be “LIPPS ASVPH!! 123”
(notice that ’W’ rotates back to ’A’) (Consider using StringBuilder for efficiency)
Please choose an option (type in Q if you want to quit):
5
Please input amount of shift: 4
ciphertext: LIPPS ASVPH!! 123
3 Tip
No bonus for this assignment.
4 of 4