%%% SECTION %%%
\section{Unit One Activities}
\begin{quote}
    Activities on Lesson page 2-5 \\
    Activities on Lesson page 2-6 \\
    Activities on Lesson page 3-1 \\
    Activities on Lesson page 3-2 \\
    Activities on Lesson page 3-3 \\
    Activities on Lesson page 3-4 \\
    Activities on Lesson page 3-5 \\
    Activities on Lesson page 6-1 \\
    Activities on Lesson page 2-7 
\end{quote}

%%% SECTION %%%
\section{Overview}

In this first unit on programming, you will encounter some basic
terminology of computing and programming, look at a few Java programs, and
study the basic components of Java programs.


%%% SECTION %%%
\section{Basic output and input}

\begin{description}
    
    \item\textbf{Activity 2-5-1: Using the Java Console for output.}

%% Definitions and phrase completions
 % 


    \item\textbf{Activity 2-5-2: Using the Java Console for input.}

    \defn{prompt}

    \begin{exercise}
	
	Type the following code into a file named ``Test.java'':
  
    \begin{verbatim}
    public class Test {
        public static void main(String[] args) {
            System.out.println(``Hi'' + ``Phred.'');    
        }
    }\end{verbatim}
    
    Compile and run this program.  Notice how the output looks a bit
    funny?  Fix it so it becomes readable.
    
    Now try using the \code{+} operator with \code{int}s,
    \code{long}s, and \code{String}s.  For example, what is the output
    if you substitute in the following lines of code?
    
    \begin{verbatim}
     System.out.println(``high '' + 5);
     System.out.println(``3'' + 20 * 2);
     System.out.println(3.4 + 1.6 + `` is five'');
     System.out.println(``Is five '' + 3.4 + 1.6);
	\end{verbatim}
    
	\end{exercise}


%% Definitions and phrase completions
 % 

    \item\textbf{Activity 2-5-3: A GUI: JLiveWindow.}
    
    \begin{exercise}
	Change method \code{buttonPressed} in class
	\code{MyJLiveWindow} so that it reads from \code{int} field 0
	and puts twice that amount in \code{int} field 1.  What
	happens if you type a letter into the \code{int} field?
    \end{exercise}

%% Definitions and phrase completions
 % 


    \item\textbf{Activity 2-5-4: The Java Console and GUIs.}

    \begin{exercise}
	Draw the Olympic rings.
	
	\note{Need a picture here}
    \end{exercise}
    
%% Definitions and phrase completions
 % 


    \item\textbf{Activity 2-5-5: Graphics windows.}

%% Definitions and phrase completions
 % 


    \item\textbf{Activity 2-5-6: Using a graphics window.}

%% Definitions and phrase completions
 % 


    \item\textbf{Activity 2-5-7: Exercises on graphics windows.}

