This assignment gets you started with the basic tools you will need to complete all of your homework projects. This project will ensure that you have correctly installed Scala, SBT and IntelliJ.
You are a student who needs to install all the tools necessary to get started in CS2340.
In this assignment you will set up your computer to
Install Scala for system-wide use on your computer by downloading the appropriate distribution from the bottom of https://www.scala-lang.org/download/
Download and install a programmer’s text editor (you can also use IntelliJ as a general text editor, but it can be awkward for quick file editing). In this course we will prmiarily use IntelliJ, but it’s important to be comfortable with general-purpose text editors too.
cs2340
.
cd
command).
mkdir cs2340
.cd cs2340
.Create a subdirectory of your cs2340
directory named hw0
.
On the command line, make sure you are in the hw0
folder. Enter these commands (remember that ‘$’ is the shell prompt (something like ‘C:\cs2340\hw0>’ on Windows) – don’t type the shell prompt character(s)):
$ scalac -version > hw0-output.txt
$ scala -version 2>> hw0-output.txt
Please note what is happening here:
>
redirects the standard output of a program.2>
(or2>>
) redirectsstderr
, which is used for diagnostics (such as version strings). The first line creates thehw0-output.txt
file, and the second line (with the extra>
) adds more text to the file. Here is a nice discussion of the file descriptorsstdin
,stdout
andstderr
.What this means is that
>
(or2>
) will overwrite the file, so if you go back to repeat the first step, you’ll need to repeat all the other steps as well.
Open your text editor and create a file in your newly created hw0
directory named NimblyBimbly.sh
(on Unix/Linux) or NimblyBimbly.bat
(on Windows) and enter the following Scala script:
Unix/Linux: NimblyBimbly.sh
#!/bin/sh
exec scala -savecompiled "$0" "$@"
!#
for (i <- 1 to 9)
print("\u004D\u0065\u006F\u0077 ")
println("...")
println("\u004D\u0065\u006F\u0077 ")
Windows: NimblyBimbly.bat
::#!
@echo off
call scala -savecompiled %0 %*
goto :eof
::!#
for (i <- 1 to 9)
print("\u004D\u0065\u006F\u0077 ")
println("...")
println("\u004D\u0065\u006F\u0077 ")
If you’re on Unix/Linux, make the script executable by entering chmod +x NimblyBimbly.sh
on the command line.
./NimblyBimbly.sh
on Unix/Linux or NimblyBimbly.bat
on Windows. You should see some output on the console.Run the script again and add its output to hw0-output.txt
by entering
Unix/Linux:
$ ./NimblyBimbly.sh >> hw0-output.txt
Windows:
C:\cs2340\hw0> NimblyBimbly.bat >> hw0-output.txt
Don’t forget the the double arrows in >>
!
hw0-output.txt
file to ensure that it contains the scalac
version string, the scala
version string, and the output of running your NimblyBimbly
script.Install SBT for your operating system using the instructions linked on the Getting Started with Scala and SBT on the Command Line page on docs.scala-lang.org.
In your hw0
directory, run the following command sbt new scala/hello-world.g8
. This pulls the ‘hello-world’ template from GitHub, prompts for project template values, and creates a starter SBT project.
When prompted, name the application hello-world
. This will create a project called “hello-world” in a subdirectory named hello-world
.
cd
to the hello-world
directory and examine the files and directories created by the sbt new
command and do the things listed on the Getting Started with Scala and SBT on the Command Line page on docs.scala-lang.org to get familiar with SBT.
Copy the first non-comment, non-blank line from hello-world/build.sbt
and paste it to the end of your hw0-output.txt
file.
Note: be sure to install the Scala plugin in IntelliJ.
Do the steps on the Building a Scala Project with IntelliJ and SBT page on docs.scala-lang.org with the following modifications:
build.sbt
file created in the previous section. Your File Open dialog may look something like this:
You may have noticed that the scala/hello-world.g8
template creates a project that uses Scala 2.12.7 and SBT 1.2.4. During the course of a Scala project you may update your Scala version or SBT version. Here’s how to update build settings (like the Scala version) and keep IntelliJ in sync (see also JetBrain’s help page for sbt projects). Do these steps:
scalaVersion
, which tells you the version of Scala sbt is using to compile and run your project. The version should be 2.12.7.build.sbt
and update the Scala version (the value of the setting scalaVersion
) to the most recent stable release (2.12.8 as of January 2019).sbt
tool window on the right and click the refresh button in the top left corner. The SBT shell will open and show the progress of the update.Note: You may also want to update the SBT version of an existing project, but to do that you’re better off simply updating the SBT version in
project/build.properties
, deleting the.idea
subdirectory (which contains the IntelliJ project), and re-importing the project frombuild.sbt
into IntelliJ as in Step 1 above.
After performing the substeps of Step 2 above, in the sbt shell execute the command scalaVersion
again. Copy the command’s output (which shows the updated value for scalaVersion
) and paste it to the end of your hw0-output.txt
file.
hw0-output.txt
FileAt this point your `hw0-output.txt file should contain
scalac
version string,scala
version string,NimblyBimbly
script,hello-world/build.sbt
, andscalaVersion
showing an updated scalaVersion
for the hello-world
project. This line should start with [info]
and show the most recent stable Scala version.If your hw0-output.txt
file is missing any of those elements you should redo all the steps that add content to hw0-output.txt
in each of the previous sections.
Submit your hw0-output.txt
file on Canvas as an attachment. When you’re ready, double-check that you have submitted and not just saved a draft.
Practice safe submission! Verify that your HW files were truly submitted correctly, the upload was successful, and that your program runs with no syntax or runtime errors. It is solely your responsibility to turn in your homework and practice this safe submission safeguard. NOTE: Unlike TSquare, Canvas will not send an email indicating that your assignment has been submitted successfully. Follow the steps outlined below to ensure you have submitted correctly.
This procedure helps guard against a few things.