Goal: The goal for this next App pick an excuse at random when needed.

In previous apps, we have give quite complete instructions. In an effort to help you become more independent, this app deliberately asks you to discover the solutions on your own.

Check out this video to see a preview of the app.


As an alternative to using the instructions below, here is an alternate video explanation. Go to this page.



It is often helpful to write down what you want to have happen - without worrying about the exact statements you will need. This "pseudo-coding" helps you to focus on the design separately from the precise way of accomplishing the goal.


Phase 1: Create the user interface.



1. Add a button that you will click to display excuses.

A) Rename this component and then add text to the button so that the user knows that this button will give us an excuse.




2. Create a HorizontalArrangement in your viewer to hold the excuse that you generate.

A) The excuse will consist of two labels described below.

3. Add two Label components and put them side by side.

A) In the first Label you should change the text to "Reason."

B) Keep the second label blank as this will change when we click the button and display our Excuse.

C) Be sure to rename these components so that you know what they do. I have labeled them ExcuseLabel and ExcuseDisplay.
C) If you need to adjust the size of the labels do so now.

3. Add a TextToSpeech component to speak the excuse.



Phase 2: Adding the excuses


1.Set your ExcuseDisplay to a blank screen whenever the Screen is initialized.
You will need the when.Initialize block and a statement from your label component.

2. Create a variable to hold a list of excuses.

A) Make sure you name your variable with a name that makes sense.

3. Use a when.Click block to call a set.Text block which will select items from your list. This is very similar to what we just did in Positive Self Talk.


4. Use a block from your lists component to pick a random item from your list. It will be good to pick a random index so you know which item you are looking at. This is helpful later on.


GetExcuse1.PNG


5. Test your app. Does it say your excuses out loud?



Phase 3: Adding new excuses.


1. Add another button named "Add Excuse."

A) This button will be used to add excuses to your Excuse generator.
B) Add a Textbox. The user will type in new excuses into this text box. When we receive data from the user, we call it input.

2. Now that we have a textbox for entering our new excuses and a button to get the text from textbox, we need to tell our App what to do with the input that is put into the textbox.

A) The textbox will be used to enter new excuses that you want to add to your Excuse Generator. We can get the text that is entered into the textbox with the following block.We call a statement which grabs the contents of a variable a "getter". This is opposed to a "setter" which changes the contents of a variable.
newExcuse.PNG
B) You will need to connect a block from your TextBox component to your existing list. You want to add to the list. Where would you expect to find an "add to list" instruction?

addToList.PNG
C) This is almost complete. You just need to tell it "What list?"

Add these blocks into a when.Click for the Add Excuse button!

3. Test your app. Does it say your new excuse as well?



Phase 4: Deleting an excuse and resetting our excuse list to the original list. Suppose you hear an excuse you just don't like and decide to delete it. How could you do that? This video shows an overview, but don't expect complete instructions. Use your own creativity to add this feature.


1. Add two more buttons.
A) The first button should be labeled Delete, this will be used to tell the program we want to delete the last excuse that you heard..
B) The second button should be called Reset. This button will return your excuse generator to it's original form.


2. Write the code to delete an excuse.

A) You will delete an excuse by telling the program the index of the excuse you want to remove. Lucky for us, we know the index of the excuse that is currently displayed.
removeList.PNG

B) An interesting thing happens if you just keep deleting things from the list. The index you have stored might not be valid. What do you think the program will do if you ask it to delete the fourth item from a list that only has three items? It won't be happy! We often write special instructions to make sure we don't ask the program to do something bad. Such error checking is an important part of good programming.

LegalValue.PNG


3. The reset button needs to be programmed to reset the excuse list to exactly what it was before you started adding or deleting. The best way to do this is to create the list again. You did it once, you can just do it again (by duplicating the "make a list" command).


4. Test your app.


5. I got tired of just pressing the "get excuse" button to see if an item was really deleted. The list picker is a simple way of seeing the contents of your list.

A) Just Drag in ListPicker (from Designer). It is under User Interface. I renamed it "Show_AllListPicker". The only code I needed was:

ListPicker.PNG
B) When you click on the button, it sends you to a different phone screen and displays the list. It returns when you click on any item of the list.


Challenges



1. (*) Add additional buttons so that you can tailor the excuse to the problem.

A) For example you could have an excuse button for Homework, Not Doing chores, Getting home late, etc.

B) Then for each button you'll need to make a unique list. If you use the duplicate feature, you can do this quite quickly.


2. (*) Add a picture button so that each excuse you give has a picture that goes along with the excuse. So, if the excuse is "My dogs ate my homework", you could also display:

dogs.jpg

3. (***) See if you can teach yourself how to use a TinyDB. Many times in programming you have to learn to use new features without the benefit of someone teaching you. See if you can figure it out on your own.


Add a TinyDB1 component. This will allow you to store data so that you don't lose your newly added excuses each time you stop using the App.