\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, Dec. 19, 2013}
\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 and then open your computers.

Part 2 is to be solved using your computer.  You will need network access to download template code and upload your solution for part 2.  Please disable Lync, IM, email, and other such communication programs before beginning 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{Allowed Resources on Part 2}:  Open book, open notes, and computer.  Limited network access.  You may use the network only to access your own files, the course Moodle and Piazza sites and web pages, the textbook's site, Oracle's Java website, and Logan Library's online books. 

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

\begin{center}
\textbf{We suggest spending no more than 40 minutes on 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. Recall that \emph{you must turn in part 1 before accessing resources for part 2. Use of your computer before turning
in part 1 of the examwill 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 Fraction {
	private int numerator;
	private int denominator;

	public Fraction() {
		this.numerator = 1;
		this.denominator = 1;
	}

	public Fraction(int num, int denom) {
		this.numerator = num;
		this.denominator = denom;
	}

	public Fraction add(Fraction frac) {
		int commonDenom = this.denominator*frac.denominator;
		int myNumerator = this.numerator*frac.denominator;
		int otherNumerator = frac.numerator*this.denominator;
		
		return new Fraction(myNumerator+otherNumerator, commonDenom);
	}
	
	public String toString(){
		return this.numerator + "/" + this.denominator;
	}
}
\end{lstlisting}
\end{minipage}
\end{center}
\clearpage

The next several questions all refer to a \code{Fraction} 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{Fraction} 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}
Fraction first = new Fraction(2, 4);
System.out.println(first.toString());
\end{lstlisting}
\end{minipage}
\hspace{0.25in}
\begin{minipage}[t]{0.3\linewidth}
\vspace{0.1in}
(a) Output: \fillInBlank[1in]\\
Diagram:
\end{minipage}

\vfill
\hrule
\begin{minipage}[t]{0.55\linewidth}
\begin{lstlisting}
Fraction frac = new Fraction();
Fraction fracTwo = frac;
frac = fracTwo.add(new Fraction(3, 5));
System.out.println(frac.toString());
\end{lstlisting}
\end{minipage}
\hspace{0.25in}
\begin{minipage}[t]{0.3\linewidth}
\vspace{0.1in}
(b) Output: \fillInBlank[1in]\\
Diagram:
\end{minipage}

\vfill
\hrule
\begin{minipage}[t]{0.58\linewidth}
\begin{lstlisting}
Fraction[] fractions = new Fraction[3];
Fraction newFraction = new Fraction(5, 12);
for (int i = 0; i < fractions.length; i++){
	fractions[i] = newFraction;
}
fractions[1].add(fractions[1]);
System.out.println(fractions[1].toString());
\end{lstlisting}
\end{minipage}
\hspace{0.25in}
\begin{minipage}[t]{0.3\linewidth}
\vspace{0.1in}
(c) Output: \fillInBlank[1in]\\
Diagram:
\end{minipage}
\vfill


\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.) \textsc{Do not type the code snippets for this question in Eclipse}.
\vspace{0.25in}

\hfill
\begin{minipage}{0.60\linewidth}
\begin{lstlisting}
int milesTraveled = 13;
int hours = 3;
System.out.println(milesTraveled / hours);
\end{lstlisting}
\end{minipage}
\hspace{0.25in}
(a) Output: \fillInBlank[1in]

\vfill
\hfill
\begin{minipage}{0.60\linewidth}
\begin{lstlisting}
String[] socialMedia = new String[8];
socialMedia[0] = "Facebook";
socialMedia[1] = "Twitter";
socialMedia[2] = "Google+";
socialMedia[3] = "Instagram";
socialMedia[4] = "Linkedin";
socialMedia[5] = "Pinterest";
System.out.println(socialMedia[socialMedia.length - 5]);
\end{lstlisting}
\end{minipage}
\hspace{0.25in}
(b) Output: \fillInBlank[1in]

\vfill
\hfill
\begin{minipage}{0.60\linewidth}
\begin{lstlisting}
double pi = 3.1415926535;
int num = 2;
System.out.printf("%d QQQ %.3f", num, pi);
\end{lstlisting}
\end{minipage}
\hspace{0.25in}
(c) Output: \fillInBlank[1in]

\vfill

\hfill
\begin{minipage}{0.60\linewidth}
\begin{lstlisting}
HashMap<Integer,Integer> map;
map = new HashMap<Integer,Integer>;
map.put(5,7);
map.put(11,5);
System.out.println(map.get(5));
\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 = 9;
for (int i = 0; i <= maxFrequency; i++) {
	// loop body elided
}
\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 < 32) {
	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[17]; 
double val =  1.0;
	for (Double d : data) {
		val = d * 25;
	}
\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 you were looking some code in a function and saw \code{int result = myVar.doCalculation(19,23);}, where \code{myVar} is local variable of the function, you should assume that \code{doCalculation} is a static method.

\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.



\vfill
\vfill

\begin{center}
{\Large Turn in your answers to this part of the exam before you begin the computer part.}
\end{center}

\end{document}  
