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

Midterm Exam 2 halfsheets

parent 443df46d
No related branches found
No related tags found
No related merge requests found
.idea/ .idea/
out/ out/
_old/
\ No newline at end of file
\documentclass[11pt, landscape]{article}
\usepackage{listings}
\lstset{basicstyle=\ttfamily,tabsize=4,texcl=true,escapechar=\^,keepspaces,showstringspaces=false,commentstyle=\ttfamily}
\input{preamble}
\renewcommand{\exam}{Midterm~2}
\begin{document}
\Large
\renewcommand{\arraystretch}{2}
\begin{enumerate}
\item \input{exam2/call-graph} \newpage
\item \linespread{0.9} \input{exam2/program-state-diagram} \linespread{1} \newpage
\item \input{exam2/straightline-code-writing} \newpage
\item \input{exam2/testing} \newpage
\item \input{exam2/conditional-code-writing} \newpage
\item \input{exam2/types-and-expressions}
\end{enumerate}
\end{document}
\ No newline at end of file
\documentclass[11pt, portrait]{article}
\usepackage{listings}
\lstset{basicstyle=\ttfamily,tabsize=4,texcl=true,escapechar=\^,keepspaces,showstringspaces=false,commentstyle=\ttfamily}
\input{preamble}
\renewcommand{\exam}{Midterm~2}
\begin{document}
\renewcommand{\arraystretch}{2}
\linespread{0.9}
\begin{enumerate}
\item \input{exam2/call-graph} %\vspace{20cm}
\item \input{exam2/program-state-diagram}\newpage
\item \input{exam2/straightline-code-writing} %\vspace{20cm}
\item \input{exam2/testing} \newpage
\item \input{exam2/conditional-code-writing} \vspace{6cm}
\item \input{exam2/types-and-expressions}
\end{enumerate}
\end{document}
\ No newline at end of file
%\vbox to 0.48\textheight{
Draw the call graph for the following program.
What will the program output when run?
\begin{lstlisting}[numbers=left]
public static void bar() {
System.out.print("in bar");
}
public static void plugh() {
bar();
System.out.println("in plugh");
foo();
}
public static void foo() {
System.out.print(0);
bar();
}
public static void main(String... arguments) {
System.out.print("in main");
bar();
foo();
plugh();
}
\end{lstlisting}
%\vfill
%}
\ No newline at end of file
%\vbox to 0.48\textheight{
Complete the following Java code so that it stores the name of the nation with the most Olympic gold medals in the variable \lstinline{winner} or, if there is a tie, the name of the nation with the most Olympic silver medals.
If the two nations tie on both counts, the code should leave \lstinline{winner} unchanged.
\begin{lstlisting}
String winner = "tie";
String nationA = /* ... */, nationB = /* ... */;
int nationAGoldsWon = /* ... */, nationBGoldsWon = /* ... */;
int nationASilversWon = /* ... */, nationBSilversWon = /* ... */;
\end{lstlisting}
%\vfill
%}
\ No newline at end of file
%\vbox to 0.48\textheight{
Draw the program state diagram for the following program just before line 3 runs.
What will the program output when run?
\begin{lstlisting}[numbers=left]
public static void baz(int item, int number) {
if (number > 0) {
System.out.print(item);
} else {
System.out.print(-1);
}
}
// length() returns the number of characters in a string
public static String plugh(String name) {
int nameLength = name.length();
baz(nameLength, "Babbage".length());
return foo(name, "Babbage");
}
public static String foo(String firstName, String lastName) {
return lastName + ", " + firstName;
}
public static void main(String... arguments) {
foo("Lovelace", "Ada");
baz(3, -4);
System.out.println(plugh("Charles"));
}
\end{lstlisting}
%\vfill
%}
\ No newline at end of file
public class Statistics {
private static int getGoalsScored(Player player) { /* ... */ }
private static Roster getRoster(String team, int season) { /* ... */ }
private static String askUserForTeam() { /* ... */ }
private static Player getPlayer(Roster roster, int jersey) { /* ... */ }
private static int askUserForJersey() { /* ... */ }
public static void main(String... arguments) {
}
}
%\vbox to 0.48\textheight{
Write the main method of the following program so that, \textbf{using only the methods provided} and System.out.println,
it asks the user for a team name and two jersey numbers and then prints out the number of goals scored during the 2024 season by the two players on that team with those jersey numbers.
You do not have to worry about formatting the output nicely.
\lstinputlisting{exam2/sports.java}
%\vfill
%}
\ No newline at end of file
%\vbox to 0.48\textheight{
You are testing the following buggy function:
\begin{lstlisting}[numbers=left]
public static int maximumOfThree(int x, int y, int z) {
int maximum = x;
if (y > x && y > z) {
maximum = y;
} else if (z > x && z > y) {
maximum = z;
}
return maximum;
}
\end{lstlisting}
You are using the Category-Partition Method and have identified the following partitions:
\begin{itemize}
\item{\lstinline{x}: negative, zero, positive}
\item{\lstinline{y}: negative, zero, positive}
\item{\lstinline{z}: negative, zero, positive}
\end{itemize}
\begin{enumerate}
\item Give a test suite that achieves 1-way category coverage.
For each test case, list its three parts.
\item The method under test fails if \lstinline{x} is smallest, but \lstinline{y} and \lstinline{z} tie for largest.
Does achieving 1-way category coverage guarantee that testing will catch this bug?
Why or why not?
\item Does exhaustive category coverage guarantee that testing will catch this bug?
Why or why not?
\item Give one advantage of white-box testing over black-box testing.
\end{enumerate}
%\vfill
%}
\newcommand{\codeblank}{\vphantom{\raisebox{12pt}{Yy}}\(\underbar{\qquad\qquad\qquad\qquad}\)}
\newcommand{\shortcodeblank}{\vphantom{\raisebox{12pt}{Yy}}\(\underbar{\qquad}\)}
The rating program below processes user ratings on a scale of $-5$ to $5$.
\begin{lstlisting}[numbers=left]
public class ProductReviewer {
private static double getThreshold(String productType) { /* ... */ }
public static void main(String... arguments) {
int rating = Integer.valueOf(arguments[0]);
String productType = arguments[1];
^\codeblank^ baseline = getThreshold(productType);
^\codeblank^ recommended = rating > 0 ^\shortcodeblank^ rating ^\shortcodeblank^ baseline;
System.out.println(baseline + rating + " (logging information)");
// ...
}
}
\end{lstlisting}
\begin{enumerate}
\item Fill in the blanks so that the code would compile and consider a product to be recommended only for positive ratings that are above the threshold for their product-type.
\item Draw a plumbing diagram for the expression statement on line~9.
\item What will this program's logging code print if the user enters a rating of $-4$ when the baseline is $2$?
\end{enumerate}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment