CS 245 - Programming Languages

Lab 7

Little Kotlin Programs

In this lab you will write, and or analyse a series of small programs in Kotlin. The intent here is simply to get you some practice with Kotlin before the first programming assignment. When you are complete, send me answers for the questions in slice analysis and kilometer / Miles program. If you do not complete both, send email with what you complete and a statement of where you go to.

In all of the programs below you may NOT use

  1. any variable declared to be a var (either explicitly or implicitly)
  2. Any loop construct

Fizz Buzz

Write a program that prints the numbers 1 .. 100 except: if the number is divisible by 3 print "Fizz", if the number is divisible by 5 print "Buzz", if the number is divisible by 3 and 5 print "FizzBuzz".

K to M conversion

Write a program that takes input from the command line to convert miles to kilometers or kilometers to miles. (1 mile equals 1.609km) For instance, if your command lines were
        kotlinc funclist6.kt -include-runtime -d funclist6.jar 
        java -jar funclist6.jar 10 k
    
then the output would be "6.14 miles". Comversely, if your command line was
        java -jar funclist6.jar 10 k
    
then the output should be "8.05 k"

Times Table

Write a program to produce a times table. You should write this in a function so that the size of the table prodyced is a paramater of the function. For example a times table for 1..3 looks like:
           1 2 3
        1  1 2 3
        2  2 4 6
        3  3 6 9
    
As with the general instructions, use only recursion. Once you have your times table printing, also create a lists of lists containing the factors (without headers) of the times table. Hence your list for the above table would be
        ((1,2,3), (2,4,6), (3,6,9))
    

What to hand in

Work no more than 80 minutes on the above programs. If you did not complete everything, send what you have.

Send email to gtowell245@cs.brynmawr.edu with all three programs. Along with the first and third program should be a main function that contains tests which shold your program in operation.