\documentclass[12pt,twoside]{article}
\usepackage[parfill]{parskip}  
\usepackage{graphicx}
\usepackage{amssymb}
\usepackage{amsmath}
\usepackage{epstopdf}
\usepackage{underscore}
\usepackage{caption}
\DeclareGraphicsRule{.tif}{png}{.png}{`convert #1 `dirname #1`/`basename #1 .tif`.png}
\usepackage{fourier}
\usepackage{listings}
\lstset{
	language=java,
	tabsize=4,
	frame=trbl,
	columns=fullflexible,
	escapechar=\#,
	basicstyle=\sffamily,
	stringstyle=\textit,
	showstringspaces=false}
\usepackage{pdfpages}
%\usepackage{pdfsync}
% from use-full-height.tex
\setlength{\textheight}{9.5in}
\setlength{\headheight}{.60in}
\setlength{\headsep}{.40in}
\setlength{\topmargin}{-1.5in}

% from use-full-width.tex
\setlength{\textwidth}{6.5in} 
\setlength{\oddsidemargin}{0in}
\setlength{\evensidemargin}{0in}

% crowd figures and text on pages to reduce page count
\renewcommand\floatpagefraction{.9}
\renewcommand\topfraction{.9}
\renewcommand\bottomfraction{.9}
\renewcommand\textfraction{.1}   
\setcounter{totalnumber}{50}
\setcounter{topnumber}{50}
\setcounter{bottomnumber}{50}

% use san-serif for code
\renewcommand{\ttdefault}{\sfdefault}

% ----------------------------------------------------------------
% Question formatting macros
% ----------------------------------------------------------------
\newcommand{\fillInBlank}[1][0.5in]{\underline{\hspace{#1}}}
\newcommand*{\fixme}[1]{\textsc{To be fixed:} \emph{{#1}}}

% #1 answer: T, F, or none to hide
% #2 question text
\newcommand*{\truefalse}[2][none]{\hspace{0.25in}%
\ifthenelse{\equal{#1}{none}}{T\hspace{0.15in}F}{%
	\ifthenelse{\equal{#1}{T}}{T\hspace{0.25in}}{%
		\hspace{0.25in}F}}%
\hspace{0.15in}{#2}}

\newcommand*{\bigoh}[1]{\ensuremath{\mathrm{O}({#1})}}

\newcommand*{\littleoh}[1]{\ensuremath{\mathrm{o}({#1})}}

\newcommand*{\bigtheta}[1]{\ensuremath{\Theta({#1})}}
% ----------------------------------------------------------------

\renewcommand{\labelenumi}{\alph{enumi}.}

\newcommand{\code}[1]{\texttt{#1}}

\frenchspacing

\begin{document}
%\maketitle

\begin{flushright}
Name: \fillInBlank[3in] Section: \fillInBlank[1in]

\LARGE{CSSE 220---Object-Oriented Software Development}

\Large{Exam 1 -- Part 1, Mar. 26, 2014}
\end{flushright}

This exam consists of two parts.  Part 1 is to be solved on these pages. If you need more space, please ask your instructor for blank paper.  After you finish Part 1, please turn in your Part 1 answers. If you would like to remain for the programming portion review in the second half of class, please quietly at your desk while the rest of the students complete the exam.

Any communication with anyone other than the instructor or a TA during the exam, \emph{may result in a failing grade for the course.}

\emph{Allowed Resources on Part 1}:  You are allowed one 8.5 by 11 sheet of paper with notes of your choice.  This section is \emph{not} open book, open notes, and you are not allowed to use your computer for this part.  

\emph{Part 1 is included in this document}.  

\begin{center}
\textbf{You will be given 50 minutes (the first half of class) to complete Part 1.}
\end{center}

Please, begin by writing your name on every page of the exam. We encourage you to skim the
entire exam before answering any questions. \emph{Use of your computer on Part 1 of the exam will be considered academic dishonesty.}


\vfill

\begin{flushright}
\begin{tabular}{rcc}
\textbf{Problem} & \textbf{Poss. Pts.} & \textbf{Earned} \\
1 & 9 & \fillInBlank \\
2 & 8 & \fillInBlank \\
3 & 12 & \fillInBlank \\
4 & 6 & \fillInBlank \\
\textbf{Paper Part Subtotal} & \textbf{35} & \fillInBlank\\
 & & \\
\textbf{Computer Part Subtotal} & \textbf{65} & \fillInBlank\\
 & & \\
\textbf{Total} & \textbf{100} & \fillInBlank
\end{tabular}
\end{flushright}
\clearpage

{\Large Part 1---Paper Part}

\begin{center}
\begin{minipage}[t]{0.9\linewidth}
\begin{lstlisting}
public class RightTriangle {

	private double height;
	private double width;
	
	public RightTriangle() {
		this.height = 1.0;
		this.width = 1.0;
	}
	
	public RightTriangle(double height, double width) {
		this.height = height;
		this.width = width;
	}
	
	public RightTriangle getScaledTriangle(double scale) {
		double newHeight = height * scale;
		double newWidth = width * scale;
		
		return new RightTriangle(newHeight, newWidth);
	}
	
	public String toString() {
		double aSquared = this.height * this.height;
		double bSquared = this.width * this.width;
		double c = Math.sqrt(aSquared + bSquared);
		return String.format("A = %.2f, B = %.2f, C = %.2f", 
			this.height, this.width, c);
	}
}
\end{lstlisting}
\end{minipage}
\end{center}
\clearpage

The next several questions all refer to a \code{RightTriangle} class.  On the previous page is a listing of this class showing its fields, constructors, and methods.  The javadocs are omitted to save space. \textsc{Do not type this class in Eclipse}.

1. (9 points) Below are several code snippets that use the \code{RightTriangle} class.  For each snippet, first 
\emph{draw a box-and-pointer diagram} showing the result of executing it.  Then \emph{give the output} of the print statement at the end of the snippet. \textsc{Do not type the code snippets for this question in Eclipse}.

\begin{minipage}[t]{0.55\linewidth}
\begin{lstlisting}
RightTriangle newTriangle = new RightTriangle();
System.out.println(newTriangle.toString());
\end{lstlisting}
\end{minipage}
\hspace{0.25in}
\begin{minipage}[t]{0.3\linewidth}
\vspace{0.05in}
(a) Diagram: 
\end{minipage}

\vfill
Output: 
\vspace{0.015in}
\hrule
\begin{minipage}[t]{0.55\linewidth}
\begin{lstlisting}
RightTriangle rt1 = new RightTriangle(1.0, 2.0);
RightTriangle rt2 = rt1;
rt1 = rt2.getScaledTriangle(3.0);
System.out.println(rt1.toString());
\end{lstlisting}
\end{minipage}
\hspace{0.25in}
\begin{minipage}[t]{0.3\linewidth}
\vspace{0.05in}
(b) Diagram:
\end{minipage}

\vfill
Output: 
\vspace{0.015in}
\hrule
\vspace{0.02in}
\begin{minipage}[t]{0.58\linewidth}
\begin{lstlisting}
RightTriangle[] rts = new RightTriangle[4];
RightTriangle rt1 = new RightTriangle(3.0, 4.0);
for (int i=0;i < rts.length;i++) {
	rts[i] = rt1;
}
rts[1].getScaledTriangle(2.0);
System.out.println(rts[1].toString());
\end{lstlisting}
\end{minipage}
\hspace{0.25in}
\begin{minipage}[t]{0.3\linewidth}
\vspace{0.05in}
(c) Diagram:
\end{minipage}
\vfill

Output: 
\vspace{0.015in}
\hrule
\clearpage

2. (8 points) Predict the output for each code snippet below. (You do \emph{not} need to draw a diagram, but you may if it might help you.) You may assume that all necessary imports have been made for each section. \textsc{Do not type the code snippets for this question in Eclipse}.
\vspace{0.25in}

\hfill
\begin{minipage}{0.60\linewidth}
\begin{lstlisting}
int degCelsius = 37;
System.out.println((degCelsius  * 9 ) / 5 + 32);
\end{lstlisting}
\end{minipage}
\hspace{0.25in}
(a) Output: \fillInBlank[1in]

\vfill
\hfill
\begin{minipage}{0.60\linewidth}
\begin{lstlisting}
String[] lunchSides = new String[7];
lunchSides[1] = "Fries";
lunchSides[2] = "Tater Tots";
lunchSides[3] = "Waffle Fries";
lunchSides[4] = "Onion Rings";
lunchSides[5] = "Curly Fries";
System.out.println(lunchSides[lunchSides.length-5]);
\end{lstlisting}
\end{minipage}
\hspace{0.25in}
(b) Output: \fillInBlank[1in]

\vfill
\hfill
\begin{minipage}{0.60\linewidth}
\begin{lstlisting}
double e = 2.7182818284;
int num = 5;
System.out.printf("%d ABC %.4f", num, e);
\end{lstlisting}
\end{minipage}
\hspace{0.25in}
(c) Output: \fillInBlank[1in]

\vfill

\hfill
\begin{minipage}{0.60\linewidth}
\begin{lstlisting}
ArrayList<Integer> list = new ArrayList<Integer>();
list.add(1);
list.add(2);
list.add(3);
list.add(1, 4);
System.out.printf("%d, %d, %d, %d", 
	list.get(0), list.get(1), list.get(2), list.get(3));
\end{lstlisting}
\end{minipage}
\hspace{0.25in}
(d) Output: \fillInBlank[1in]
\vfill


\clearpage
3. (12 points) For each loop below, write down how many times its body will execute, or indicate that we can't tell from the information given. \textsc{Do not type the code snippets for this question in Eclipse}.

\hfill
\begin{minipage}{0.58\linewidth}
\begin{lstlisting}
int maxFrequency = 12;
for (int i = 0; i <= maxFrequency; i++) {
	// loop body excluded
}
\end{lstlisting}
\end{minipage}
\hspace{0.25in}
\begin{minipage}[t]{0.25\linewidth}
(a) Answer: \fillInBlank
\end{minipage}
\vfill

\hfill
\begin{minipage}{0.58\linewidth}
\begin{lstlisting}
int sum = 1;
while (sum < 24) {
	sum = sum*2;
}
\end{lstlisting}
\end{minipage}
\hspace{0.25in}
\begin{minipage}[t]{0.25\linewidth}
(b) Answer: \fillInBlank
\end{minipage}
\vfill

\hfill
\begin{minipage}{0.58\linewidth}
\begin{lstlisting}
while(true){
	//generates a random number between 0 and 1
	double random = Math.random();

	if(random < 0.5) {
		break;
	}
}
\end{lstlisting}
\end{minipage}
\hspace{0.25in}
\begin{minipage}[t]{0.25\linewidth}
(c) Answer: \fillInBlank
\end{minipage}
\vfill

\hfill
\begin{minipage}{0.58\linewidth}
\begin{lstlisting}
double[] data = new double[31]; 
double val =  1.0;
	for (Double d : data) {
		val = d * 5;
	}
\end{lstlisting}
\end{minipage}
\hspace{0.25in}
\begin{minipage}[t]{0.25\linewidth}
(d) Answer: \fillInBlank
\end{minipage}
\vfill

\clearpage

4. (6 points) {\emph Write T next to the statements that are true, F next to the statements that are false.}

 \fillInBlank Static methods use no instance variables of any object of the class they are defined in.
 
  \fillInBlank If I had a class \code{Foo} with a non--static method \code{nonstatic()}, I could call it like this: \code{Foo.nonstatic();}.
 
  \fillInBlank Before you can call a static method, you must first create an instance of a class like this: \code{MyClass foo = new MyClass();}.

  \fillInBlank Static methods typically take all their data from parameters and compute something from those parameters.
    
\fillInBlank If i and j are \code{int} values, then \code{Math.max(i,j)} is an example of a correct way to call a static method.

\fillInBlank A static variable is shared by all instances of a class, so a change to it from any instance affects all other instances.

\vfill
\vfill

\begin{center}
{\Large Turn in your answers to this part of the exam and please wait quietly until the rest of the class has completed the exam. You may leave if you do not wish to stay for the review session for the programming exam.}
\end{center}

\end{document}  
