Skip to content
Snippets Groups Projects
Verified Commit bff7c73c authored by Christopher Bohn's avatar Christopher Bohn :thinking:
Browse files

Final Exam halfsheets

parent 130ad117
Branches
No related tags found
No related merge requests found
\documentclass[11pt, portrait]{article}
\usepackage{multicol}
\usepackage{listings}
\usepackage{layout}
\lstset{basicstyle=\ttfamily,tabsize=4,texcl=true,escapechar=\^,keepspaces,showstringspaces=false,commentstyle=\ttfamily}
\input{preamble}
\renewcommand{\exam}{Final~exam}
\begin{document}
% \renewcommand{\arraystretch}{2}
\Large
\begin{enumerate}
\item \setlength{\hoffset}{-0.5cm} \input{final-exam/program-state-diagram} \newpage
\item \setlength{\hoffset}{0cm} \input{final-exam/code-reading} \newpage
\item \setlength{\hoffset}{-1cm} \input{final-exam/class-diagram} \newpage
\item \setlength{\hoffset}{0cm} \input{final-exam/testing} \newpage
\item \input{final-exam/object-orientation} \newpage
\item \input{final-exam/loop-code-writing} \newpage
\item \input{final-exam/design-an-algorithm_3-grades} \newpage
\item \input{final-exam/unit-testing} \newpage
\item \input{final-exam/control-flow-graph}
\end{enumerate}
\end{document}
\ No newline at end of file
\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} \vspace{1cm}
\item \input{final-exam/code-reading} \newpage
\item \input{final-exam/class-diagram} %\vspace{1cm}
\item \input{final-exam/testing} \newpage
\item \input{final-exam/object-orientation} \vspace{4cm}
\item \input{final-exam/loop-code-writing} \newpage
\item \input{final-exam/design-an-algorithm_3-grades} \vspace{4cm}
\item \input{final-exam/unit-testing} \newpage
\item \input{final-exam/control-flow-graph}
\end{enumerate}
\end{document}
\ No newline at end of file
Consider the following class:
\begin{quote}
\begin{lstlisting}
public class Pay {
private double hours, amount;
public Pay(double hours, double amount) {
this.hours = hours;
this.amount = amount;
}
public double getHourlyRate() {
return amount / hours;
}
public boolean isOvertime() {
return hours > 40;
}
public String toString() {
String result = "$" + getHourlyRate() + " per hour";
if (isOvertime()) {
return result + " (overtime)";
}
return result;
}
}
\end{lstlisting}
\end{quote}
Draw a class diagram for \lstinline{Pay}.
Evaluate the code below to determine the value of \lstinline{myPay}:
\begin{quote}
\begin{lstlisting}
String myPay = new Pay(10.0,5.0).toString();
\end{lstlisting}
\end{quote}
\ No newline at end of file
Consider the following class:
\begin{quote}
\begin{lstlisting}
public class Point {
private int x, y;
public Point(int x, int y) {
this.x = x;
this.y = y;
}
public Point translate(int dx, int dy) {
this.x += dx;
this.y += dy;
return this;
}
public Point mystery() {
return translate(-2 * x, -2 * y);
}
public String toString() {
return "(" + x + ", " + y + ")";
}
}
\end{lstlisting}
\end{quote}
Determine what would be printed by the following statement
\begin{quote}
\begin{lstlisting}
System.out.println(new Point(4, 6).mystery());
\end{lstlisting}
\end{quote}
\ No newline at end of file
Draw a control-flow graph for the code listed below.
\begin{quote}
\begin{lstlisting}[numbers=left]
int[] data = new int[] { 2, 11, 18, 4 };
int size = data.length;
int[] moreData = new int[size];
for (int i = 0; i < size; ++i) {
if (i > 0) {
moreData[i] = data[i - 1];
} else {
moreData[i] = data[i] - 1;
}
}
for (int i = size - 1; i >= 0; --i) {
System.out.println(moreData[i]);
}
\end{lstlisting}
\end{quote}
Write the values printed by this code in the order they are printed.
\ No newline at end of file
Suppose you are designing an algorithm to find the best grade among
three exam grades given as integer percentages.
\begin{enumerate}
\item Give a detailed restatement of the problem as an outline of subproblems (you do not need to include the subproblem of getting the three grades as inputs).
\item Give a solution to the problem as a sequence of steps.
\item Show, with arrows, the mapping from subproblems to the parts of your solution that solve those subproblems.
\end{enumerate}
Suppose the function \lstinline{hasCross} takes two arguments, an \(x\)~coordinate and a \(y\)~coordinate, and returns \lstinline{true} if that position on a certain tic-tac-toe board is occupied by an `X', \lstinline{false} otherwise.
Similarly, the function \lstinline{hasNaught} takes two coordinates and returns \lstinline{true} if the position is occupied by an `O'.
Tic-tac-toe boards are usually \(3\times 3\), so both coordinates range from 0 to~2.
Write code to set the variable \lstinline{empty} to \lstinline{true} if the entire board is blank (no square is occupied by either symbol), but to \lstinline{false} otherwise.
\ No newline at end of file
Given the following class diagram, write the class in Java:
%\illustration{0}
\begin{center}
\begin{tabular}{|c@{}l|}
\hline
\multicolumn{2}{|c|}{Course} \\ \hline
+ & title : String \\
- & corequisites : List$\langle$Course$\rangle$ \\
- & prerequisites : List$\langle$Course$\rangle$ \\ \hline
\end{tabular}
\end{center}
Add the code for a constructor that takes one argument, \lstinline{title}.
The constructor should also set \lstinline{corequisites} to a new, empty \lstinline{ArrayList} and \lstinline{prerequisites} to a new, empty \lstinline{ArrayList}.
You do not need to write getters and setters.
\vspace{1cm}
Write a line of Java code to create a course titled \lstinline{"Software Engineering I"} and store that course in a newly declared variable named \lstinline{soft160}.
Draw a program state diagram (showing all contexts) for the
program state just after line 9 executes. What is the output of the program?
\begin{quote}
\begin{lstlisting}[numbers=left]
private static boolean fie(int fum) {
for (int i=0; i<2; ++i){
fum++;
}
if (fum > 3) {return true;}
return false;
}
private static int baz(int fum) {
boolean result = fie(fum+1);
if (result) {return fum;}
return -fum;
}
public static void main(String... arguments) {
int fum = baz(1);
System.out.println(fum + " " + (0 < fum && fum < 5));
}
\end{lstlisting}
\end{quote}
\ No newline at end of file
Consider category-partition testing of a method.
\begin{enumerate}
\item What artifacts would a software engineer consult to design such tests?
\item What artifacts would be analyzed by running such tests?
\item What metrics would be measured by running such tests?
\item Which of the following quality dimensions from the list below would each of those metrics speak to?
\begin{quote}
\begin{multicols}{2}
\begin{itemize}
\item{Functional correctness}
\item{Code complexity}
\item{Readability}
\item{Testability}
\item{Testedness}
\item{Scalability}
\item{Compatibility}
\item{Portability}
\item{Usability}
\end{itemize}
\end{multicols}
\end{quote}
\item How do your answers change if coverage information is collected while testing?
\item Is category-partition testing a white-box or black-box testing technique?
Justify your response.
\end{enumerate}
You are using the category-partition method to unit test a method \lstinline{countWords} with the parameter \lstinline{identifier} of type \lstinline{String}.
The \lstinline{countWords} method has the following specification:
\begin{quote}
The \lstinline{countWords} method shall take a camel-case string called \lstinline{identifier} and return the number of nonempty pieces \lstinline{identifier} would be divided into if it were broken just before every capital letter~(\lstinline{A}--\lstinline{Z}).
For example, if
\lstinline{identifier} were the string \lstinline{"AlphaBCharlie"}, \lstinline{countWords} would return~\lstinline{3} because the string would break into three words:
\lstinline{"Alpha"}, \lstinline{"B"}, and \lstinline{"Charlie"}.
\end{quote}
\begin{quote}
\begin{itemize}
\item{\lstinline{identifier}'s length:}
\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 Write a set of test frames that achieve 1-way coverage of your partitions.
\item Using your partitions from above and the following JUnit test template, create a JUnit test that matches the test name.
\begin{lstlisting}
@Test
public void countWords() {
int result = Editor.countWords(^\codeblank^);
assertEquals(^\codeblank^, result);
}
\end{lstlisting}
\end{enumerate}
...@@ -40,6 +40,9 @@ ...@@ -40,6 +40,9 @@
\newcommand{\Let}[2]{\KwLet{#1\({\null}\leftarrow{\null}\)#2}\;} \newcommand{\Let}[2]{\KwLet{#1\({\null}\leftarrow{\null}\)#2}\;}
\SetKwFor{Function}{function}{}{end} \SetKwFor{Function}{function}{}{end}
% fill-in-the-blanks in code
\newcommand{\codeblank}{\ensuremath{\underbar{\vphantom{\raisebox{12pt}{Yy}}\qquad\qquad\qquad\qquad}}}
% graphics % graphics
\usepackage{graphicx} \usepackage{graphicx}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment