%%% UNCOMMENT THIS TO PRINT AN ANSWER KEY (and comment out the other \documentclass)
%\documentclass[11pt,addpoints,answers]{exam}
%\newcommand{\SOLUTION}{ \textcolor{red}{-- SAMPLE SOLUTION --} } % TODO: uncomment this line to show SOLUTION LABEL
%\newcommand{\CORRECT}{ \textcolor{red}{CORRECT}} 

%%% UNCOMMENT THIS TO PRINT AN EXAM (and comment out the other \documentclass)
\documentclass[11pt,addpoints]{exam}
\newcommand{\SOLUTION }{Lecture Handout } % TODO: uncomment this line to so no solution label is included
\newcommand{\CORRECT}{} 

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% 
%    TODO: Change HANDOUT VARIABLES for EACH HANDOUT
% 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\newcommand{\handoutname}{File Input and Exceptions }      % 1-primary          2-secondary          3-tertiary
\newcommand{\handoutcolor}{Yellow}   %  Yellow-primary  Green-secondary   Buff-tertiary
\newcommand{\weeknumber}{}   % 1-primary          2-secondary          3-tertiary
\newcommand{\week}{ \weeknumber }               %  P-primary         S-secondary          T-tertiary

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% 
%    TODO: Change HANDOUT VARIABLES for EACH SEMESTER and COURSE OFFERING
% 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\newcommand{\semester}{Spring }
\newcommand{\yr}{2015 }   % \year was already defined elsewhere, but could not use
\newcommand{\lecA}{Lec 001\: Deppeler 800TR}
\newcommand{\lecB}{Lec 002\: Deppeler 100TR}
\newcommand{\instructorfull}{Deb Deppeler}
\newcommand{\instructor}{Deppeler} % fits better in header and footer
\newcommand{\coursenumber}{302}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\setlength{\parindent}{0pt}
\usepackage[utf8]{inputenc}
\usepackage{changepage}
\usepackage{multicol}
\usepackage{graphicx}
\usepackage{latexsym}
\usepackage{textcomp}
\usepackage{dashrule}
\usepackage{multirow}
\usepackage{array}
\usepackage{enumitem}
\usepackage{color}

\definecolor{dkgreen}{rgb}{0,0.6,0}
\definecolor{gray}{rgb}{0.5,0.5,0.5}
\definecolor{mauve}{rgb}{0.58,0,0.82}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%       CODE ENVIRONMENT FOR LONGER CODE FRAGMENTS
%       TO USE: \begin{lstlisting} [code] \end{lstlisting}
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\usepackage{listings}     % for preformatted code fragments
\usepackage{lmodern}   % NEEDED FOR BOLD FONTS WITHIN LISTINGS  
\lstset{
  language=Java,
  emph={EXPR,EXPR1,EXPR2,COND,COND1,COND2,STMT,STMT1,STMT2,DEC_STMT,CODE,CODE1,CODE2},  % LABELS that are bold and underline
  emphstyle=\bfseries\underbar,
  frame=none,   % default to none, can set =single, =tb, 
  aboveskip=3mm,
  belowskip=3mm,
  showstringspaces=false,
  columns=flexible,
  basicstyle={\small\ttfamily},
  numbers=none,
  numberstyle=\tiny\color{gray},
  keywordstyle=\color{blue},
  commentstyle=\color{dkgreen},
  stringstyle=\color{mauve},
  breaklines=true,
  breakatwhitespace=true,
  tabsize=4
}

%%  TIP: to get list enumerated with lowercase roman numerals: i,ii,iii,iv,iv, ...
%\begin{enumerate}[label={\roman*}]
%\item double d = s;
%\item double d = c;
%\item double d = t;
%\end{enumerate}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% package:exams POINTS STYLE AND PLACEMENT
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\pointpoints{pt}{pts}
\pointsinrightmargin

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% HEADER & FOOTER STYLE
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\pagestyle{headandfoot}
\runningheadrule
%\firstpageheader{}{}{}
\firstpageheader{CS\coursenumber \space \handoutname \space }{\week \SOLUTION}{\textcopyright \yr \instructor}
\runningheader{CS\coursenumber \space \handoutname \space }{\week \SOLUTION}{\textcopyright \yr \instructor}
\firstpagefooter{\textcopyright  \yr  \instructor}{CS\coursenumber \space \handoutname \week \SOLUTION}{Page \thepage\ of \numpages}
\runningfooter{}{CS\coursenumber \space \handoutname \space \SOLUTION}{Page \thepage\ of \numpages}
\runningfootrule

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{document}


