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
$ 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.
$ pkt BearKt
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.
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.
$ 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.
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)
DescriptionIn this final assignment, the students will demonstrate their ability to apply two ma
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. Thisprogram will have two classes, a LineItem class and a Transaction class. Th
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
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