From 530e766a4dde036d980dddb70f35f0d80e1df3b5 Mon Sep 17 00:00:00 2001
From: Christopher Bohn <bohn@unl.edu>
Date: Thu, 5 Dec 2024 10:08:47 -0600
Subject: [PATCH] Final Exam halfsheets answer key (mostly done)

---
 final-exam-halfsheet-answers.tex              | 22 ++++++++
 final-exam/class-diagram_key.tex              | 29 +++++++++++
 final-exam/code-reading_key.tex               | 27 ++++++++++
 final-exam/control-flow-graph_key.tex         | 12 +++++
 .../design-an-algorithm_3-grades_key.tex      |  5 ++
 final-exam/loop-code-writing_key.tex          | 28 ++++++++++
 final-exam/object-orientation.tex             |  1 -
 final-exam/object-orientation_key.tex         | 28 ++++++++++
 final-exam/program-state-diagram.tex          |  4 +-
 final-exam/program-state-diagram_key.tex      | 12 +++++
 final-exam/testing_key.tex                    | 21 ++++++++
 final-exam/unit-testing.tex                   |  6 +--
 final-exam/unit-testing_key.tex               | 52 +++++++++++++++++++
 preamble.tex                                  |  4 +-
 14 files changed, 244 insertions(+), 7 deletions(-)
 create mode 100644 final-exam-halfsheet-answers.tex
 create mode 100644 final-exam/class-diagram_key.tex
 create mode 100644 final-exam/code-reading_key.tex
 create mode 100644 final-exam/control-flow-graph_key.tex
 create mode 100644 final-exam/design-an-algorithm_3-grades_key.tex
 create mode 100644 final-exam/loop-code-writing_key.tex
 create mode 100644 final-exam/object-orientation_key.tex
 create mode 100644 final-exam/program-state-diagram_key.tex
 create mode 100644 final-exam/testing_key.tex
 create mode 100644 final-exam/unit-testing_key.tex

