INQ241B
Mobile Apps

Final Review

A Miniature Practice Exam

  1. Draw what the following script would draw when run:

    action main()
      ◳angle := 0
      ▷go(25)
      ▷go(50)
    end action
    
    private action go(
      distance : Number)
    do
      turtle→forward(distance * 2)
      ◳angle := ◳angle + 45
      turtle→left turn(◳angle)
    end action
  2. For the following script:

    action main()
      var board := game→start
      var rectangle := create rectangle(100, 100)
      rectangle→set pos(rectangle→width / 2, board→height / 2)
      board→add on every frame(perform)
        where perform() is
          ▷update(rectangle)
      end
    end action
    
    private action update(
      sprite : Sprite)
    do
      sprite→set x(sprite→x + 10)
      if sprite→right > board→width then
        sprite→set left(0)
      else do nothing end if
    end action
    1. Draw what will be displayed when the app first starts.

    2. Describe what will happen when the app runs.

  3. For the following script:

    page main ()
    initialize
      ◳count := 0
    display
      boxed
        box→set width(10)
        box→set height(10)
        if ◳count = 0 then
          box→set background(colors→black)
        else
          box→set border(colors→black, 0.1)
        end if
        box→on tapped(handler)
          where handler() is
            ◳count := ◳count + 1
            if ◳count = 2 then
              ◳count := 0
            else do nothing end if
        end
      end boxed
    end page
    1. Draw what will be displayed when the app first starts.

    2. Describe what will happen when the user presses the button multiple times.