Kotlin Basics Preparation
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
- Collections
- Control flow
- Functions
Advanced Learning Objectives
After class, you should be able to:
- Write Kotlin using basic types, collections, control flow, and functions
Readings
To achieve the pre-class learning objectives, you should read the following sections in the Kotlin tour:
- Hello World
- Basic Types
- Collections
- Control Flow
- Functions - Up to but not including Lambda expressions
Checks
You should submit answers to the following on the Gradescope assignment linked through Moodle (note that you can and should try typing up and running your answers). You may upload them in the same file or different files and the name of the files doesn’t matter.
-
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
-
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 functioncalculateGPA
. (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