Fun with Methods CS 221 Spring 2022 - Due: by 5pm on 4/29/22 In this project you will be creating several methods to do

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899604
Joined: Mon Aug 02, 2021 8:13 am

Fun with Methods CS 221 Spring 2022 - Due: by 5pm on 4/29/22 In this project you will be creating several methods to do

Post by answerhappygod »

Fun With Methods Cs 221 Spring 2022 Due By 5pm On 4 29 22 In This Project You Will Be Creating Several Methods To Do 1
Fun With Methods Cs 221 Spring 2022 Due By 5pm On 4 29 22 In This Project You Will Be Creating Several Methods To Do 1 (92.34 KiB) Viewed 7 times
Fun With Methods Cs 221 Spring 2022 Due By 5pm On 4 29 22 In This Project You Will Be Creating Several Methods To Do 2
Fun With Methods Cs 221 Spring 2022 Due By 5pm On 4 29 22 In This Project You Will Be Creating Several Methods To Do 2 (82.61 KiB) Viewed 7 times
Fun With Methods Cs 221 Spring 2022 Due By 5pm On 4 29 22 In This Project You Will Be Creating Several Methods To Do 3
Fun With Methods Cs 221 Spring 2022 Due By 5pm On 4 29 22 In This Project You Will Be Creating Several Methods To Do 3 (72.56 KiB) Viewed 7 times
Fun With Methods Cs 221 Spring 2022 Due By 5pm On 4 29 22 In This Project You Will Be Creating Several Methods To Do 4
Fun With Methods Cs 221 Spring 2022 Due By 5pm On 4 29 22 In This Project You Will Be Creating Several Methods To Do 4 (59.6 KiB) Viewed 7 times
Fun With Methods Cs 221 Spring 2022 Due By 5pm On 4 29 22 In This Project You Will Be Creating Several Methods To Do 5
Fun With Methods Cs 221 Spring 2022 Due By 5pm On 4 29 22 In This Project You Will Be Creating Several Methods To Do 5 (93.74 KiB) Viewed 7 times
Fun with Methods CS 221 Spring 2022 - Due: by 5pm on 4/29/22 In this project you will be creating several methods to do a variety of things. Be careful to implement exactly what the method is asking for. Be sure to follow these rules (or lose points): 1. You must implement all of these methods in a single class called Project3 2. You must name your methods exactly as they are written below. Do not change the method name or modify the capitalization. 3. Do not add, remove, or reorder parameters or change the types. (Match examples given.) 4. Do not change the return type. a. Note: Returning is not the same as printing. The method should only print something if the instructions say so. Otherwise, the method should return the result and should not print anything. (You can and should print as you code and debug, but remove print statements that should not be there prior to submission.) 5. Each method may have at most one return statement (or none if it is void and does not return anything). You will lose points if you have a method with multiple return statements. 6. For the methods that work with Strings, you are only allowed to use charAt, substring, indexof, length, equals and/or compare To. If you want to use any other built-in method, you must ask me first (and I may say no--some methods may exist that make the task trivial. You will not be allowed to use these). To be clear, you are not allowed to use any replace or replace All String methods. 7. be Do not duplicate code in this project. Make use of methods that you write if they can used elsewhere in the project. If you have any questions about what the method is asking for, just ask.
Methods to write: 1. (2 pts) Create a method called printArray that prints a given array of Strings in the following form on the same line: [String1, String2, String3, StringN] *** " So the array items are surrounded by square brackets, and each item in the array is separated by a comma. Note: There is no comma after the last item. For example: String[] a = ("puppy", "kitten", "hamster"}; printArray (a) // Prints: [puppy, kitten, hamster] String[] b ("fish", "piglet", "puppy", "turtle"); printArray (b) // Prints: [fish, piglet, puppy, turtle] String[] c = new String [0]; printArray (c) // Prints: [] You may not use the built in Arrays.toString method (you are essentially writing your own version of this method). 2. (3 pts) Create a method called inAlphabeticalOrder that given an array of Strings, determines if the items are in alphabetical order. For example: String[] a = ("puppy", "kitten", "hamster"); inAlphabeticalOrder (a) // Returns: false String[] b = ("kitten", "piglet", "puppy", "turtle"); inAlphabeticalOrder (b) // Returns: true String[] c = new String [0]; inAlphabeticalorder (c) // Returns: true
3. (3 pts) Many acronyms exist, whether it's DM acronyms like "rofl" ("rolling on floor laughing") or "smh" ("shaking my head") or acronyms within a university or company like "USP" ("University Studies Program") or "ARU" ("Academic Revenue Units"). For those that do not know acronyms (like if you were to message your grandma, or for a new employee), write a method called acronymExpander that takes a given text, a given acronym, and the corresponding expansion that the given acronym stands for (so three parameters total; note the examples given below). If the given acronym appears in the given text, every appearance will be expanded to what it stands for. The acronym only needs to be expanded if it matches the casing given. The final acronym-expanded text should be returned from the method. Carefully observe the example inputs and associated outputs below to better understand what your method is supposed to do: A String myText "lol did you see this episode? Lol imo it was hilarious when Andy surprised April lol!"; acronymExpander (myText, "lol", "laugh out loud") Returns: "laugh out loud did you see this episode? Lol imo it was hilarious when Andy surprised April laugh out loud!" acronymExpander (myText, "IDK", "I don't know") Returns: "101 did you see this episode? Lol imo it was hilarious when Andy surprised April lol!"
4. (3 pts) Overload the acronymExpander method to take a given text and two (parallel) arrays of Strings where the first array has acronyms the user wants expanded in the given text and the second array has the associated expansions for the acronyms. For example: String myText = "lol did you see this episode? Lol imo it was hilarious when Andy surprised April lol!"; string[] acronyms = ("101", "imo"); String[] exps = ("laugh out loud", "in my opinion"}; acronymExpander (myText, acronyms, exps) Returns: "laugh out loud did you see this episode? Lol in my opinion it was hilarious when Andy surprised April laugh out loud!" Note the rules outlined at the start of this project: Do not duplicate code in this project. (Spoiler Hint: use (call) your method from task 3 in this task.) 5. (3 pts) "Drawing" options at random from a set of possible choices is a relatively common task. For example, say you have 10 people, and you are trying to pick two at random to be on call, or maybe you're trying to pick five at random to do a drug test. Write a method called drawItems to support a random drawing: given an array of Strings, and a number of how many to draw, return an array with that many elements drawn at random from the given array. Elements cannot be drawn more than once. You may assume that the number passed in is between zero and the length of the array inclusive (and your documentation should reflect this assumption!). Do not modify the original array passed into the method. Examples: String[] profs = ("Hannah", "Erik", "Scott", "George", "David", "Ahilan", "Kathy"); drawn (profs, 3) // Might return: [Erik, Ahilan, Scott] drawn (profs, 3) // Might return: [David, Scott, Erik) Cannot return: [George, Kathy, George] (no duplicates can be drawn)
drawn at random from the given array. Elements cannot be drawn more than once. You may assume that the number passed in is between zero and the length of the array inclusive (and your documentation should reflect this assumption!). Do not modify the original array passed into the method. Examples: String[] profs= ("Hannah", "Erik", "Scott", "George", "David", "Ahilan", "Kathy"); drawN (profs, 3) // Might return: [Erik, Ahilan, Scott] drawN (profs, 3) // Might return: [David, Scott, Erik) Cannot return: [George, Kathy, George] (no duplicates can be drawn) 6. (1 pts) Overload the drawItems method to only take an array of Strings. This method should randomly draw all elements of the array. Do not duplicate any code in this project that you do not have to. (Spoiler Hint: This method should only have one line of code.) 7. (3 pts) "Testing" code is not just about making sure it runs, but making sure it runs correctly. For varying input, does the output match what you expect it to be for the given input? To properly test code, you have to consider the range of possible inputs, choose representative test cases to represent each range, run the code with these inputs, and finally, ensure the output of the code is what it should be, based on the input (does the actual output from the code match expected output). You must create a main method to test all of your methods in this manner by making multiple calls to each with different input(s), and then check that the outputs satisfy what you would expect by outputting the result you got (here it's okay to print!) next to what you should have gotten. For example, your main should have print outs similar to this: "Drawing 1 item from ["kitten", "puppy", "turtle"]: ["kitten"] (expected: 1 item)". Provide as many hard-coded calls to each method as necessary to demonstrate that your method works for the range of inputs you've considered may be possible to be given to your method. (By hard-coded I mean that the values you are testing should be defined in your code; there should be no Scanner/user input in this project.) You must be sure you test each "path" your method could take. For example, if you have an if else statement in your method, you must provide a method call that tests the "then block" and another method call that tests the "else block." Note that the examples I have provided are not sufficient to know whether the method is completely correct, and if you only have the same or very similar test cases as mine, you will not get full points for this part of the project. You have to consider the variety of cases that could be input into each method. If you are unsure of what this requirement is asking, talk to me for advice.
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply