Earn Higher Grades With Instant Assignment Help.Ask Question!

Computer Science
(5/5)

The goal of this assignment is to practice writing short Kotlin programs that use loops use conditional statements use the processing library functions process command line arguments

INSTRUCTIONS TO CANDIDATES
ANSWER ALL QUESTIONS

Kotlin & Processing basics

Overview

The goal of this assignment is to practice writing short Kotlin programs that

- use loops

- use conditional statements

- use the processing library functions

- process command line arguments

Before starting, follow instruction in the classpath how-to guide. I am assuming throughout this lab writeup that you have downloaded and saved the core.jar file in an appropriate place, and have defined your CLASSPATH environment variable appropriately, as described in the classpath how-to guide.

The programs

  1. Checkerboard. Write a program Checkerboard.kt that takes an integer command line argument n, and uses a nested loop construct to output an n-by-n checkerboard pattern like the ones below:

$ pkt CheckerboardKt 4

$ pkt CheckerboardKt 5

The convention is that the lower left corner square is always black. Note that your program must work correctly for any positive integer n, not just for n equal to 4 or 5. Additionally, your program should check that the user provides exactly one command line argument (as a positive integer) before continuing; it should give error message and quit otherwise.

  1. Bears. This exercise has two parts.
    1. Write a Kotlin program Bear.kt that draws a cute cartoon face of a bear like the following.

$ pkt BearKt

    1. By changing the arguments of all shape-drawing functions calls, turn your bear face drawing code into the function

fun bear1(x: Float, y: Float, w: Float, h: Float)

so that when bear1(x, y, w, h) is called, a bear face of width w, height h will be drawn with its upper left corner at (x, y). For example, this example run
$ pkt BearsKt

results from the fact that the file Bears.kt contains the line

    size(800, 400) 

inside its settings() definition, and the lines

    bear1(60F,  80F, 200F, 200F) 

    bear1(260F, 20F, 200F, 150F) 

    bear1(280F, 180F, 150F, 200F) 

    bear1(450F,  40F, 300F, 300F) 

inside its draw() definition.

    1. Now implement a function

fun bear2(x: Float, y: Float, w: Float, h: Float)

by changing the Bear.kt code so that calling bear2(x, y, w, h) works exactly like bear1(x, y, w, h). However, bear2 should use the translate and scale functions, and retains most of the bear face drawing code from Bear.kt.

  1. Random walks. A drone begins flying aimlessly, starting at Pittman Hall. At each time step, the drone flies one meter in a random direction, either north, east, south, or west, with probability 25%. How far will the drone be from Pittman Hall after n steps? This process is known as a two-dimensional random walk. It is a discrete version of a natural phenomenon known as Brownian motion. It serves as a scientific model for an astonishing range of physical processes from the dispersion of ink flowing in water, to the formation of polymer chains in chemistry, to cascades of neurons firing in the brain.
    1. Write a Kotlin program RandomWalker.kt that obtains an integer n from its command line argument and simulates the motion of a random walk for n steps. Draw the location point at each step (including the starting point), treating the starting point as the Cartesian Coordinates system origin (0, 0). Also, print the square of the final Euclidean distance from the origin. Here is an example run with n = 5000.

$ pkt RandomWalkerKt 5000

squared distance = 1250.0

Make sure the program checks the command line argument(s) and gives appropriate error message if not exactly one argument is given.

    1. Write a program RandomWalkers.kt that obtains two integers n and trials from its command line arguments. In each of trials independent experiments, simulate a random walk of n steps and compute the squared distance (without using the processing library to display the points.). Output the mean squared distance (the average of the trials squared distances). Here are example runs of the program on various values of n and trials.
  1. $ kotlin RandomWalkersKt 100 10000 $ kotlin RandomWalkersKt 400 2000
  2. mean squared distance = 101.446 mean squared distance = 383.12
  3. $ kotlin RandomWalkersKt 100 10000 $ kotlin RandomWalkersKt 800 5000
  4. mean squared distance = 99.1674 mean squared distance = 811.8264
  5. $ kotlin RandomWalkersKt 200 1000     $ kotlin RandomWalkersKt 1600 100000

mean squared distance = 195.75          mean squared distance = 1600.13064

As n increases, we expect the random walk to end up farther and farther away from the origin. But how much farther? Use RandomWalkersKt to formulate a hypothesis as to how the mean squared distance grows as a function of n. Use trials = 100,000 to get a sufficiently accurate estimate.

Make sure the program checks the command line argument(s) and gives appropriate error message if not exactly two arguments are given.

Program style and format

Follow the guidelines in the Style Guidelines. Is your header complete? Did you comment appropriately? Is your code indented consistently? Did you use descriptive variable names? Did you follow the input and output specifications? Are there any redundant conditions?

Gradesheet

We will use this gradesheet when grading your lab.

Submission

You should create a “zip” archive file containing all Kotlin programs and your completed readme.txt file. Be sure to include the completed readme.txt file in your zip file. Read zip how-to if you do not know how to create a zip file. Ask your lab instructor for help if you need it.

Submit the zip file via Moodle.

Powered by pandoc and hakyll. Last modified on: Wed Apr 01 2020 18:48:28 GMT+0530 (India Standard Time)

 

 

Attachments:
(5/5)

Related Questions

CSI 1420 Introduction to C Programming & Unix Fall 2018, CRN 44882, Oakland University Homework Assignment 6 - Using Arrays and Functions in C

DescriptionIn this final assignment, the students will demonstrate their ability to apply two majorconstructs of the C programming language – Fu

The standard path finding involves finding the (shortest) path from an origin to a destination, typically on a map. This is an

Path finding involves finding a path from A to B. Typically we want the path to have certain properties,such as being the shortest or to avoid going t

Develop a program to emulate a purchase transaction at a retail store. This program will have two classes, a LineItem class and a Transaction class. The LineItem class will represent an individual

Develop a program to emulate a purchase transaction at a retail store. Thisprogram will have two classes, a LineItem class and a Transaction class. Th

SeaPort Project series For this set of projects for the course, we wish to simulate some of the aspects of a number of Sea Ports. Here are the classes and their instance variables we wish to define:

1 Project 1 Introduction - the SeaPort Project series For this set of projects for the course, we wish to simulate some of the aspects of a number of

Project 2 Introduction - the SeaPort Project series For this set of projects for the course, we wish to simulate some of the aspects of a number of Sea Ports. Here are the classes and their instance variables we wish to define:

1 Project 2 Introduction - the SeaPort Project series For this set of projects for the course, we wish to simulate some of the aspects of a number of

Ask This Assignment To Be Done By Our ExpertsGet A+ Grade Solution Guaranteed

expert
joyComputer science
(4/5)
12 Answers Hire Me
expert
Robert DLaw
(4.8/5)
992 Answers Hire Me
expert
Dr Samuel BarberaStatistics
(5/5)
846 Answers Hire Me
expert
Tutor For YouEconomics
(5/5)
867 Answers Hire Me