diff --git a/final-exam-halfsheet-answers.tex b/final-exam-halfsheet-answers.tex
new file mode 100644
index 0000000..93599ad
--- /dev/null
+++ b/final-exam-halfsheet-answers.tex
@@ -0,0 +1,22 @@
+\documentclass[11pt, portrait]{article}
+\usepackage{multicol}
+\usepackage{listings}
+\lstset{basicstyle=\ttfamily,tabsize=4,texcl=true,escapechar=\^,keepspaces,showstringspaces=false,commentstyle=\ttfamily}
+\input{preamble}
+\renewcommand{\exam}{Final~Exam}
+
+\begin{document}
+%    \renewcommand{\arraystretch}{2}
+    \linespread{0.9}
+    \begin{enumerate}
+        \item \input{final-exam/program-state-diagram} \input{final-exam/program-state-diagram_key} \newpage
+        \item \input{final-exam/code-reading} \input{final-exam/code-reading_key} \newpage
+        \item \input{final-exam/class-diagram} \input{final-exam/class-diagram_key} \newpage
+        \item \input{final-exam/testing} \input{final-exam/testing_key} \newpage
+        \item \input{final-exam/object-orientation} \input{final-exam/object-orientation_key} \newpage
+        \item \input{final-exam/loop-code-writing} \input{final-exam/loop-code-writing_key} \newpage
+        \item \input{final-exam/design-an-algorithm_3-grades} \input{final-exam/design-an-algorithm_3-grades_key} \newpage
+        \item \input{final-exam/unit-testing} \newpage \input{final-exam/unit-testing_key} \newpage
+        \item \input{final-exam/control-flow-graph} \input{final-exam/control-flow-graph_key}
+    \end{enumerate}
+\end{document}
\ No newline at end of file
diff --git a/final-exam/class-diagram_key.tex b/final-exam/class-diagram_key.tex
new file mode 100644
index 0000000..3f26621
--- /dev/null
+++ b/final-exam/class-diagram_key.tex
@@ -0,0 +1,29 @@
+\begin{key}
+    We briefly went over how to diagram the methods, so students might include them in the diagram.
+    Make sure the public/private modifiers are correct and the format is correct.
+    It is helpful to keep the fields and methods in the same order as they appear in the code.
+
+    \begin{center}
+        \begin{tabular}{|c@{}l|}
+            \hline
+            \multicolumn{2}{|c|}{Pay}   \\ \hline
+            - & hours : double          \\
+            - & amount : double         \\ \hline
+        \end{tabular}
+    \end{center}
+    or
+    \begin{center}
+        \begin{tabular}{|c@{}l|}
+            \hline
+            \multicolumn{2}{|c|}{Pay}                       \\ \hline
+            - & hours : double                              \\
+            - & amount : double                             \\ \hline
+            + & Pay(hours: double, amount: double) : Pay    \\
+            + & getHourlyRate() : double                    \\
+            + & isOvertime() : boolean                      \\
+            + & toString() : String                         \\ \hline
+        \end{tabular}
+    \end{center}
+
+    ``\lstinline{$0.5 per hour}'' is printed.
+\end{key}
\ No newline at end of file
diff --git a/final-exam/code-reading_key.tex b/final-exam/code-reading_key.tex
new file mode 100644
index 0000000..e5097fc
--- /dev/null
+++ b/final-exam/code-reading_key.tex
@@ -0,0 +1,27 @@
+\begin{key}
+    \begin{enumerate}
+        \item{A new \lstinline{Point} is created.}
+        \item{The constructor is called with \lstinline{this} set to the new object
+        and the arguments \lstinline{4} and \lstinline{6}.}
+        \item{The constructor sets the object's fields to \lstinline{4} and
+        \lstinline{6}.}
+        \item{The constructor returns.}
+        \item{The \lstinline{mystery} method is called with \lstinline{this} set to
+        the object.}
+        \item{The \lstinline{mystery} method computes \lstinline{-2 * x}, which is
+        \lstinline{-8}, and \lstinline{-2 * y}, which is \lstinline{-12}.}
+        \item{The \lstinline{translate} method is called with \lstinline{this} set to
+        the object and the arguments \lstinline{-8} and \lstinline{-12}.}
+        \item{The \lstinline{translate} method changes the object's fields to
+        \lstinline{-4} and \lstinline{-6}.}
+        \item{The \lstinline{translate} method returns the object.}
+        \item{The \lstinline{mystery} method returns the object.}
+        \item{The \lstinline{println} method is called with \lstinline{this} set to
+        \lstinline{System.out} and the argument being the object.}
+        \item{The object is formatted as a string by calling its \lstinline{toString}
+        method with \lstinline{this} set to the object.}
+        \item{The \lstinline{toString} computes and returns the string
+        ``\lstinline{(-4, -6)}''.}
+        \item{``\lstinline{(-4, -6)}'' is printed.}
+    \end{enumerate}
+\end{key}
\ No newline at end of file
diff --git a/final-exam/control-flow-graph_key.tex b/final-exam/control-flow-graph_key.tex
new file mode 100644
index 0000000..6cb0941
--- /dev/null
+++ b/final-exam/control-flow-graph_key.tex
@@ -0,0 +1,12 @@
+\textcolor{red}{TODO: do the first part}
+\begin{key}
+    \dots
+\end{key}
+\begin{key}
+    \begin{itemize}
+        \item{\lstinline{18} (being \lstinline{moreData[3]}, which was set to \lstinline{data[2]})}
+        \item{\lstinline{11} (being \lstinline{moreData[2]}, which was set to \lstinline{data[1]})}
+        \item{\lstinline{2} (being \lstinline{moreData[1]}, which was set to \lstinline{data[0]})}
+        \item{\lstinline{1} (being \lstinline{moreData[0]}, which was set to \lstinline{data[0] - 1})}
+    \end{itemize}
+\end{key}
\ No newline at end of file
diff --git a/final-exam/design-an-algorithm_3-grades_key.tex b/final-exam/design-an-algorithm_3-grades_key.tex
new file mode 100644
index 0000000..446d0b6
--- /dev/null
+++ b/final-exam/design-an-algorithm_3-grades_key.tex
@@ -0,0 +1,5 @@
+\textcolor{red}{TODO: do}
+
+\begin{key}
+    \dots
+\end{key}
\ No newline at end of file
diff --git a/final-exam/loop-code-writing_key.tex b/final-exam/loop-code-writing_key.tex
new file mode 100644
index 0000000..284feb7
--- /dev/null
+++ b/final-exam/loop-code-writing_key.tex
@@ -0,0 +1,28 @@
+\begin{key}
+    \begin{description}
+        \item[Base case] A board with no squares is vacuously has no occupied squares (effectively assumes that the entire board is blank until proven otherwise)
+        \item[Initiation, outer loop] \lstinline{x = 0} (start in the 0th column)
+        \item[Consecution, outer loop] \lstinline{x++} (advance to the next column)
+        \item[Termination, inner loop] \lstinline{x < 2} (terminate after we've passed the 2nd column)
+        \item[Action, outer loop] Evaluate each square in the $x$th column
+        \item[Initiation, inner loop] \lstinline{y = 0} (start in square $(x, 0)$)
+        \item[Consecution, outer loop] \lstinline{y++} (advance to the next square in the $x$th column)
+        \item[Termination, inner loop] \lstinline{y < 2} (terminate after we've passed the 2nd row in the $x$th column)
+        \item[Action, inner loop] if square $(x,y)$ has an `X' or a `Y' then we have a counterexample to the assumption that the board is blank
+    \end{description}
+
+
+    \begin{lstlisting}
+boolean empty = true;
+for (int x = 0; x < 2; x++) {
+  for (int y = 0; y < 2; y++) {
+    if (hasCross(x, y) || hasNaught(x, y)) {
+      empty = false;
+    }
+  }
+}
+    \end{lstlisting}
+
+    (Student \textit{must} design their solutions, but they should avoid overengineering their solutions.
+    There is, for instance, no need to count the empty or filled cells.)
+\end{key}
\ No newline at end of file
diff --git a/final-exam/object-orientation.tex b/final-exam/object-orientation.tex
index 251034e..aa53b3d 100644
--- a/final-exam/object-orientation.tex
+++ b/final-exam/object-orientation.tex
@@ -1,6 +1,5 @@
 Given the following class diagram, write the class in Java:
 
-%\illustration{0}
     \begin{center}
         \begin{tabular}{|c@{}l|}
             \hline
diff --git a/final-exam/object-orientation_key.tex b/final-exam/object-orientation_key.tex
new file mode 100644
index 0000000..c07a3e5
--- /dev/null
+++ b/final-exam/object-orientation_key.tex
@@ -0,0 +1,28 @@
+\begin{key}
+    \begin{lstlisting}
+public class Course {
+  public String title;
+  private List<Course> corequisites;
+  private List<Course> prerequisites;
+
+  public Course(String title) {
+    this.title = title;
+    corequisites = new ArrayList<Course>();
+    prerequisites = new ArrayList<Course>();
+  }
+}
+    \end{lstlisting}
+    Notes:
+    \begin{itemize}
+        \item{Per convention, the name of the constructor's parameter matches the name of the field, and we distinguish the two via the \lstinline{this} keyword.}
+        \item{We do not write \lstinline{this.corequisites} or \lstinline{this.prerequisites}, as the convention in Java is to omit \lstinline{this} when it is unnecessary.}
+        \item{We cannot say just \lstinline{new List<Course>()} because we must choose which kind of list \lstinline{corequisites} and \lstinline{prerequisites} are.
+            We \textit{could}, however, say just \lstinline{new ArrayList<>()} because Java can infer the ``\lstinline{<Course>}'' from the declared type.}
+    \end{itemize}
+
+    \vspace{1cm}
+
+    \begin{lstlisting}
+Course soft160 = new Course("Software Engineering I");
+    \end{lstlisting}
+\end{key}
\ No newline at end of file
diff --git a/final-exam/program-state-diagram.tex b/final-exam/program-state-diagram.tex
index 202ddbe..28b4813 100644
--- a/final-exam/program-state-diagram.tex
+++ b/final-exam/program-state-diagram.tex
@@ -1,5 +1,5 @@
-Draw a program state diagram (showing all contexts) for the
-program state just after line 9 executes. What is the output of the program?
+Draw a program state diagram (showing all contexts) for the program state just after the second time that line 3 executes.
+What is the output of the program?
 
 \begin{quote}
     \begin{lstlisting}[numbers=left]
diff --git a/final-exam/program-state-diagram_key.tex b/final-exam/program-state-diagram_key.tex
new file mode 100644
index 0000000..72445cc
--- /dev/null
+++ b/final-exam/program-state-diagram_key.tex
@@ -0,0 +1,12 @@
+\begin{key}
+
+    \begin{tabular}[h]{clclcl}
+        \textbf{main}                   & \hspace{3cm}                                      & \textbf{baz}                  & \hspace{3cm}                                      & \textbf{fie}              &                   \\ \cline{1-1}\cline{3-3}\cline{5-5}
+        \multicolumn{1}{|l|}{arguments} & $\rightarrow$ \textlangle unknown\textrangle      & \multicolumn{1}{|l|}{fum}     & $\rightarrow$ 1                                   & \multicolumn{1}{|l|}{fum} & $\rightarrow$ 4   \\
+        \multicolumn{1}{|l|}{fum}       & $\rightarrow$ \textlangle undefined\textrangle    & \multicolumn{1}{|l|}{result}  & $\rightarrow$ \textlangle undefined\textrangle    & \multicolumn{1}{|l|}{i}   & $\rightarrow$ 1   \\ \cline{1-1}\cline{3-3}\cline{5-5}
+    \end{tabular}
+
+    \vspace{1cm}
+
+    The program outputs ``1 true''
+\end{key}
\ No newline at end of file
diff --git a/final-exam/testing_key.tex b/final-exam/testing_key.tex
new file mode 100644
index 0000000..1ebaf17
--- /dev/null
+++ b/final-exam/testing_key.tex
@@ -0,0 +1,21 @@
+\begin{key}
+    \begin{enumerate}
+        \item A software engineer would need to consult (a)~either the specification or the
+        design documents (to determine the requirements on the method) and (b)~either
+        the design documents or the code (to determine the method's signature).
+        \item When run, the tests would analyze (a)~the code, specifically the method under
+        test and any of its callees, but also, implicitly, (b)~the unit tests being
+        run (because their correctness also affects the test results).
+        \item Metrics collected would include (a)~the number of tests run, (b)~the number of
+        tests that passed, and (c) the test pass rate (the ratio of (a) and (b)).
+        \item The number of tests run would speak to testedness, and may also give some
+        sense of testability.  The number of tests passing and the test pass rate
+        would speak to functional correctness.
+        \item If coverage were collected, an additional metric, code coverage, would be
+        measured.  It would provide information about testedness and, implicitly,
+        testability.
+        \item Category-partition testing is a black-box testing technique because it does
+        not use the code (in particular, the structure of the code) to create the
+        test cases (it uses the specification but it also use the method signature).
+    \end{enumerate}
+\end{key}
\ No newline at end of file
diff --git a/final-exam/unit-testing.tex b/final-exam/unit-testing.tex
index 131c487..da34f2f 100644
--- a/final-exam/unit-testing.tex
+++ b/final-exam/unit-testing.tex
@@ -14,14 +14,14 @@ The \lstinline{countWords} method has the following specification:
         \item{number of words in \lstinline{identifier}:}
         \item{\lstinline{identifier} starts with a capital letter:}
         \item{\lstinline{identifier} contains a one-letter word:}
-        \item{return value:}
     \end{itemize}
 \end{quote}
 
 \begin{enumerate}
-    \item Given the specification above, identify a partition for each category and the return value.
-    \item Identify a representative value for each choice.
+    \item Given the specification above, identify a partition for each category.
     \item Write a set of test frames that achieve 1-way coverage of your partitions.
+    \item Identify a representative value for each choice.
+    \item Use those representative values to convert your test frames into test cases.
     \item Using your partitions from above and the following JUnit test template, create a JUnit test that matches the test name.
 
         \begin{lstlisting}
diff --git a/final-exam/unit-testing_key.tex b/final-exam/unit-testing_key.tex
new file mode 100644
index 0000000..b8e0266
--- /dev/null
+++ b/final-exam/unit-testing_key.tex
@@ -0,0 +1,52 @@
+\begin{key}
+    \begin{enumerate}
+        \item
+        \begin{itemize}
+            \item{\lstinline{identifier}'s length: 0, 1, more than 1}
+            \item{number of words in \lstinline{identifier}: 0, 1, more than 1}
+            \item{\lstinline{identifier} starts with a capital letter: true, false}
+            \item{\lstinline{identifier} contains a one-letter word: true, false}
+        \end{itemize}
+        \vspace{1cm}
+        \item
+        \hbox{}
+        \centerline{%
+            \begin{tabular}{ccccc}
+                Code Under Test         & length        & number of words   & starts with capital letter    & contains a 1-letter word  \\ \hline
+                \lstinline{countWords}  & 0             & 0                 &                               &                           \\
+                \lstinline{countWords}  & 1             & 1                 & true                          & true                      \\
+                \lstinline{countWords}  & more than 1   & more than 1       & false                         & false                     \\
+            \end{tabular}%
+        }
+        \hbox{}
+        \vspace{1cm}
+        \item
+        \begin{itemize}
+            \item{\lstinline{identifier}'s length: 0, 1, 2}
+            \item{number of words in \lstinline{identifier}: 0, 1, 2}
+            \item{\lstinline{identifier} starts with a capital letter: true, false}
+            \item{\lstinline{identifier} contains a one-letter word: true, false}
+        \end{itemize}
+        \vspace{1cm}
+        \item
+        \hbox{}
+        \centerline{%
+            \begin{tabular}{ccc}
+                Code Under Test         & Argument(s)                       & Return Value  \\ \hline
+                \lstinline{countWords}  & \lstinline{identifier:""}         & \lstinline{0} \\
+                \lstinline{countWords}  & \lstinline{identifier: "A"}       & \lstinline{1} \\
+                \lstinline{countWords}  & \lstinline{identifier: "theDog"}  & \lstinline{2} \\
+            \end{tabular}%
+        }
+        \hbox{}
+        \vspace{1cm}
+        \item
+        \begin{lstlisting}
+@Test
+public void countWords() {
+  int result = Editor.countWords("A");
+  assertEquals(1, result);
+}
+        \end{lstlisting}
+    \end{enumerate}
+\end{key}
\ No newline at end of file
diff --git a/preamble.tex b/preamble.tex
index 0cf9436..997139c 100644
--- a/preamble.tex
+++ b/preamble.tex
@@ -1,4 +1,6 @@
 \usepackage{fullpage}
+\usepackage{xcolor}
+\usepackage{tikz}
 
 % headers and footers
 \usepackage{fancyhdr}
@@ -58,7 +60,7 @@
 \makeatother % end block to replace
 \newenvironment{qq}{\parskip=-6pt\relax\begin{quote}\leavevmode\llap{\
     refstepcounter{qq}{\textbf{\alph{qq}.\ }}}\ignorespaces}{\end{quote}}
-\newenvironment{key}{\begin{quote}\textcolor{blue}\bgroup\ignorespaces}{\egroup\end{quote}}
+\newenvironment{key}{\begin{quote} \textcolor{blue} \bgroup \ignorespaces}{\egroup \end{quote}}
 %%%%% %%%%% %%%%%
 % \usepackage[algo2e,lined,nofillcomment]{../common/libraries/tex/algorithm2e}
 % \dontprintsemicolon
-- 
GitLab