Overview

As you now know, there are some core things that every programming language has. You’ve seen the syntax already during the scavenger hunt, but now it’s time to think a bit more deeply about what all the syntax was doing.

Basic Learning Objectives

Before class, you should be able to explain the following in Kotlin:

  • Basic types (Int, Double, String)
  • Collections (Array, MutableList, MutableMap, MutableSet)
  • Control structures (if/else, when, for, while)
  • Functions

Advanced Learning Objectives

After class, you should be able to:

  • Write Kotlin using basic types, collections, control structures, and functions

Readings

To achieve the pre-class learning objectives, you should read the following sections in our textbook. Note: these are long sections and some of it will be review from the scavenger hunt, so a good strategy is to do a first pass where you skim and take notes on the syntax and what is discussed at a high level and then treat these as reference sections to come back to when you are wanting to use that Kotlin syntax specifically. Also, this is an in-progress textbook that has been adapted by Carleton professor Dave Musicant! There will definitely be typos or spots that are confusing, so please make note of them and we can fix them, yey!

Checks

You should submit answers to the following through Moodle (note that you can and should try typing up and running your answers in the embedded windows below). Once you have code that works, you can copy and paste it into a file named something like basics.kt to upload to Moodle. You may upload your answers in the same file or different files and the name of the files doesn’t matter (but should end with .kt).

  1. The code below computes a student’s GPA, but some lines are in the wrong order. Put the lines in the correct order. The output of this program should be:

     Student’s GPA: 3.65
    
  2. Given a list of letter grades from a student’s transcript, the function calculateGPA computes a student’s GPA based on Carleton’s grading system, but some parts are missing. Fill in the blanks for the code for the function calculateGPA. (main is already complete.) The output of this program should be:
     Student’s GPA: 3.25
     Student’s GPA: 2.42
     Student’s GPA: 2.17
    
  3. Did you find any typos or unclear spots? Please list them so we can fix them!