31 on your own computer. For example you can call Scala on the command |
31 on your own computer. For example you can call Scala on the command |
32 line with the option \texttt{-cp drumb.jar} and then query any |
32 line with the option \texttt{-cp drumb.jar} and then query any |
33 function from the template file. Say you want to find out what |
33 function from the template file. Say you want to find out what |
34 the function \code{get_january_data} |
34 the function \code{get_january_data} |
35 produces: for this you just need to prefix them with the object name |
35 produces: for this you just need to prefix them with the object name |
36 \texttt{CW6b} and call them with some arguments: |
36 \texttt{M1} and call them with some arguments: |
37 |
37 |
38 \begin{lstlisting}[language={},numbers=none,basicstyle=\ttfamily\small] |
38 \begin{lstlisting}[language={},numbers=none,basicstyle=\ttfamily\small] |
39 $ scala -cp drumb.jar |
39 $ scala -cp drumb.jar |
40 |
40 |
41 scala> CW6b.get_january_data("FB", 2014) |
41 scala> M1.get_january_data("FB", 2014) |
42 val res2: List[String] = List(2014-01-02,54.709999,....) |
42 val res2: List[String] = List(2014-01-02,54.709999,....) |
43 \end{lstlisting}%$ |
43 \end{lstlisting}%$ |
44 |
44 |
45 \subsection*{Hints} |
45 \subsection*{Hints} |
46 |
46 |
47 \noindent |
47 \noindent |
48 \textbf{For the Main Part:} useful string functions: |
48 \textbf{For Main Part 1:} useful string functions: |
49 \texttt{.startsWith(...)} for checking whether a string has a given |
49 \texttt{.startsWith(...)} for checking whether a string has a given |
50 prefix, \texttt{\_ ++ \_} for concatenating two strings; useful option |
50 prefix, \texttt{\_ ++ \_} for concatenating two strings; useful option |
51 functions: \texttt{.flatten} flattens a list of options such that it |
51 functions: \texttt{.flatten} flattens a list of options such that it |
52 filters way all \texttt{None}'s, \texttt{Try(...).getOrElse ...} runs |
52 filters way all \texttt{None}'s, \texttt{Try(...).getOrElse ...} runs |
53 some code that might raise an exception---if yes, then a default value |
53 some code that might raise an exception---if yes, then a default value |
56 a list; \texttt{.filter(...)} for filtering out elements in a list; |
56 a list; \texttt{.filter(...)} for filtering out elements in a list; |
57 \texttt{.getLines.toList} for obtaining a list of lines from a file; |
57 \texttt{.getLines.toList} for obtaining a list of lines from a file; |
58 \texttt{.split(",").toList} for splitting strings according to a |
58 \texttt{.split(",").toList} for splitting strings according to a |
59 comma.\bigskip |
59 comma.\bigskip |
60 |
60 |
61 \noindent |
61 \noindent\alert |
62 \textbf{Note!} Fortunately Scala supports operator overloading. But |
62 \textbf{Note!} Fortunately Scala supports operator overloading. But |
63 make sure you understand the difference between \texttt{100 / 3} and |
63 make sure you understand the difference between \texttt{100 / 3} and |
64 \texttt{100.0 / 3}! |
64 \texttt{100.0 / 3}! |
65 |
65 |
66 \newpage |
66 \newpage |
67 \subsection*{Main Part (7 Marks, file drumb.scala)} |
67 \subsection*{Main Part 1 (7 Marks, file drumb.scala)} |
68 |
68 |
69 A purely fictional character named Mr T.~Drumb inherited in 1978 |
69 A purely fictional character named Mr T.~Drumb inherited in 1978 |
70 approximately 200 Million Dollar from his father. Mr Drumb prides |
70 approximately 200 Million Dollar from his father. Mr Drumb prides |
71 himself to be a brilliant business man because nowadays it is |
71 himself to be a brilliant business man because nowadays it is |
72 estimated he is 3 Billion Dollar worth (one is not sure, of course, |
72 estimated he is 3 Billion Dollar worth (one is not sure, of course, |
100 online. Unfortunately nowadays this kind of data is more difficult to |
100 online. Unfortunately nowadays this kind of data is more difficult to |
101 obtain, unless you are prepared to pay extortionate prices or be |
101 obtain, unless you are prepared to pay extortionate prices or be |
102 severely rate-limited. Therefore this part comes with a number |
102 severely rate-limited. Therefore this part comes with a number |
103 of files containing CSV-lists with the historical stock prices for the |
103 of files containing CSV-lists with the historical stock prices for the |
104 companies in our portfolios. Use these files for the following |
104 companies in our portfolios. Use these files for the following |
105 tasks.\bigskip |
105 tasks.\medskip |
|
106 |
|
107 \noindent\alert |
|
108 \textbf{Note:} Do not hardcode the path to the CSV-files. The testing |
|
109 framework will assume that these files are in the same directory as the |
|
110 drumb.scala file. |
|
111 \bigskip |
106 |
112 |
107 \newpage |
113 \newpage |
108 \noindent |
114 \noindent |
109 \textbf{Tasks} |
115 \textbf{Tasks} |
110 |
116 |
229 turn out to be a blue chip company. Also, since the portfolios are |
235 turn out to be a blue chip company. Also, since the portfolios are |
230 chosen from the current S\&P 500, they do not include the myriad |
236 chosen from the current S\&P 500, they do not include the myriad |
231 of companies that went bust or were de-listed over the years. |
237 of companies that went bust or were de-listed over the years. |
232 So where does this leave our fictional character Mr T.~Drumb? Well, given |
238 So where does this leave our fictional character Mr T.~Drumb? Well, given |
233 his inheritance, a really dumb investment strategy would have done |
239 his inheritance, a really dumb investment strategy would have done |
234 equally well, if not much better.\medskip |
240 equally well, if not much better. And one would assume this guy is |
|
241 by now locked up in prison and the key thrown away, but alas he |
|
242 is still around annoying commonsense people.\medskip |
235 |
243 |
236 \end{document} |
244 \end{document} |
237 |
245 |