Some basic tasks

There are a few basic things which is good to know when you solve exercises in this course:

Downloading exercise projects

The programming assignments for an exercise rounds are collected in one zip archive and can be downloaded from the corresponding A+ section

When you start a round, download the package, unpack the archive, and import the project in Code as described in Workflow.

Warning

Some unzipping utillities (e.g. on Windows) will create an extra folder with the same name as the zip file. As there is already a folder in the archive make sure you import the right one (see Workflow).

The files associated with an exercise is located in a directory called a<xy>-<project>, where <xy> is the number of the assignment in the round and <project> is the name of the assignment project. If you look in the subdirectory src/main and src/test you will find the scala files associated with the assignment task and test respectively.

The tasks are marked by comments and ??? in the scala file. Read the assignment instructions in A+ and comments in the source code for hints and descriptions of your tasks.

Note

Each exercise is will give you a problem description, your tasks, and often links to helpful material and hints. It pays to read all of this carefully.

Submitting your solutions for grading

When you are happy with your solution to an exercise check wich scala files are required for submission to A+ add them to the corresponding field on A+ and click ‘Submit’. (Tip: open a system file manager from Code by right-clicking on a file tab and selecting Open Containing Folder / Reval / Reveal in Finder [depends on your OS], then simply drag-n-drop the file to the web page.)

_images/startup-aplus-submit-annot.png

Select the required file for upload and click ‘Submit’.

Note

Most exercises will award some points for partial solutions, so it can be worth submitting your work even if you have not solved all tasks in an exercise before the deadline.

Warning

Note that A+ gives you a limited number of submissions (usually 10) for each exercise. So do not rely on the grader to test your solutions. This is what unit tests are for. Only submit when you want to be graded on your work.

Opening an sbt console from the command line

While developing your solution it is sometimes handy to be able to test things in the interactive sbt Scala REPL. If you have sbt installed on your computer you can start a REPL through its console.

Note

IntelliJ has a built-in sbt shell that you can use without explicitly installing anything extra. The drawback is that it is not as user-friendly as sbt started from the terminal (it has worse formatting, for instance). If you decide to use it, start it by selecting sbt shell instead of Terminal in IntelliJ, and skip the ‘sbt’ part of any commands below.

If you experience any problems with the built-in sbt-shell, it is usually best to follow the same instructions as for VS Code to install sbt on your system and start it from the terminal however.

To start a sbt console, do the following:

  • In VS Code, go to View → Terminal, in IntelliJ, select the Terminal tab at the bottom of the screen (or press Alt+F12). This will open up a system terminal in your project. Here you can give system commands just as from a normal terminal window.

Warning

In VS Code Do not use the popup menu from one of the project files, this will start a terminal in the specific sub directory of that file, and the sbt console may not work properly.

  • Basic console: To start a basic scala console you can give the command sbt "~console"

  • Alternatively you can start a console aware of your assignment code: Take the name of the assignment or library you want to be able to include and put it before the console part. For example to get a console aware of the files in the assignment “pascal” (in the folder a02-pascal). Give the command sbt "~pascal/console". (For assignments you always leave out the ‘axy-‘part.)

  • This will start a Scala console using the sbt build tool, and additionally tell sbt to watch the assignment files for changes in case you edit them (this is what the ~ part of the command does). Note that this uses a separate build mechanism from Code, so the first time you run it you may have to wait a few seconds for the files to compile.

    _images/vscode-console-1-annot.png

    Giving the command sbt "~ pascal/console" in a Code terminal tab.

Note

If the standard short-cuts pasting clipboard text is not working in the VS Code terminal try using Shift+Insert.

  • You should now see the familiar scala> prompt. Now you have a REPL ready to use, why not test it with some basic Scala? If you started with the name of an assignment can also import code from packages in that assignment, if needed.

    _images/vscode-console-2-annot.png

    Interactive Scala in the sbt console.

  • Use Ctrl+d to quit the console, or recompile (if there are saved changes to your source files this will trigger a recompile, otherwise it will quit the console).

Note

  • If you happen to only give the command sbt by mistake, you will enter the sbt build system (the prompt starts with sbt). That’s not a problem, just enter rest of the command there instead to start the Scala console.

  • The console will not start if you have a compilation error in your code.

  • If the terminal gives an error such as command not found: sbt then you need to check that sbt is properly installed and available in your system path.