Beruflich Dokumente
Kultur Dokumente
Why
Do
We
Program?
To
answers
ques)ons
What
is
the
average
height
of
the
men
in
this
class?
double[] height_of_men = readHeightData();!
double sum_of_heights = 0.0;!
for (int i=0; i<height_of_men.length; i++) {!
!sum_of_heights += height_of_men[i];!
}!
double avg_height = sum_of_heights / height_of_men.length;!
Why
Do
We
Program?
To
understand
our
world
Why
Do
We
Program?
To
discover
Why
Do
We
Program
To
make
money
Why
Do
We
Program?
To
create
new
worlds
Why
Do
We
Program?
To
evolve
What
Is
Programming?
In
contrast
with
many
engineers
who
make
houses,
cars,
medicines,
clothing
for
human
need
and
enjoyment,
we
make
things
that
do
not
themselves
meet
human
needs,
but
serve
as
tools
in
the
mee)ng
of
needs.
In
a
word,
the
computer
scien)st
is
a
toolsmith
no
more,
but
no
less.
It
is
an
honorable
calling.
--
Dr.
Fred
P.
Brooks,
Jr.
Programming
is
Toolsmithing
How Do We Program?
Object-Oriented
Programming
Programs
expressed
as
a
set
of
so_ware
objects.
Each
object
is
associated
with
data
and
a
set
of
func)ons
or
procedures
that
operate
with
that
data.
Abstrac)on
Encapsula)on
Inheritance
Polymorphism
Delega)on
Design
Paderns
Asynchronous
Programming
Course
Management
Sakai
Piazza
hdp://piazza.com/unc/spring2014/comp401/home
Textbook / Resources
No
required
text.
Will
be
pos)ng
links
to
lots
of
on-line
materials
on
Piazza
course
resources
page.
Prerequisites
This
should
not
be
your
rst
introduc)on
to
programming.
COMP
110
or
116
High
school
Hobbyist
/
Profession
experience
hdp://www.oracle.com/technetwork/java/
compile-136656.html
hdp://docs.oracle.com/javase/tutorial/java/nutsandbolts/
index.html
Many
others.
1
nal
exam
Monday,
5/5,
12:00
noon
Loca)on
TBA
Grading
40%
assignments
10%
recita)ons
15%
x
2
midterms
20%
nal
Compu)ng
your
grade
Assignments
May
restrict
the
use
of
certain
Java
libraries
and/or
features.
May
require
the
use
of
certain
programming
techniques
or
approaches
to
the
solu)on.
Correctness
is
but
one
criteria
for
grading.
Elegance
and
readability
will
also
count.
Honor
Code
Can
discuss
assignment
solu)ons
at
a
high
level
but
not
at
the
level
of
code.
Code
sharing
=
chea)ng
You
are
allowed
to
padern
your
code
a_er
anything
I
post
(i.e.,
class
examples,
etc.).
Recita)ons
Recita)ons
are
mandatory.
Adendance
will
be
taken.
If
you
have
a
valid
excuse,
you
must
no)fy
me
in
advance.
If
missed
for
unforeseen
circumstances
(sickness,
etc.),
please
be
prepared
to
provide
documenta)on.
OO
Programming
Languages
Almost
all
modern
programming
languages
support
some
sort
of
object-oriented
programming.
Not
all
of
them
will
do
so
in
the
same
way.
There
isnt
just
one
way
of
being
object-oriented.
hdp://www.oracle.com/technetwork/java/javase/
Mac Users
Eclipse
Java-based
Integrated
development
environment
(IDE)
Not
necessarily
the
best,
but
reasonable,
free,
and
fairly
straighuorward
to
use.
Available
at
hdp://eclipse.org
AverageHeightApp
(1/2)
Open
a
plain
text
editor.
Create
a
le
called
AverageHeightApp.java
Enter
the
following
text:
public class AverageHeightApp { !
!
!
public static void main(String[] args) {!
double[] height_of_men = readHeightData();!
double sum_of_heights = 0.0;!
for (int i=0; i<height_of_men.length; i++) {!
sum_of_heights += height_of_men[i];!
!}!
!double avg_height = sum_of_heights /!
height_of_men.length;!
!System.out.println("The average height is: " + avg_height + " inches");!
}!
!
static double[] readHeightData() {!
double[] height_data = {66.0, 72.0, 69.5, 68.2, 75.0, 64.5, 63.0};!
return height_data;!
}!
}!
AverageHeightApp
(2/2)
At
a
terminal
command
line
(console
for
you
Windows
people),
execute
the
following
commands:
>
javac
AverageHeightApp.java
>
java
AverageHeightApp
AverageHeightApp
Notables
Demonstrates:
Use
of
javac
and
java
from
the
command
line
Appropriate
declara)on
of
main
Using
a
for
loop
to
iterate
over
an
array
Using
System.out.println
for
console
output
See
reference
documenta)on
for
System
class
Link
on
Piazza
resources
page
AverageHeightApp
take
2
Same
as
before,
but
with
Eclipse.
Eclipse
Workspace
Crea)ng
new
project
Crea)ng
a
new
package
Crea)ng
new
class