Unit 4 Projects
Project 1: Write a program that asks for a single word, then displays that word backwards.
Sample Output
input: stressed
output: desserts
Project 2: Write a program to accept a word, then display the word as shown in the following example.
Input: ROYAL
Output:
R
RO
ROY
ROYA
ROYAL
Project 3: Write a program that will allow the entry of a name consisting of a first and last name (with a space separating the two). The input is to be made into a single string. The program should then output the results in the form last, first. See the example below:
Input: Jerry Seinfeld
Output: Seinfeld, Jerry
Project 4: Write a program to put a given word into Pig Latin. There are many forms of this made up language, but here are the rules we will use:
If the word begins with a vowel, put way on the end of it. Example: apple becomesappleway.
If the word begins with a consonant, move all leading consonants to the end and putay after it. Examples: night becomes ightnay and scram becomes amscray.
A special case: Words with qu at the beginning require that the u goes to the end along with the q. Examples: quit becomes itquay, square becomes aresquay.
Use the above examples to test your program. All of them need to work.
Project 5: The String Math Calculator
Accept a simple arithmetic expression into a string (involving 2 1-digit integers). The program analyzes the string, performs the operation, and then displays the result (see below). As long as it works for these examples, it is considered a success. There are many other more complicated possibilities, but this is all we will consider for now.
Test Data
Input (note, no spaces)
Output
4+2
4+2=6
4-2
4-2=2
4*2
4*2=8
4/2
4/2=2
Project 6: Write a program to analyze the words in a sentence. This program should accept a sentence into a string, and then determine the number of words in that sentence, the average word length and the length of the longest word. Hint: a word is detected when a space or punctuation mark is encountered. For example, if the sentence is “The quick silver fox jumped over the lazy brown dog.”, the output of the program will be:
Number of Words: 10
Average Word Length: 4.2
Longest Word: 6
Project 7: Write a program that will accept both a sentence and a single letter into separate variables. The program should then display all words in the sentence that contain the given letter. See the following examples:
Input:
Sentence: Where are they now?
Letter: e
Output:
Where
are
they
Input:
Sentence: I went to the store.
Letter: o
Output:
to
store
If there is no occurrence of the letter in the sentence, display a message stating so.
Project 8: Write a program that will accept 3 words into 3 separate strings, and then display the words in alphabetical order, one line at a time. Use the compareTo method See the example below.
Input words: Royal, Simi, Santa
Output:
ROYAL
SANTA
SIMI
Note that all words must be capitalized to do this.
Project 9: Write a method that tests whether a word is a palindrome (the same when read forward or backward, as in “madam”). Create a tester class and test the isPalindrome method.
public boolean isPalindrome(String word)