%%%%%%%%%%%%%%%%%%%%% HANDOUT TITLE %%%%%%%%%%%%%%%%%%%%
%\begin{center}  
%
%\vspace{1mm}
%
%Computer Sciences \coursenumber                   % Computer Sciences 302
%
%\vspace{2mm}
%
%{\Large\week \weeknumber: \handoutname \SOLUTION}                       % Shadowed (hidden) fields
%
%\vspace{2mm}
%
%Instructor: \instructorfull                                % Instructors: Deppeler
%
%\vspace{5mm}
%
%\end{center}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%%% HANDOUT INSTRUCTIONS %%%%%%%%%%%%%%%%
%\textbf{Fill in these fields (left to right) on the red scantron form (use \#2 pencil):} 
%\begin{enumerate}
%\item \makebox[\textwidth]{\textbf{Full Name:}\enspace\hrulefill}
%
%\item \makebox[\textwidth]{\textbf{NetID and Email:}\enspace\hrulefill}
%
%\end{enumerate}
%\vspace{5mm}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%



%%%%%%%%%%%%%%%%%%% WAIT TO GET STARTED (Quiz or Exam Only) %%%%%%%%%%%%%%%%%%
%
%\hfil\hdashrule{\textwidth}{0.5pt}{1pt}\hfil
%
%\vspace{3mm}
%
%\begin{enumerate}
%\item Be sure to review the reference pages as needed during the exam.
%\item \textbf{Turn off and put away} your cell phone, calculator, Inspector Gadget (watches, glasses, pencils, etc.) now and wait for the proctor to signal the start of the exam. 
%\end{enumerate}
%
%\vspace{3mm}
%
%\hfil\hdashrule{\textwidth}{0.5pt}{1pt}\hfil


%% GRADE TABLE UNUSED ON MULTIPLE CHOICE EXAMS %%
%\begin{center}
%\gradetable
%\end{center}
%\vspace*{\fill}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%                                    REFERENCE %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\newpage

\begin{adjustwidth}{-0.5in}{-0.5in}
\textbf{Disclaimer:} the following are provided for your reference only, and the inclusion of information here does not guarantee it will be used on the exam.
\end{adjustwidth}

%%%%%%%%%%%%%%%%%%%% FILE CLASS REFERENCE Exam 3 only)
\begin{adjustwidth}{-0.5in}{-0.5in}
\subsection*{Methods from the java.io.File class:}
\begin{tabular}{>{\ttfamily}l l}
File(String filename) & Creates a \texttt{File} object for the given file name \\
boolean exists() & Returns \texttt{true} if the specified file already exists \\
boolean canRead() & Returns \texttt{true} if the specified file can be opened for reading \\
boolean canWrite() & Returns \texttt{true} if the specified file can modified (written to) \\
\end{tabular}


%%%%%%%%%%%%%%%%%%%%% SCANNER CLASS REFERENCE 
\subsection*{Methods from the java.util.Scanner class:}
\begin{tabular}{>{\ttfamily}l l}
Scanner(String s) & Creates a \texttt{Scanner} to read the \texttt{String s} \\
Scanner(System.in) & Creates a \texttt{Scanner} that reads from the keyboard. \\
Scanner(File fn) throws FileNotFoundException & Creates a \texttt{Scanner} to read from file \\ % (EXAM 3 ONLY)
void close() throws IOException & Closes the stream and any associated file \\
boolean hasNext() & Returns \texttt{true} if there’s another token of input. \\
boolean hasNextInt() & Returns \texttt{true} if the next input is an int value. \\
boolean hasNextDouble() & Returns \texttt{true} if the next input is a double value. \\
boolean hasNextLine() & Returns \texttt{true} if there’s another line of input. \\
String next() & Returns the next word only, as a String. \\
int nextInt() & Returns the next word only, as an integer. \\
double nextDouble() & Returns the next word only, as a double. \\
String nextLine() & Returns the next line as a String. \\
\end{tabular}

\end{adjustwidth}
%\vspace*{\fill}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%                                                            START OF HANDOUT                                                                   
% ----------------------------------------------------------------------------------------------------------------------------
%  #-Y = Yellow = Primary Exam week      #- G = Green = Secondary Exam week  #-T = Buff = Tertiary week 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% \subsection*{Elementary Programming}
% \subsection*{Selections}
% \subsection*{Loops}
% \subsection*{methods}
% \subsection*{Math functions}
% \subsection*{String and char}
% \subsection*{1D Arrays}
% \subsection*{Classes and objects}
% \subsection*{2D Arrays}
% \subsection*{1D Arrays}


\subsection*{Questions}

\begin{questions}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% QUESTION  1-Echo a File's contents to the Screen
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\question Write a method named \texttt{fileEcho} that accepts a filename as a String and displays each line to the screen with a line number.

\vspace{10mm}


\vspace{\fill}

\newpage

% ------------------------------------------------------------------------------
% Read raw scores and compute final percentage
% ------------------------------------------------------------------------------
\question Write code that reads a grade file and computes the percentage for each student.  The first line is the grade item name. The second line is the percentage of the final grade for each grade item. The third line is the max score possible for each grade item.  The remaining lines are scores for specific students.

Example grade file:

\begin{lstlisting}
ITEM,e1,e2,p1,p2,LABS
WEIGHT,10,15,10,10,15
MAX,100,100,50,50,15
s1,89,93,49,50,15
s2,70,52,47,48,15
s3,88,79,42,38,15
s4,76,80,38,45,15
s5,75,74,40,43,15
\end{lstlisting}



\end{questions}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% PAGE n: 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%\begin{questions}

%\question What's next?

%\end{questions}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% QUESTION  -Y   -G                                                QUESTION TEMPLATE
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%\question ?
%
%\begin{lstlisting}[frame=single]      % = none, =tb, =lr
%
%code fragment here
%
%\end{lstlisting}
%
%\begin{enumerate}[label={\roman*}]
%\item one
%\item two
%\item three
%\end{enumerate}
%	
%\begin{choices}
%\choice {\tt !}
%\choice @
%\choice \#
%\choice \$
%\choice \%
%\end{choices}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%% QUESTION  -Y   -G                                                HAVE YOU ANSWERED ALL QUESTIONS
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%\newpage
%
%\hdashrule{\textwidth}{0.5pt}{1pt}
%
%Check that you have answered all questions and bring your UW ID and turn in your exam question paper and scantron sheet.
%
%\hdashrule{\textwidth}{0.5pt}{1pt}


%\end{questions}

\end{document}

%%%%%%%%%%%%%%%%%%%%%% SAMPLE FORMAT EXAMPLES %%%%%%%%%%%%%
% ROMAN NUMERAL 
%\begin{enumerate}[label={\roman*}]
%\item \texttt{ double d = s.hasNextDouble(); }
%\item\texttt{  double d = c; }
%\item\texttt{  double d = t; }
%\end{enumerate}
%
%
%\question Which replacement for \textbf{\underline{CODE}} completes this method, which  must return true if and only if the value of \texttt{cents} is between 0 (inclusive) and 100 (inclusive).  Otherwise, the method must return false.
%
%\begin{lstlisting}[frame=none] 
%	public static boolean validCents (int cents) {
%  		CODE
%	}
%\end{lstlisting}
%
%\begin{choices}
%
%\choice \begin{lstlisting}[frame=none] 
%return true || false;
%\end{lstlisting}
% 
%\choice \begin{lstlisting}[frame=none] 
%if ( cents >= 0 ) { return true; }
%else if ( cents <= 100 ) { return true; }
%else { return false; }
%\end{lstlisting}
% 
%\choice \begin{lstlisting}[frame=none] 
%return !(cents < 0 || cents > 100);
%\end{lstlisting}
%
%\choice \begin{lstlisting}[frame=none] 
%if ( cents <= 100 || cents >= 0 ) { return true; }
%else { return false; }
%return 0 <= cents <= 100 ;
%\end{lstlisting}
%
%\end{choices}
%
%%%%%%%%%%%%%%%%%%%%%% SAMPLE FORMAT EXAMPLES %%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%%%% PYTHON EXAMPLES by HOBBES %%%%%%%%%%%%%
%
%  SAMPLE QUESTIONS FROM HOBBES CS301 -- kept for examples of fill-in the blank and multi-column
%
%%%%%%%%%%%%%%%%%%%%%% PYTHON EXAMPLES by HOBBES %%%%%%%%%%%%%
%\newpage
%
%\section{Question Type Examples}
%
%\subsection*{True or False: Basic Python information}
%

%%%%%%%%%%%%%%%%%%%%%%% QUESTION CHECKBOXES, TWO COLUMNS & TWO ROWS of choices
% QUESTION  -Y   -G
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%\question[4] What is the \textit{value} in {\tt x} after the following line of code is executed?
%\begin{adjustwidth}{1.3cm}{}
%{\tt x = "string"[1] + "berry"[-1]}
%\end{adjustwidth}
%
%%%%%%%%%%%%%%%%%%%%%%% QUESTION FILL IN THE BLANK EXAMPLES of choices
% QUESTION  -Y   -G
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%
%\vspace{4mm}
%
%\begin{multicols}{2}
%\begin{checkboxes}
%	\CorrectChoice {\tt one
%	five}
%	
%	\vspace{5mm}
%	
%	\choice {\tt one
%	two}
%	
%	\choice {\tt one
%	two
%	five}
%	
%	\vspace{5mm}
%	
%	\choice {\tt five}
%\end{checkboxes}
%\end{multicols}

%\subsection*{Fill-in-the-blank: Writing code}
%
%For each of the following questions, fill in the value, operator, or statement needed to produce the indicated output (check the comments if you need a hint). Pay attention to data types!
%
%\vspace{5mm}


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% QUESTION  -Y   -G
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%\question[6]
%\begin{adjustwidth}{.5cm}{}
%{\tt x = $\rule{5cm}{0.15mm}$ \# literal value
%
%print x * 5  \hspace{3.25cm}  \# output: 11111}
%\end{adjustwidth}
%
%\vspace{5mm}


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% QUESTION  -Y   -G
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%\question[6]
%\begin{adjustwidth}{.5cm}{}
%{\tt x = $\rule{6cm}{0.15mm}$ \hspace{3mm} \# code to get number 1-10 from user
%
%print x + 5 \hspace{4.75cm} \# output is a number between 6-15}
%\end{adjustwidth}
%
%\vspace{5mm}


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% QUESTION  -Y   -G
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%\question[6]
%\begin{adjustwidth}{.5cm}{}
%{\tt for x in range(10): \hspace{3.25cm} \# output: 1 2 3 4 5 6 7 8 9 10
%
%\vspace{3mm}
%
%\hspace{1cm} print $\rule{5cm}{0.15mm}$ \hspace{3mm} \# expression with x}
%\end{adjustwidth}
%
%\vspace{5mm}


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% QUESTION  -Y   -G
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%\question[6] Fill in the blanks in the condition so that it evaluates to {\tt True} for the {\tt int} values of {\tt x} indicated on the number line below. Empty circles are not included in the range.
%
%\begin{center}
%\includegraphics[clip=true, trim=4cm 12.25cm 2cm 5cm, scale=0.6]{NumberlineE1}
%\end{center}
%
%\vspace{2mm}
%\begin{adjustwidth}{.5cm}{}
%\hspace{1cm}{\tt ( x < 5 and $\rule{3cm}{0.15mm}$ ) or $\rule{4cm}{0.15mm}$}
%\end{adjustwidth}
%
%\vspace{5mm}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% QUESTION  -Y   -G
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%\question[6]
%\begin{adjustwidth}{.5cm}{}
%{\tt x = 3 \hspace{3.4cm} \# output: 27
%
%print x $\rule{2cm}{0.15mm}$ 3 \hspace{3mm} \# operator only}
%\end{adjustwidth}
%
%\vspace{5mm}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% QUESTION  -Y   -G
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%\question[6]
%\begin{adjustwidth}{.5cm}{}
%{\tt num\_spaces = 0
%
%for x in word: \hspace{3.4cm} \# assume word is some long string
%
%\hspace{1cm}if $\rule{5cm}{0.15mm}$: \# condition
%
%\hspace{2cm}num\_spaces += 1 \hspace{1.7cm} \# count number of spaces
%}
%\end{adjustwidth}

