Java程序辅导

C C++ Java Python Processing编程在线培训 程序编写 软件开发 视频讲解

客服在线QQ:2653320439 微信:ittutor Email:itutor@qq.com
wx: cjtutor
QQ: 2653320439
Assignment 4 Assignment #4 -- Array and String exercises Due: Tues, March 19th Objective This assignment will consist of writing 2 programs that involve practice with arrays and Strings Task 1: Pig Latin Filename: PigLatin.java Understand the rules of Pig Latin: If a word begins with a consonant, move all of the characters up to the first vowel to the end of the word and add "ay". Examples: bad becomes adbay, groovy becomes oovygray. If a word begins with a vowel, write the word and add "way" Examples: add becomes addway, office becomes officeway. Y is not a vowel. Example: yes becomes esyay. If there are no vowels in the word, just write the word. Example: why becomes why. Your program will accept a paragraph of text. Paragraphs are separated by a blank line, as such the input terminating sentinal value will be an empty string. Take the entered paragraph and convert it into a Pig Latin paragraph and output the result to the screen. The user should be queried if they wish to translate another paragraph. For further details on execution please see the sample output. Requirements Create the method public static boolean isVowel(char c) that determines if a character is a vowel or not. Create the method public static int findFirstVowel(String word) that determines the location of the first vowel in a word (return -1 if none). Create the method public static String convertToPigLatin(String word) that converts the English word into its equivalent Pig Latin word. Punctuation Dealing with punctuation is an extra credit endeavor. The only punctuation you are required to deal with are ?!,.. All sentences will be correctly formatted so that the there are no additional spaces where there shouldn't be eg. Good format: This might be easy, but may also be hard., Bad format: This might be easy ,but may also be hard. It will be worth 10% extra credit. Sample Run 1 (user input is underlined) Please enter a sentence (blank line to exit) :This is a sentence. Please enter a sentence (blank line to exit) :This is another line. Please enter a sentence (blank line to exit) : isThay isway away entencesay. isThay isway anotherway inelay. Would you like to translate another? n Good bye! Sample Run 2 (user input is underlined) Please enter a sentence (blank line to exit) :This is a sentence. Please enter a sentence (blank line to exit) :This is another line. Please enter a sentence (blank line to exit) : isThay isway away entencesay. isThay isway anotherway inelay. Would you like to translate another? y Please enter a sentence (blank line to exit) :This is a sentence. Please enter a sentence (blank line to exit) :This is another line. Please enter a sentence (blank line to exit) : isThay isway away entencesay. isThay isway anotherway inelay. Would you like to translate another? n Good bye! Task 2 Filename: Sentences.java Write an application that uses random-number generation to create sentences.  Use four arrays of strings called article, noun, verb, and preposition. The arrays of Strings: The article array should contain the articles:  "the", "a", "one", "some", "any" The preposition array should contain the prepositions:  "to", "from", "over", "under", "on" The noun array and the verb array should contain words entered by the user. So start the program by asking the user to enter 5 nouns, and then ask them to enter 5 verbs. Store these in the appropriate arrays Create a sentence by selecting a word at random from each array in the following order: article, noun, verb, preposition, article, noun As each word is picked, concatenate it to the previous words in the sentence.  The words should be separated by spaces.  When the final sentence is output, it should start with a capital letter and end with a period.  The application should generate random 20 sentences and output them to the console Note: It's not enough to output just one word at a time. You need to create each sentence as a single string before printing it to output. (Make use of the concatenation operation!) Hint: The hardest part is making sure the sentence is capitalized, because you only have one article array (and it stores the lowercase version, since you use articles again). Remember that we've seen a number of library methods from class String, as well as other places. You may want to remind yourself of these: In the Character class, we saw methods that can give the lowercase or uppercase conversions of a single character From class String, charAt From class String, substring Sample Run 1 (user input is underlined) Enter 5 nouns (lowercase): truck car dog man boy Enter 5 past tense verbs (lowercase): ran jumped killed attacked cried Some truck cried from the truck. One boy jumped under the car. Any car jumped from some man. A car ran from one truck. A truck attacked on a dog. The man attacked on some boy. One boy killed over any car. A truck killed under the dog. A car killed from a man. Some dog attacked on the truck. The man killed on one boy. One car ran on the man. The truck attacked from the dog. A man killed on any man. Any dog attacked over one truck. One car ran on one boy. A car killed under any car. Some man attacked on a boy. The boy cried under any dog. The man jumped from one dog. Sample Run 2 (user input is underlined) Enter 5 nouns (lowercase): book chair platypus villain clock Enter 5 past tense verbs (lowercase): shot fell slapped yelled cooked The chair slapped from some platypus. The platypus shot from one chair. Some villain yelled under any platypus. Any platypus shot from some platypus. The book yelled under the platypus. Any clock shot from any clock. The book yelled from the platypus. A book cooked on one book. A clock slapped on some platypus. A platypus yelled over any platypus. One book slapped over one book. Any platypus cooked over the chair. One clock slapped under a chair. The book cooked to one book. A chair yelled under the chair. Any book yelled over any book. One book slapped on some chair. A villain fell to a villain. One villain slapped on the book. The platypus cooked on some book. Requirements for each program Use the Scanner class for input Use the Random class for random number generation You can use any of the libraries discussed in class. You will want to refresh your memory on the String and StringBuffer class libraries, specifically When you write source code, it should be readable and well-documented. General hints about code layout So far, we've mainly been writing programs using a single main() method, but in your last assignment, you wrote some separate methods that could be called from main(). Consider breaking longer tasks (or repeated tasks) into methods. This will allow you to shorten the amount of code you write. i.e. instead of writing the same task many times, if you write it once in a method, you can call upon it many times IF you write methods other than main(), make sure you also declare them to be public and static (just like main). If you want to have a variable that is in scope for all of your methods in a class (rather than only in main(), then you can place it inside the class block, but outside any methods. If you do this, declare it to be static as well. Example: class Yadda { static variable1; public static int method1() { // stuff } public static void method2() { // other stuff } public static void main(String[] args) { } } Note that in the above example, "variable1" can be used in method1, method2, and main. General Requirements When you write source code, it should be readable and well-documented. See the link Style Guidelines for further instructions on this topic Compiling and testing Compilation instructions for various environments are on the course web site, under the heading "Compilers and Compiling Help". These include instructions for building projects in both NetBeans and Eclipse, as well as compiling from the command line on your CS account or from the DOS prompt. Make sure to test your program with a variety of different inputs. The Sample Runs above are just that -- examples, only. Never hard-code your programs to work for only one or two test cases. Your program should work and calculate the correct results for any set of valid inputs. Submitting: Program submissions should be done by using the web site http://cgs3416.swzinc.org. Add the file(s) PigLatin.java and Sentences.java to your submission. Do not send program submissions through e-mail -- e-mail attachments will not be accepted as valid submissions. General Advice - always keep an untouched copy of your finished homework files on your computer science account, or e-mail a copy of your finished files (before the due date) to your own FSU e-mail account. This way, these files will have a time-stamp which will show when they were last worked on (a timestamp from the CS servers, or a time stamp on the FSU e-mail) and will serve as a backup in case you ever have problems with submitting files. My advice is to do this for ALL programs. For HW #4, submit only the following file: PigLatin.java Sentences.java