cws/cw01.tex
changeset 166 780c40aaad27
parent 152 114a89518aea
child 167 349d706586ef
equal deleted inserted replaced
165:1347bbd86c52 166:780c40aaad27
     1 \documentclass{article}
     1 \documentclass{article}
     2 \usepackage{../style}
     2 \usepackage{../style}
       
     3 \usepackage{disclaimer}
     3 %%\usepackage{../langs}
     4 %%\usepackage{../langs}
     4 
     5 
     5 \begin{document}
     6 \begin{document}
     6 
     7 
     7 \section*{Coursework 6 (Scala)}
     8 \section*{Coursework 6 (Scala)}
    11 at 11pm. You are asked to implement three programs about list
    12 at 11pm. You are asked to implement three programs about list
    12 processing and recursion. The third part is more advanced and might
    13 processing and recursion. The third part is more advanced and might
    13 include material you have not yet seen in the first lecture.
    14 include material you have not yet seen in the first lecture.
    14 \bigskip
    15 \bigskip
    15 
    16 
    16 \noindent
    17 \IMPORTANT{}
    17 \textbf{Important:}
       
    18 
       
    19 \begin{itemize}
       
    20 \item Make sure the files you submit can be processed by just calling\\
       
    21 \mbox{\texttt{scala <<filename.scala>>}} on the commandline.
       
    22 
       
    23 \item Do not use any mutable data structures in your
       
    24 submissions! They are not needed. This means you cannot create new 
       
    25 \texttt{Array}s or \texttt{ListBuffer}s, for example. 
       
    26 
       
    27 \item Do not use \texttt{return} in your code! It has a different
       
    28   meaning in Scala, than in Java.
       
    29 
       
    30 \item Do not use \texttt{var}! This declares a mutable variable. Only
       
    31   use \texttt{val}!
       
    32 
       
    33 \item Do not use any parallel collections! No \texttt{.par} therefore!
       
    34   Our testing and marking infrastructure is not set up for it.
       
    35 \end{itemize}
       
    36 
    18 
    37 \noindent
    19 \noindent
    38 Also note that the running time of each part will be restricted to a
    20 Also note that the running time of each part will be restricted to a
    39 maximum of 360 seconds on my laptop.
    21 maximum of 360 seconds on my laptop.
    40 
    22 
    41 
    23 \DISCLAIMER{}
    42 \subsection*{Disclaimer}
       
    43 
       
    44 It should be understood that the work you submit represents
       
    45 your \textbf{own} effort. You have not copied from anyone else. An
       
    46 exception is the Scala code I showed during the lectures or
       
    47 uploaded to KEATS, which you can freely use.\bigskip
       
    48 
    24 
    49 
    25 
    50 \subsection*{Part 1 (3 Marks)}
    26 \subsection*{Part 1 (3 Marks)}
    51 
    27 
    52 This part is about recursion. You are asked to implement a Scala
    28 This part is about recursion. You are asked to implement a Scala
   273   have become out of our \$100.
   249   have become out of our \$100.
   274 \end{itemize}
   250 \end{itemize}
   275 
   251 
   276 \noindent
   252 \noindent
   277 Until Yahoo was bought by Altaba this summer, historical stock market
   253 Until Yahoo was bought by Altaba this summer, historical stock market
   278 data for such back-of-the-envelope calculations was available online
   254 data for such back-of-the-envelope calculations was freely available
   279 for free, but nowadays this kind of data is difficult to obtain, unless
   255 online. Unfortuantely nowadays this kind of data is difficult to
   280 you are prepared to pay extortionate prices or be severely
   256 obtain, unless you are prepared to pay extortionate prices or be
   281 rate-limited.  Therefore this coursework comes with a number of files
   257 severely rate-limited.  Therefore this coursework comes with a number
   282 containing CSV-lists about historical stock prices for companies of
   258 of files containing CSV-lists with the historical stock prices for the
   283 our portfolio. Use these files for the following tasks.\bigskip
   259 companies in our portfolios. Use these files for the following
       
   260 tasks.\bigskip
   284 
   261 
   285 \noindent
   262 \noindent
   286 \textbf{Tasks (file drumb.scala):}
   263 \textbf{Tasks (file drumb.scala):}
   287 
   264 
   288 \begin{itemize}
   265 \begin{itemize}
   302   this problem is to obtain the whole January data for a stock symbol
   279   this problem is to obtain the whole January data for a stock symbol
   303   and then select the earliest, or first, entry in this list. The
   280   and then select the earliest, or first, entry in this list. The
   304   stock price of this entry should be converted into a double.  Such a
   281   stock price of this entry should be converted into a double.  Such a
   305   price might not exist, in case the company does not exist in the given
   282   price might not exist, in case the company does not exist in the given
   306   year. For example, if you query for Google in January of 1980, then
   283   year. For example, if you query for Google in January of 1980, then
   307   clearly Google did not exists yet.  Therefore you are asked to
   284   clearly Google did not exist yet.  Therefore you are asked to
   308   return a trade price as \texttt{Option[Double]}\ldots\texttt{None}
   285   return a trade price as \texttt{Option[Double]}\ldots\texttt{None}
   309   will be the value for when no price exists.
   286   will be the value for when no price exists.
   310 
   287 
   311 \item[(1.c)] Write a function \texttt{get\_prices} that takes a
   288 \item[(1.c)] Write a function \texttt{get\_prices} that takes a
   312   portfolio (a list of stock symbols), a years range and gets all the
   289   portfolio (a list of stock symbols), a years range and gets all the
   376 companies, whose names I have never heard of. Following the dumb
   353 companies, whose names I have never heard of. Following the dumb
   377 investment strategy from 1978 until 2017 would have turned a starting
   354 investment strategy from 1978 until 2017 would have turned a starting
   378 balance of \$100 into roughly \$30,895 for real estate and a whopping
   355 balance of \$100 into roughly \$30,895 for real estate and a whopping
   379 \$349,597 for blue chips.  Note when comparing these results with your
   356 \$349,597 for blue chips.  Note when comparing these results with your
   380 own calculations: there might be some small rounding errors, which
   357 own calculations: there might be some small rounding errors, which
   381 when compounded, lead to moderately different values.\bigskip
   358 when compounded lead to moderately different values.\bigskip
   382 
   359 
   383 \noindent
   360 \noindent
   384 \textbf{Hints:} useful string functions: \texttt{.startsWith(...)} for
   361 \textbf{Hints:} useful string functions: \texttt{.startsWith(...)} for
   385 checking whether a string has a given prefix, \texttt{\_ + \_} for
   362 checking whether a string has a given prefix, \texttt{\_ ++ \_} for
   386 concatenating two strings; useful option functions: \texttt{.flatten}
   363 concatenating two strings; useful option functions: \texttt{.flatten}
   387 flattens a list of options such that it filters way all
   364 flattens a list of options such that it filters way all
   388 \texttt{None}'s, \texttt{Try(...) getOrElse ...} runs some code that
   365 \texttt{None}'s, \texttt{Try(...) getOrElse ...} runs some code that
   389 might raise an exception, if yes, then a default value can be given;
   366 might raise an exception---if yes, then a default value can be given;
   390 useful list functions: \texttt{.head} for obtaining the first element
   367 useful list functions: \texttt{.head} for obtaining the first element
   391 in a non-empty list, \texttt{.length} for the length of a
   368 in a non-empty list, \texttt{.length} for the length of a
   392 list.\bigskip
   369 list.\bigskip
   393 
   370 
   394 
   371