CIS1068: PROGRAM DESIGN AND ABSTRACTION [Spring 2010]
First required programming course in the CS Major. Problem solving and programming in Java,
introduction to software
engineering, procedural and data abstraction, and
elementary object-oriented
programming. Data
types covered include primitive data types, strings, classes, arrays,
array lists, and streams. Programming techniques include at least one
technique for searching and sorting an array and an introduction to file
processing. At the end of the course students are expected to be able write good quality small (100..200
lines) programs that solve small interesting and relevant problems.
Prerequisite: Grade of C or better in Mathematics 1021
(C073) or higher,
or placement into Mathematics 1022 (C074). Grade of C or better in C+IN SC
1053 (0061) or 1057 (C071) or a passing score on a placement exam given
during the first week of class.
Additional information about this course can be found on WWW at URL
http://www.cis.temple.edu/~ingargio/cis67/.
Instructor: Dr. Giorgio Ingargiola
- Office : Wachman Hall, Room 1038
- Phone : (215)204-6825
- E-Mail : giorgio@temple.edu
- Contact Hours :
Tuesday and Thursday from 11:15am to 12:45pm,
or by appointment, or take your chances and drop
by.
Lecture Time:
- Tuesday and Thursday: 8:00am to 9:20am in Tuttleman 302
Laboratory:
- Section 1: Wednesday from 10:00am to 11:50am in Wachman 104
- Section 3: Monday from 3:00pm to 4:50pm in Wachman 104
Section 1: Teaching Assistant: Vuk Malbasa
- Office : Wachman Room 1000M
- Phone : 215-204-3950
- E-Mail for homeworks: vmalbasa@gmail.com
- Help Homepage: www.vukmalbasa.com
- Contact Hours : Monday 3 to 5pm, Wednesday, Friday: 2 to 4 pm
Section 3: Teaching Assistant: Vladan Radosavljevic
- Office : Wachman Room 1000M
- Phone : 215-204-3950
- E-Mail for homeworks: vladan@ist.temple.edu
- Help Homepage: www.ist.temple.edu/~vladan/
- Contact Hours : Wednesday 12-1:30pm, Thursday 2 to 4pm
Miscellaneous: Our first class (Section 1) is on Tuesday, January 19
and the last
class is on Monday, May 3.
The last day to drop the course (and get tuition refund) is
Monday, February 1.
The last day to withdraw from the course (no refund) is Monday ,
March 29.
Students who have previously withdrawn from this course, or who have
already withdrawn from 5 courses since September 2003 may not withdraw.
Each student should have a general Temple email address.
Important student information is accessible from http://owlnet.temple.edu/
Any student who has a need for accomodation based on the impact of a
disability should contact me privately to discuss the specific situation
as soon as possible. Students with documented disabilities should contact
Disability Resources and Services at
215-204-1280 in 100 Ritter Hall to coordinate reasonable accomodations.
Freedom to teach and freedom to learn are inseparable facets
of academic freedom. The University has adopted a policy on
Student and Faculty Academic Rights and Responsibilities
(Policy # 03.70.02) which can be accessed through the
following link:
http://policies.temple.edu/getdoc.asp?policy_no=03.70.02
Students should be familiar with the University statement on academic honesty found at the
following link
http://www.temple.edu/bulletin/Responsibilities_rights/responsibilities/responsibilities.shtml
Textbook: Cay Horstmann: Big Java, 4th edition, John Wiley 2010
GRADING
- Weekly : 18% 10 minute tests: Eleven tests, given each week,
only your top ten scores will count
- Midterm 1 : 10% Tuesday, February 16
- Midterm 2 : 12% Tuesday, March 23
- Final : 35% Common exam from 3:30 to 5:30pm on May 10
- Homeworks : 25%
Disastrous performance in either the exams, or in the homeworks,
will result in a Fail grade. Class attendance is required. Absence
in more than 25% of the classes will result in a penalty of at least
half a letter grade.
Attendance to the laboratory is MANDATORY.
Absence from more than four labs
will result in the loss of at least one letter grade.
EXAMS
The exams are closed book. Their content is cumulative, i.e. they address
the material covered up to the day of the exam. If a student misses
a midterm for an emergency [as agreed with instructor], there will be no
makeup exam: the final will become
proportionally more important. If you miss a midterm without previous
agreement and without definite proof as to the medical or legal reasons,
you will get a zero for that exam. Weekly 10-minute tests that are
missed will not be made up.
The final exam is mandatory on the scheduled day.
HOMEWORKS
You will be assigned one homework each week.
Each assignment must be completed on time and sent by e-mail to the
Teaching Assistant (TA). The homeworks will be graded, commented
upon, and returned by e-mail by the TA usually before the next homework is
due.
Homeworks late up to 24 hours will be penalized 2 points (out of 10 possible).
Homeworks that are late by more than 24 hours will not be accepted by the TA;
the instructor may accept them in case of emergencies.
You are expected to work and complete all the homeworks on your
own.
Plagiarism will be severely punished.
See the
University Policy on Plagiarism and Academic Cheating.
LABORATORIES
Laboratories are lead by the Teaching Assistant.
Attendance to the laboratory is Mandatory.
In the laboratory you will be helped to learn how to use the programming
environment: command language, editor, compiler, and debugger. You will be
presented examples related to the material discussed in class and you will
examine common errors and how to avoid them.
Part of the laboratory time
will be dedicated to work on your programming assignments.
In the laboratory initially we will use command line commands javac, java,
text editor. Later you will be encouraged to use a
graphic interactive development environment like Eclipse
COURSE LEARNING OBJECTIVES:
A. INTRODUCTORY CONCEPTS
- Describe the basic components of a computer system: CPU, main memory,
secondary memory, I/O, bus.
- Introduce performance measures of time, memory, speed.
- Examine the role of a compiler in the programming process.
- Describe the role of the Java Virtual Machine [JVM]
- Create and edit a program using a text editor.
- Compile a program using the command-line in a terminal window.
- Run a program using the command-line in a terminal window.
- See example of use of an IDE.
B. PRIMITIVE DATA TYPES AND VARIABLES
- Describe the primitive data types in Java: representation, operations
and range of each primitive data type.
- Use positional notation to convert an integer to a base 10 numeral and
viceversa
- Experiment with ASCII representation of characters and see some
example of Unicode characters.
- Declare and initialize variables of each primitive data type.
- Write and evaluate expressions containing unary and binary operators,
+, -, *, /, %, &&, ||, !, <, <=, ==, !=, >=, ==, ++ [pre and
post increment], -- [pre and post decrement], using operator
precedence rules.
- Write and experiment with short hand [||, &&] and complete
[|, &] evaluation of conjuctions and disjunctions.
- Learn to use shorthand operators like +=, -=, *=, /=.
- Define and give examples of assignments.
- Write and evaluate expressions and assignments requiring conversions
between primitive data types, some implicit, some needing type casting.
- Explain why overflow can take place when computing with integer
[long, int, short, byte] variables.
- Explain why round-off error can take place when computing
with real [float, double] variables.
C. PROGRAM FLOW AND CONTROL
- Use conditional statements [if, if..else,
switch].
- Write, evaluate, and debug complex conditional statements [e.g. nested
conditionals, sequences of conditionals, dangling if].
- Write, evaluate, and debug three loop statements [while,
do/while and for].
- Show that do/while and for loops can be implemented
using the while
loop.
- Show how to control the number of times a loop is executed, experiment
with various termination conditions, use sentinel values, recognise
infinite loops.
- Learn to use when appropriate continue and break statements within loops.
- Learn to read code containing conditional expressions.
D. USING PREDEFINED CLASSES
- Recognize fundamental distinction in Java between primitive data types
and reference types.
- Learn to use the Java API and to import chosen classes.
- Write code to use the Math class: abs, sqrt, random
- Write code to use the String class: charAt, compareTo, equals,
indexOf, length, substring, and the concatenation operator.
- Write code to explore the consequences of Strings being immutable in
Java. For example see that building a very long
string a character at a time will be very time consuming. That instead
substrings can be computed rapidly.
- See examples of use of the class StringBuilder and how it differs from String.
- Write code to use the Integer [MIN_VALUE, MAX_VALUE,
parseInt],
Character [isDigit, isLetter, toUpperCase], Double [NaN, parseDouble]
classes
- Learn to use in the System class the objects in and out and the methods
arraycopy and exit.
- Recognize that the instances referenced from reference variables have
to be allocated and later taken care by garbage collection.
E. ARRAYS AND ARRAYLISTS
- Declare an array reference for a one-dimensional array of a given
element type [both primitive types and reference types] and size using the
keyword new.
- Recognize that an array reference can be null or it can reference an
empty array.
- Declare and initialize a one-dimensional array with specific values
using the {} notation. For example int[] a = {1,2,3};
and later a = new int[]{7,8,9,2,3};
- Understand the String[] formal parameter of the main method and write
programs that use command-line parameters.
- Write code to access and set specific elements of an array. Use the
length property to determine the number of elements in an array.
- Use a loop to traverse a given array and set its elements to some
desired values.
- Write code to determine simple properties of an array of numbers,
for example the smallest value and the average value.
- Write code to transform a given array, for example, reverse its
content.
- Declare a two dimensional array and experiment to see that it is
really a one dimensional array of one dimensional arrays and it can be
jagged.
-
Write code to traverse a two-dimensional array of scalars to compute
some basic property [count, average, smallest value]
- Write code to transform a given two-dimensional array, for example,
transpose a square matrix.
- Program with ArrayLists to deal with unknown numbers of elements.
Recognize that the elements of ArrayLists must be reference.
- Use autoboxing and deboxing to facilitate the use of ArrayLists
to store unknown numbers of primitive type values.
- Learn to transfer the content of an ArrayList to an array.
- Use the enhanced for loop statement to traverse arrays and
ArrayLists
F. INPUT/OUTPUT AND FILES
- Write code to print to the screen strings and other data
[System.out.println, System.out.print, System.out.printf].
- Write code to perform simple formatted output of integers, reals, strings and characters.
- Write code to read different kinds of data from the keyboard using the
Scanner class: hasNextLine, nextLine, hasNext, next, nextInt, nextDouble,
useDelimiter.
- Give examples of text and binary files and explain their differences.
- Write code to output to a text file instead than to the terminal,
using the PrintWriter class. See how a PrintWriter is constructed,
associated to an external file.
Use on a PrintWriter the methods print, println, printf, as we did with
System.out.
- Write code to input strings and other data from a text file, instead
than from the keyboard, using the Scanner class. See that a Scanner has to
be constructed on an existing file and used with the same methods that we
used on System.in.
- Write code to use the Scanner class to obtain substrings and other
data from a string.
G. EXCEPTION HANDLING
- Define what is an exception and understand the distinction between
checked and unchecked exceptions.
- Write code that requires the use of the try..catch..finally statement,
of the throws clause, and the throw statement.
- Write code that deals with the exceptions FileNotFoundException,
IOException, NullPointerException, ArrayIndexOutOfBoundException,
StringIndexOutOfBoundsException, InputMismatchException.
- Define and use a new exception class. For example define an exception
to report that the user is unable/unwilling to enter a specific data
value.
G. STATIC METHODS
- Explain the computational purpose of a static method, including the
main method, in Java.
- Define the signature of a static method
- Identify the formal parameters in the signature of a static
method.
- Show how a static method is called and how actual parameters
correspond to the formal parameters.
-
Identify the return type in the signature of a method and explain the use
of the keyword void as a return type.
-
Explain the principle of method overloading and identify two examples from
the Java API where overloading occurs.
- Explain that parameters are passed by value and see what this means in
the case that the parameter type is primitive and in the case that it is a
reference type.
H. OBJECTS, INSTANCE METHODS, AND CLASSES
- Define as classes some common objects, for example,
fractions, bank accounts, and DVDs.
- Understand the distinction between an idea/concept/prototype, and its
instances. For example the distinction between the idea of a DVD and my
"No Country for Old Men" DVD.
- Understand the state and behavior of a common everyday class of objects
[e.g. a bank account].
-
Define the terms: data field, constructor, accessor and mutator and
identify examples of their use.
-
Write data fields for a Java class to represent the state of a specific
object.
- Define and implement classes that have static and instance data
members and static and instance methods.
- Understand the role of the hidden parameter in the definition of
instance methods and be able to give examples of its use.
- Repeat and apply to instance methods concepts encountered discussing
static methods, such as signature, formal parameters, actual parameters,
return value, parameter passing, overloading.
- Write code that uses the keyword this.
-
Define and implement a number of constructors for a number of classes,
including default and copy constructors.
-
Define and implement the accessor methods for the fields for a class.
-
Define and implement a number of mutator methods for a class.
-
Implement the toString(), equals(), and clone() methods for at least a
class.
-
Create instances of a class in a separately compiled class, and invoke
both instance and static methods from the separately compiled class.
- Examine the role of Object as the supremum of the Java class hierarchy.
-
Understand the default implementations in the Object class of the
equals and clone methods.
-
Write for some classes implementations of toString, equals, and clone
that overrides the corresponding methods inherited from the Object Class.
- Write code to experiment with deep vs. shallow equals and clone.
J. ALGORITHMS
-
Write code to swap the content of two variables.
-
Write the algorithm and then code the euclidean algorithm to compute the
greatest common divisor of two numbers.
- Write the algorithm and then code algorithms that
- Compute the n-th power of a number
- Determine if a number is a power of 2
- Determine if a number is a prime
- Determine the written representation of a number in various bases
- Determine, given the written representation of a number in various
bases, what is the corresponding number.
- Print the first n Fibonacci numbers.
-
Write code to rotate the content of an array n positions to the right.
-
Write code to traverse a one-dimensional
array of numerical data to compute each of the following:
- the maximum value
- the minimum value
- index of the maximum value
- index of the minimum value
- the total sum
- the average of all values
-
the count of the number of values that match a specific property [e.g.
odd, positive, greater than some value, etc.]
-
Write code that traverses a one-dimensional
array of object references using the compareTo method to compute each of
the following:
- the maximum object
- the minimum object
- index of the maximum object
-
index of the minimum object
-
the count of the number of objects that match a specific property based on
given field(s).
-
Write the algorithm and the code for the insertion sort algorithm for an
array of integers and for an array of comparable object references.
-
Write the algorithm and the code for the selection sort algorithm for an
array of integers and for an array of comparable object references.
-
Write the algorithm and the code for the linear search algorithm and the
binary search algorithm.
- Write the algorithm and the code for the merge algorithm of arrays and
files.
- Write the algorithm and the code to generate random permutations of n
values.
- Write algorithms and code that use random number to solve mathematical
problems, for example to compute PI and examine the birthday paradox.
- Understand how long an algorithm will take to complete its work.
For example, understand that a linear search will take time proportional
to the size on the input array, that a binary search will take
proportional to the logarithm of the size of the input array, and that
both selection and insertion sort will take time proportional to the
square of the size of the input array.
K. CAREFUL SOFTWARE DEVELOPMENT
- Define the phases of software development [requirements, analysis,
design, implementation, and testing] and give examples from your
homeworks.
- Learn to develop programs carefully and gradually, using stubs
[trivial initial implementations for complex methods] and drivers [code to
test existing methods and classes].
- Write well indented, well spaced programs using a consistent style.
- Use meaningful names for variables, methods, classes.
- Be aware of the scope of each identifier, be it of a variable, a
method, or a class.
- Learn to trace carefully by hand [or using a debugger] the execution
of important portions of your programs.
- Use access attributes [public, protected, private] to control the
visibility of names.
- Be aware of the role of packages and of the import statements, though
you will write programs that exist in a single directory [package].
- Document your program by commenting each class, each method, each
data field. Use other comments on variables, loops, computations as
appropriate to facilitate comprehension by a reader.
- Have an understanding of the use of Javadoc [/**..*/, @param, @return]
- Understand different kinds of errors, syntax [ for example, x + 3 = y;
], semantic
[ for example, "0123456".substring(1,3) is "123"], logical [for example,
off-by-1 errors], pragmatic [for example, not reading integers and not
taking into account the possibility of alphabetic data].
- Learn to correct compile-time errors [use line indication
associated to the error message]and run-time errors [use information
about cause and location of error from the stack trace of the error].
-
Define preconditions and postconditions for the methods you write.
-
Define some class invariant for at least some the classes you write.
-
Define the loop invariant for many of the loops you write.
-
Be able to make convincing arguments to show that your code does what it was intended to do.