%% Definitions and phrase completions
 % 



    What is the type of the result, when you ``add'' the following:

    \phrase{A \code{String} and an \code{int} produces a result of type
    \underline{\code{String}}.}

    \phrase{A \code{String} and a \code{String} produces a result of
    type \blankfill{.8in}.}

    \phrase{An \code{int} and an \code{int} produces a result of type
    \blankfill{.8in}.}

    \phrase{An \code{int} and a \code{String} produces a result of
    type \blankfill{.8in}.}

    \phrase{A \code{String} and an \code{int} and then another
    \code{int} produces a result of type \blankfill{.8in}.}

    \phrase{An \code{int} and a \code{long} produces a result of type
    \blankfill{.8in}.}



    \phrase{Match the outputs with the print statements. If there is a
    mistake in the print statement, don't match it with anything.}

    $\begin{array}{llll} $System.out.println(``fred'');$ \\
    $System.out.println(23);$ \\
    $System.out.print(fred);$          & & & $fred$  \\
    $System.out.print(23);$ \\
    $System.out.print(``23'');$        & & & $23$ \\
    $System.out.print(``fr'' + ed); $ \\
    $System.out.print(``1'' + 20 + 2);$ \\
    \end{array} $ \\

    \phrase{Given the value stored in a is 20 and the value stored in
    b in 3, write the output of the following print statement:}

    \code{System.out.println("Compost composed... \slash nThe result
    of a + b: " \\
    + a + b + "\slash n" + 33 + ", 44, 55");} \hfill{.5in}

    \phrase{Notice how difficult it is to read when written as one
    statement? Using the same variables, a and b, re-write the print
    statement as three seperate print statements. Hint: each line of
    output should be a seperate line of code. You may use ``println''
    instead of ``\slash n''.}

    \phrase{Assuming you have included the file \code{JLiveRead.java}
    in your project, what line of code will read an integer typed by
    the user, and store it in some integer variable \code{x}?}

    \phrase{What do the following lines of code do?}
    \code{System.out.print(``Enter number of young goats: ``);}
    \code{int numKids= JLiveRead.readInt();}

    \phrase{What would you expect the following code to do? (It is not
    code you can execute, so don't bother trying!)} \code{int phredID=
    ExampleClass.readIntID();}

    \begin{exercise}
    Create a project in your IDE using the two files
    \code{JLiveWindow.java} and \code{MyJLiveWindow.java}. Compile
    and run the project, to check that you've set it up correctly.
    \\
    Given that the line of code: \\
    \code{int sum= getIntField(0) + getIntField(1);} \\
    reads the integer in field 0, adds it to
    the integer read from field 1 and stores the result in
    \code{sum} whenever the button is pressed, what do each of the
    following lines of code do? Add them to method
    \code{buttonPressed}, and create a line of code to set
    different \code{int} fields to the results. Then run the
    program to check your results.\\
    
    \code{int mult= getIntField(0) * getIntField(1);}
    
    \code{int other= getIntField(0) - getIntField(1);}
    
    \code{int divResult= getIntField(0) / getIntField(1);}
    
    What happens if you type 4 in field 0 and 3 in field 1? Where
    did the decimal place go?
    \end{exercise}

\end{description}

%%% SECTION %%%
\section{Assertions in programs}
2-6


\begin{description}

\item\textbf{Activity 2-6-1: Relations about variables and values.}

%% Definitions and phrase completions
 % 
\defn{relation}

% Write something here about that weird sequence of steps to guessing
% a number...


\item\textbf{Activity 2-6-2: Simplifying a particular kind of relation.}

%% Definitions and phrase completions
 % 

  \truefalse{\textit{dogs} can mean \textit{feet}.\footnote{It's in the
      footnote to this activity.}}

\phrase{What is wrong with the following relation?
    $$\textrm{If it is raining, \code{wp} is true.}$$}

\phrase{Rewrite the relation to completely specify \code{wp}.}

\item\textbf{Activity 2-6-3: Assertions.}


%% Definitions and phrase completions
 % 

\end{description}


%%% SECTION %%%
\section{Methods}
\begin{description}

\item\textbf{Activity 3-1-1: Methods are recipes.}

%% Definitions and phrase completions
 % 

\phrase{Computers are not intelligent. They will follow the 
instructions they are given without any extrapolation or imagination. 
If you want to write a program to ``Add two numbers together'', you 
need to tell the computer which two numbers, and where to store the 
result. Someone else already told the computer how to add. \\

Write a set of instructions for wrapping a present.  Assume the person
following the instructions knows what the present is, as well as what
paper, sicissors, string, tape, pen and label are.  Try to follow your 
instructions using real materials, and you may find your instructions 
aren't as detailed as you think.}

\phrase{When you look at a box of instant cake mix (or a box of pasta,
or soup mix, or some other pre-processed food), you find a set of
instructions.  Write a set of instructions for boiling pasta.  Can you
make them general enough that you can substitute ``rice'' for
``pasta'' and only have to change the cooking time?  How about for
boiling potatoes?}

\item\textbf{Activity 3-1-2: The black-box view of a method.}

%% Definitions and phrase completions
 % 

\defn{method}

\defn{procedure}

\defn{specification}

\phrase{Write the form of a method header:}

\defn{body}

\defn{parameter}

\phrase{Write the form of a parameter declaration:}

\truefalse{\code{int} is a type.}

\truefalse{A parameter is a variable.}

\phrase{What does keyword \code{public} indicate?}

\phrase{Write a method header for a method called \code{myFirstHeader}
that is \code{public}, has return type \code{void}, and has two 
parameters, a variable called \code{i} and a variable called \code{j}, 
both of type \code{int}.}

%\item\textbf{Activity 3-1-3: Check your understanding of terminology.}

%% Definitions and phrase completions
 % 

\item\textbf{Activity 3-1-4: Understanding procedure calls.}

%% Definitions and phrase completions
 % 

\phrase{What do you need to do in order to figure out what execution 
of a procedure call does?}

\phrase{What does the method call \code{drawRect(22, 30, 40, 10} do?}

\item\textbf{Activity 3-1-5: The general form of a procedure call.}

%% Definitions and phrase completions
 % 

\phrase{What are the parts of a procedure call?
\begin{enumerate}
    \item {}
    \item {}
    \item {}
\end{enumerate}}

\phrase{Write the rules for the number and types of arguments:
\begin{enumerate}
    \item {}
    \item {}
    \item {}
\end{enumerate}}

\truefalse{\code{drawLine(0, 10, (3+30)/11, 4);} is a valid procedure 
call.}

\exercise{Think of something.}

\end{description}


%%% SECTION %%%
\section{Method bodies and method calls}
\begin{description}

\item\textbf{Activity 3-2-1: The method body.}

%% Definitions and phrase completions
 % 

\phrase{Write the steps for executing a procedure call:
\begin{enumerate}
    \item {}
    \item {}
    \item {}
    \item {}
    \item {}
\end{enumerate}}

\phrase[2in]{Perform the first four steps for executing the following
method call:

\code{print3(8*4, (14-6)/2);}}

\phrase[2in]{Perform the first four steps for executing the following
method call, where \code{x=12}:

\code{doIt(8*4, (14-6)/2, x);}

Here is the code for method \code{doIt}:
%\begin{verbatim}
    // Draw something
    public static void doIt(int ) {
    
    
    
    
    }
%\end{verbatim}
}

\item\textbf{Activity 3-2-2: Example of method-call execution.}

%% Definitions and phrase completions
 % 

\defn{frame}

\phrase{It is so important that you memorize the steps to executing a
procedure call that you should now, from memory, try to write those
steps:
\begin{enumerate}
    \item {}
    \item {}
    \item {}
    \item {}
    \item {}
\end{enumerate}
If you could do it, congratulations! If not, keep trying --this is 
one of the most important steps to learning how to program.}

\phrase[2in]{Perform the first four steps for executing the following
method call, where \code{x=12}:

\code{doIt(8*4, (14-6)/2, x);}

Here is the code for method \code{doIt}:
%\begin{verbatim}
    // Draw something
    public static void doIt(int ) {
    
    
    
    
    }
%\end{verbatim}
}

\item\textbf{Activity 3-2-3: Executing inner calls.}

%% Definitions and phrase completions
 % 

\phrase{From memory, write the steps to executing a procedure call:
\begin{enumerate}
    \item {}
    \item {}
    \item {}
    \item {}
    \item {}
\end{enumerate}}


\phrase{What happened to the frame for method \code{paint} while 
method \code{drawTriangle} was being executed?}


\truefalse{When method \code{drawTriangle} finished executing, we 
re-started execution of \code{paint}.}


%\item\textbf{Activity 3-2-4: Review of methods.}

%% Definitions and phrase completions
 % 

\item\textbf{Activity 3-2-5: Writing procedure calls.}

%% Definitions and phrase completions
 % 

\defn{debug}

\end{description}



%%% SECTION %%%
\section{Two components of method bodies}
\begin{description}

\item\textbf{Activity 3-3-1: Local variables.}

%% Definitions and phrase completions
 % 

\defn{local variable}

\phrase{Write the form of a local variable declaration:}

\phrase{What do you have to do to a local variable before you use it?}

\defn{scope}

\phrase{What is the scope of a local variable?}

\phrase{Circle the scope of variable \code{aVar}.
%\begin{verbatim}
public void foo() {

    System.out.println();
    int bVar;
    bVar= 3;
    int aVar;
    System.out.println();
    aVar= bVar * 2;
}
%\end{verbatim}
}

\item\textbf{Activity 3-3-2: Combining declaration and initialization.}

%% Definitions and phrase completions
 % 
\phrase{Write the form of an initialized variable declaration:}

\phrase{What should you do at the same time as you declare a local
variable?}


%\item\textbf{Activity 3-3-3: Check your understanding of local variables.}

%% Definitions and phrase completions
 % 

\item\textbf{Activity 3-3-4: The \code{return} statement.}

%% Definitions and phrase completions
 % 

\phrase{What happens when a \code{return} statement is executed?}

\end{description}



%%% SECTION %%%
\section{Functions}
\begin{description}

\item\textbf{Activity 3-4-1: Form of a function.}

%% Definitions and phrase completions
 % 

\phrase{Write the two major differences between a procedure and a 
function:
\begin{itemize}
    \item {}
    \item {}
\end{itemize}}

\phrase{How can you tell the difference between a procedure and a
function?}

\item\textbf{Activity 3-4-2: The function call.}

%% Definitions and phrase completions
 % 

\phrase{Procedures and functions are \urule{1.5in} mechanisms.}

\phrase{A procedure call is a \urule{1.5in}}

\phrase{A function call is an \urule{1.5in}}

\phrase[1in]{Describe the difference between the purposes of a
function specification and a function body:}

\phrase{Here is a function specification and header, and a call on 
that function. What is the result?
%\begin{verbatim}
\\\textsf{\Large Think up a function call.}
%\end{verbatim}
}

\item\textbf{Activity 3-4-3: Executing a function call.}

%% Definitions and phrase completions
 % 

\phrase{Write the steps for executing a function call:
\begin{enumerate}
    \item {}
    \item {}
    \item {}
    \item {}
    \item {}
\end{enumerate}}

\phrase{Which two steps differ from the steps for executing a
procedure call, and how are they different?}


%\item\textbf{Activity 3-4-4: Check your understanding of functions.}

%% Definitions and phrase completions
 % 

\end{description}





%%% SECTION %%%
\section{Top-down programming}
\begin{description}

\item\textbf{Activity 3-5-1: Top-down design, or stepwise refinement.}

%% Definitions and phrase completions
 % 


\defn{top-down programming}

\defn{statement-comment}


\item\textbf{Activity 3-5-2: The Raven.}

%% Definitions and phrase completions
 % 

\phrase{How many lines did Poe decide The Raven should be?
% 100
}

\phrase{What was the topic?
% Beauty
}

\phrase{What was the tone?
% Melancholic
}

\phrase{What would have to be sonorous and susceptible to protracted
emphasis?
% Nevermore
}


\item\textbf{Activity 3-5-3: Example 1: anglicizing integers.}

%% Definitions and phrase completions
 % 

\phrase{In method \code{tensName}, why is \code{n}'s range \code{2 <= 
n <= 9}? That is, why isn't \code{1} included?}

\item\textbf{Activity 3-5-4: Example 2: anglicizing integers a 
different way.}

%% Definitions and phrase completions
 % 

\phrase[1in]{In method \code{anglicize}, why didn't we use \code{if-else}
statements?  What bug would happen if we had?  Find an example of a
method call that would evaluation to the wrong result if we had used
\code{if-else} statements.}

\exercise{Write a function that has a \code{String} parameter, which
contains one of the single-digit words like \code{``zero''},
\code{``one''} or \code{``nine''}, and returns the \code{int} version 
of it. For example, if your function is called with argument 
\code{``seven''}, it should evaluate to \code{7}.}

\end{description}




%%% SECTION %%%
\section{Classes}
\begin{description}

\item\textbf{Activity 6-1-1: The class as a file drawer of methods.}

%% Definitions and phrase completions
 % 

\phrase[1in]{Write the form of a class definition.}

\phrase{In the filing cabinet metaphor, where are static methods
kept?}

\defn{public}

\phrase{On the Lesson page is a description of naming conventions for 
files. What should you name the file containing class \code{Foo}?}

\item\textbf{Activity 6-1-2: Referencing static methods.}

%% Definitions and phrase completions
 % 

\phrase{Write the two rules for referring to a static method in a 
method call:
\begin{enumerate}
    \item {}
    \item {}
\end{enumerate}}

\item\textbf{Activity 6-1-3: Examples of referencing static methods: 
temperature conversion.}

%% Definitions and phrase completions
 % 
\truefalse{It is vital that you think about efficiency as you develop
a program.}

\phrase{What trick did we use to avoid having to work out formulas for
the second set of temperature conversion methods?}


\item\textbf{Activity 6-1-4: Overloading method names.}

%% Definitions and phrase completions
 % 

\defn{overloading}


\end{description}


% 
% %%% SECTION %%%
% \section{Additional statements and expressions}
% 
% read the last footnote on conditional expression.
% 
% \begin{description}
% 
% \item\textbf{Page 2-7}
% 
% %% Definitions and phrase completions
%  % 
% 
% 
% 
% \end{description}
% 
% 
% 
