Question 1
Topic: Lesson 1: introduction to Flutter and Dart Programming Language
Skill tested: Applies Dart variable types and inference when representing values with different data types.
A small Dart command-line utility reads a quantity from a text source and calculates an estimated cost. The source returns a String, while the calculation requires a numeric value. The program should keep the quantity read from the source unchanged, reject input that cannot be parsed, and avoid weakening type safety by storing unrelated values in a dynamically typed variable. Which implementation best meets these requirements?
Parsing the source String into a separate int preserves the original input and gives the calculation a statically checked numeric value. The program should account for parsing failure, for example by using int.tryParse and handling a null result. A dynamic variable in A bypasses useful compile-time checks, and multiplication will not convert arbitrary strings automatically. B attempts an invalid assignment because Dart does not implicitly convert String to int. D performs string-oriented operations rather than numeric calculation.