Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

it is a problem for Java It's October the spooky time of the year. This lab will use for loops, substring, and string concatenation to

it is a problem for Javaimage text in transcribed

It's October the spooky time of the year. This lab will use for loops, substring, and string concatenation to descramble a string to give you either a short scary story (if you are up for it) or a short joke, depending on your input.(1 for joke, 2 for scary story) The decoding for the scary story is done by adding three characters to a string then skipping 3, for the joke it is done by adding 2 characters to a string then skipping 2; both until the scrambled string ends 1. Start by making a method named descrambler, which returns a String and has the parameters: int input and String scrambled, in that order 2. Initialize an empty String (I'll refer to it as story) 3. Make a for loop that starts at 0 and goes 1 less than the length of the parameter string. This loop will also skip 3 letters per loop so increment i by 6 (3 letters concatenated +3 letters skipped) 4. In the for loop make an if statement which checks if input is 2 and i is less than 459 5. In the if statement concatenate the substring of scrambled from i to i+3 to story. You are now done with the First for loop 6. Now make a second for loop which starts at 459 to 1 less than the length of the parameter string. (increment by? HINT: step 3) 7. In the loop check if the input is 1 and if that is true then concatenate 2 letters 8. At the end of your method return story(or whatever you called your local string) LAB ACTIVITY 13.5.1: Short Story 0/10 StoryTime.java Load default template... 1 import java.util.Scanner; 2 public class StoryTime f 4 /*Method name: descrambler( 5 @returns: String 6 @param: int 7 @param: String 9 / Make your method here 12 13 public static void main (String[] args) t StoryTime s new StoryTime); Scanner scn new Scanner(System.in); System.out.println("Pick 1 for a joke or 2 for a Short Scary Story"); int input -scn.nextInt); String str"Juswert alois Iuyr waqies fplminiqweshenmcd wkjhashasfingwtf thttye dpolishertes ionm" 16 17 18 19 "y bcvdauertght hjker bnmpulqweleaghi onopl mywdf yebgniloderw dlos rescxzs apernd fas becuytkonlkjed ghjme asdto qwefoltyulo" 20 +"Wxcv hethmr tasro hjmner dfgroolkom. ewrShehyt stolkilldfg hewerld gfdtigjk8htlloiy adfgs Injk wacdflkelopd iplontocct" 21 +"thmnbe ebnmmptcvby rbvcoomxzs, rweremetyumberewrinqasg tghjhatcvg myghj dauioughploteriuy hartyd dwqsiedytr twfgho whjkeekbfds ahjk 22 "I erthrtretyw yua uiboioomoperasansdg dfa fgfeghw hjyejkarkls 1;agzxo.xc Icv nvbownm lerivtye uiinjk cfgondfstweancvt asfedfarer 23 24 25 26 27 28 if(input input2) String Story-s.descrambler(input, str); System.out.println (Story); else t System.out.println("Invalid Input"); 30 31

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Machine Learning And Knowledge Discovery In Databases European Conference Ecml Pkdd 2015 Porto Portugal September 7 11 2015 Proceedings Part 2 Lnai 9285

Authors: Annalisa Appice ,Pedro Pereira Rodrigues ,Vitor Santos Costa ,Joao Gama ,Alipio Jorge ,Carlos Soares

1st Edition

3319235249, 978-3319235240

More Books

Students also viewed these Databases questions