Create a customised childrens story


Assignment:

Task:

Imagine you are writing a computer program that creates a customised children's story using names provided by the user of the program. Your first attempt at the program prompts the user for the gender and name of the hero, the type and name of their pet, and writes the first two sentences of the story.

For instance, if the user provides the following information: 'F' (for female), Poppy, cat, Jess, the program will produce the output given in Figure :

875_customised story.jpg

Look at the skeleton program and answer part (a) below. Then develop the program by editing your answer file step-by-step as specified in parts (b) to (e).The first two lines of code have been written for you. The user is prompted for the hero's gender ('F' or 'M') and the hero's name. (Note the need for the escape character before the apostrophe in the prompt string.)

(a) What is the purpose of the second argument 'F' in the statement
heroGender = window.prompt('Is the hero female or male? Enter F or M', 'F'); ?

(b) Write the next two lines of code (as indicated by the comments in the code file) to prompt the user for the type of pet (i.e. what type of animal it is) and the name of the pet.

The program is not expected to check that what the user enters makes sense. It should simply accept whatever is input.

Run the program and check that it prompts for four inputs in total. (You can enter whatever you like in response to each prompt. The program will not yet produce any output.)

Take a screenshot of the prompt for the name of the pet and insert the screenshot into your Solution Document along with the two lines of code you have added.

(c) Write a line of code to output 'Once upon a time there was a ' (note the space at the end). Run the program and check that it now prompts for four inputs then writes this output. Insert this line of code in your Solution Document.

(d) You now need a selection structure to decide whether to output 'girl ' or 'boy '. Here is the required algorithm:

if heroGender is 'F'
output 'girl '
else
output 'boy '

Using this algorithm, write the code and test that it works.

(e) Write the code to produce the remaining output, as in Figure . The second sentence should appear on a new line. Take a screenshot of the output from your final program. It should be similar to Figure , but with different details.

Solution Preview :

Prepared by a verified Expert
JAVA Programming: Create a customised childrens story
Reference No:- TGS01938181

Now Priced at $25 (50% Discount)

Recommended (99%)

Rated (4.3/5)