Please remember to write your program in good programming style: choose meaningful names of variables and don't forget comments! Also, please read the problems carefully and implement them exactly.
Please say something secret: Itaha isaha coldaha inaha Moaharrisaha!
Aha! You meant:
It is cold in Morris!
When you said:
Itaha isaha coldaha inaha Moaharrisaha!
You may assume that aha is always lowercase.
Please type in a string: ThIS is My STrinG
You typed: THIS IS my string
Please type in a string: AppLE
You typed: APple
Please type in a string: AppLE!
You typed: APPle!
Your task is to write a program that asks the user to enter some
inputs and then prints out a story in which the missing words are
filled in with the user's input. To see a sample program, please
download the class file MadLib.class to the
folder with your java programs and run it by typing Java
MadLib
at the command prompt. Of course, you have to make up
your own story.
Important! At least one of the user's inputs must appear in your story twice (or more times). Your program must take at least three inputs. The story should be two-three sentences long. Don't worry about articles mismatching nouns, such as "a apple".
Also important: If you'd like, I can make the .class file of your program available on the class web page so that others can try it, too. The funniest story (or two) might even get a small prize :-)
Helpful: When writing a long string, make sure to open and close quotes on one line. For instance, the following does not work in Java:
String longstr = "My very very very very very very very very very
very very very very very very very long string";
Instead break the string into smaller substrings, each surrounded by
quotes, and connect them with a + operator:
String longstr = "My very very very very very very very very very" +
" very very very very very very very long string";
// PS3 question on Strings and StringBuffers
public class PS3 {
public static void main (String [] args) {
String str1 = new String("Java ");
StringBuffer sb1 = new StringBuffer(" fun");
sb1.insert(0,str1);
StringBuffer sb2 = new StringBuffer("String");
str1 = sb2.substring(0,1);
str1 = str1.toLowerCase();
int n = sb2.indexOf("ring");
sb2.delete(0,1);
String str2 = sb2.substring(2,3);
str1 = str2.concat(str1);
int m = sb1.indexOf("fun");
sb2 = sb1;
sb2.insert(m-1,str1);
}
}
You may, if you'd like, test the program by putting print statements
in it. In fact, it may be a good idea to do it. However, your work
will be graded based on the diagram only.
Important: do not use if/else statement or any other Java features that we haven't covered in class yet.