Assignment 1 – Dart Practice

  1. Due
  2. Objective
  3. Instructions
  4. Part 1 - Simple Dart
  5. Part 2 - Class Definition
  6. Part 3 - Class Definition, redux
  7. Submission

Due

Wednesday, January 24 @ 11:59pm via Canvas

Objective

To be introduced to and get comfortable with VSCode and basic Dart language features.

Instructions

This assignment must be completed individually. You may use Internet sources, but you must cite algorithms that you copy and modify from elsewhere.

  1. Create a new Flutter project called dart-practice using the VSCode command palette as described in Getting started with Visual Studio Code.
  2. Replace lib/main.dart with the following file: main.dart
  3. Download practice.dart and place it in the lib/ folder.

Run the Flutter application from main.dart. You should see a simple UI with text, including a few “FIX ME”s.

Part 1 - Simple Dart

Part 2 - Class Definition

  1. Define a class called Person in practice.dart below the Practice class:
    • Define three class variables in the Person class:
      1. first a String representing a person’s first name
      2. last a String representing a person’s last name
      3. age an int representing a person’s age
    • Define a Constructor for the Person class such that a call to Person("Sammy", "Seahawk", 22) will initialize the appropriate class variables.
    • Define a method named getWelcome() with no parameters that returns a String that formats the values of the class variables as: My name is {first} {last} and I am {age} years old.
    • To test, uncomment lines 35 and 65-67 in main.dart.
    • Change line 35 of main.dart to contain your name and age.
    • You should see the following (with your info) when completed correctly: Assignment 1 Part 2 output

Part 3 - Class Definition, redux

  1. Define a class called OptionalPerson in practice.dart below the Person class. Feel free to copy and paste from the Person class to start.
    • Define three class variables in the Person class:
      1. first a String representing a person’s first name
      2. last a String representing a person’s last name
      3. age an nullable int representing a person’s age
    • Define a Constructor for the Person class wherein the first and last names are required, but the age is optional, i.e., age does not need to be passed as a parameter.
    • Define a method named getWelcome() with no parameters that returns a String that returns the values of the class variables in the following format:
      • “My name is {first} {last} and I am {age} years old.” iff age is not null.
      • “My name is {first} {last}.” iff age is null.
    • When you are ready to test, uncomment 70-71 in main.dart.
    • Below line 36 of main.dart, declare two variables that instantiate instances of your new OptionalPerson class. Create one with the age and one without age.
    • Add some code after the const Text('class OptionalPerson', style: TextStyle(fontWeight: FontWeight.bold)), in main.dart to display the result of getWelcome() called in your two OptionalPerson variables. Feel free to copy, paste, and modify my code.
    • You should see something similar to the following when completed correctly: Assignment 1 Part 3 output

Submission

Submit your main.dart and practice.dart files to Canvas.