CS110 Java Programming Assignment #8
Instructor: Trish Cornez
String Manipulation
PROGRAM 1
Write an interactive program that prompts the user to input a
string of words.
Translate the given sentence to Pig Latin and display it.
NOTE: Use methodsto make your code as efficient and as organized as possible.
Correctness is the most important element, however, points will be given for the quality of your code.
The Pig Latin system works as follows:
- Words that start with a vowel (A, E, I, O, U) simply have "way" appended to the end of the word.
- Words that start with a consonant have the first consonant letter moved
to the end of the word and "ay" is appended.
Incorporate the following features :
- Correct the upper case and lower case formatting.
- All punctuation, numerals, and symbols should not be modified.
For example:
Input:
These awful french fries are getting cold
Output:
Hesetay awfulway renchfay riesfay areway ettinggay oldcay
PROGRAM 2
Write a Java program that tests the method doubleIt().
doubleIt() receives a string of characters and returns a string where for every character in the original, there are two characters.
Perform the following tests:
- doubleIt("Apple") ----->"AAppppllee"
- doubleIt("cat") -----> "ccaatt"
- doubleIt("cold fries") -----> "ccoolldd ffrriieess"
PROGRAM 3
A sandwich is two pieces of toast with something in between. Write a Java program that tests the method getMiddle().
This method should receive a string of text and return the string that is between the first and last appearance of "toast"
in the given string, or return the empty string "" if there are not two pieces of toast.
Perform the following tests:
- getMiddle("toastAppletoast") ----->"Apple"
- getMiddle("cattoastkittycattoast") -----> "kittycat"
- getMiddle("toastkittycat") -----> ""
- getMiddle("coldfries") -----> ""
Extra Credit
Create the game of Tic Tac Toe
Construct your game to allow the user to play against the computer.
It will require the use of single and two dimensional
arrays, as well as a large, yet manageable, set of logic
combinations to explore.
The algorithm for Tic tacTtoe is often written with game
tree data structures, a topic not discussed in CS110.
To solve this problem without the use of game trees, you
will need to explore and implement all possible game scenarios.
The image below shows an execution of the game with the user,
player X, losing to his opponent, the computer O.
