Basic HTML Version

|  | Table of Contents |  | View Full Version

Page 67 - logicode 2609 C6
P. 67

    Example 2: Create an app that shows ‘Hello’ when a button is clicked in MIT App Inventor.
                     Step  1    Start

                              1.1  Open MIT App Inventor in your browser.
                              1.2  Click New project and name it HelloApp.

                     Step  2    Design the Screen
                              2.1  Drag a Button onto Screen1, rename it ButtonHello and set the Text to “Say Hello”.

                              2.2  Drag a Label onto Screen1, rename it LabelOutput and leave the text blank.
                     Step  3    Add the Behaviour (Blocks Editor)

                              3.1  Open the Blocks tab.

                              3.2  From ButtonHello, drag the event block “when ButtonHello.Click do”.
                              3.3   From LabelOutput, drag the setter “set LabelOutput.Text to” and snap it inside the
                                   event block.

                              3.4   From Text blocks, drag a text literal, type “Hello” and connect it to the setter.

                     Step  4    Test the App
                              4.1  Connect a device or emulator.

                              4.2   Run the app, tap “Say Hello” and verify that “Hello” appears in LabelOutput.
                     Step  5    End

                     Example 3: Write an algorithm to subtract two numbers and display the result.
                     Step  1    Start

                     Step  2    Input num1 and num2.

                     Step  3    Calculate Sub = num1 – num2.
                     Step  4    Display Sub.

                     Step  5    Stop
                     Example 4: Write an algorithm to input a number and check if a number is between 1 and 100.

                     Step  1    Start
                     Step  2    Input NUM.

                     Step  3    If NUM >= 1 and NUM<= 100, then

                                   Display "NUM is between 1 and 100."
                              Else

                                   Display "NUM is not between 1 and 100."
                     Step  4    Stop

                     Example 5: Write an algorithm to display the even numbers from 2 to 10.
                     Step  1    Start

                     Step  2    Set a variable NUM = 2.

                                                                                  Algorithms, Flowcharts and System Maps  65

| 62 63 64 65 66 67 68 69 70 71 72 |