Final Exam: Thursday 12/14, 10:30am - 12:30pm
Project 6 is due on December 7
CS 152 - Computer Science II (Section 02)
Fall-2017
Classes: TR 10:50am 12:05pm, Maria Sanford Hall 221
Instructor: Dr. Zdravko Markov, 30307 Maria Sanford Hall, (860)-832-2711,
http://www.cs.ccsu.edu/~markov/, e-mail: markovz at ccsu dot edu
Office hours: MW 9:00am - 10:30am, TR 12:10pm - 2:00pm, or by appointment.
Catalog description: Computer Science II Prereq.: CS 151 and
MATH 152. Further topics in object-oriented programming: inheritance, polymorphism,
and Java interfaces. Event- driven programming. Elementary searching and
sorting techniques. Recursion. Design with UML diagrams. Introduction to
software engineering.
Prerequisites: CS 151 and MATH 152
Course Learning Outcomes:
-
The students will learn to apply inheritance, polymorphism, interfaces
and abstract classes.
-
The students will learn to design, implement, debug and test non-trivial
Java applications (with multiple classes and/or interfaces with methods
requiring advanced algorithms).
-
The students will learn to write Java applets and GUI event driven stand-alone
applications.
-
The students will learn to write recursive methods with integers, arrays,
and graphics.
-
The students will learn to apply, trace, and informally analyze linear
and binary search and selection and insertion sorting algorithms.
-
The students will learn to implement and use linked lists.
Program Educational Objectives: CS 152 is part of the core CS program
and is designed in accordance with the Program Educational Objectives and
the Student Outcomes as specified in the Department
Mission Statement. The course Learning Outcomes support the following
Student Outcomes, wnich are part of the corresponding Program Educational
Objectives:
-
Graduates will have a broad understanding of the fundamental theories,
concepts, and applications of computer science.
-
Outcome (a): An ability to apply knowledge of computing and mathematics
appropriate to the discipline.
-
Outcome (b): An ability to analyze a problem, and identify and define the
computing requirements appropriate to its solution.
-
Outcome (c): An ability to design, implement, and evaluate a computer-based
system, process, component, or program to meet desired needs.
-
Graduates will be prepared for careers in computer science and information
technology.
-
Outcome (k): An ability to apply design and development principles in the
construction of software systems of varying complexity.
Required textbook: Lewis & Loftus, Java Software Solutions:
Foundations of Program Design, 8-th Edition, Addison-Wesley, 2015.
Required software: BlueJ - an integrated Java programming environment
(www.bluej.org)
Class Participation: Regular attendance and active class participation
is expected from all students. If you must miss a test, try to inform the
instructor of this in advance.
Assignments and tests: Reading and problem assignments are listed
under the schedule of classes. Some of the problems will be worked in class.
There will be quizzes, two tests and a final exam.
They will include material from the textbook, the lectures, and the programming
projects.
Programming projects: There will be 6 programming projects
requiring the use of BlueJ to write and run Java programs. The projects
with their due dates are listed below in the schedule of classes. All projects
must be submitted through the class page in Blackboard Learn course management
system at https://ccsu.blackboard.com/.
Grading: The final grade will be based on projects (50%),
quizzes
(10%),
tests (20%), and the final exam (20%), and will
be affected by classroom participation, conduct and attendance. The letter
grades will be calculated according to the following table:
A |
A- |
B+ |
B |
B- |
C+ |
C |
C- |
D+ |
D |
D- |
F |
95-100 |
90-94 |
87-89 |
84-86 |
80-83 |
77-79 |
74-76 |
70-73 |
67-69 |
64-66 |
60-63 |
0-59 |
Unexcused late submission policy: Projects submitted more than
two days after the due date will be graded one letter grade down. Projects
submitted more than a week late will receive two letter grades down. No
submissions will be accepted more than two weeks after the due date.
Honesty policy: The CCSU honor code for Academic Integrity is
in effect in this class. It is expected that all students will conduct
themselves in an honest manner and NEVER claim work which is not their
own. Violating this policy will result in a substantial grade penalty,
and may lead to expulsion from the University. You may find it online at
http://web.ccsu.edu/academicintegrity/.
Please read it carefully.
Students with disabilities: Students who believe they need course
accommodations based on the impact of a disability, medical condition,
or emergency should contact me privately to discuss their specific needs.
I will need a copy of the accommodation letter from Student Disability
Services in order to arrange class accommodations. Contact Student Disability
Services, Willard Hall, 101-04 if you are not already registered with them.
Student Disability Services maintains the confidential documentation of
your disability and assists you in coordinating reasonable accommodations
with your faculty.
Tentative schedule of classes, assignments, projects and tests (by week)
Note: Due dates for classes, assignments, and tests may change
(see also University
Calendar). Additional material may be posted. Check the schedule regularly
for updates!
-
Aug 29, 31, Sep 5, 7: Object Oriented Design and Arrays
-
Topics:
-
Review of Chapter 7: Static variables and methods, Class relationships,
The this reference, Method design
-
Review of Chapter 8: Arrays
-
Dynamic arrays (ArrayList class)
-
Object class
-
Interfaces
-
Lecture Slides: LEWIS_07.ppt,
LEWIS_08.ppt
-
Programs/Exercises:
-
Static variables and methods: SloganCounter.java,
Slogan.java
(use a this reference in the constructor, change variable count
and method getCount() to static/instance)
-
Write class Person that has references to objects of two other classes
- Name and Address. Instantiate several objects of class Person and count
them using a static variable.
-
Arrays: ReverseOrder.java,
LetterCount.java
-
Sorting arrays: array.java
(create a method to print the array and use it to trace sorting, use local
variables and parameters or instance variables and no parameters)
-
ArrayList: Beatles.java
-
Modify array.java
to use ArrayList (need casting or defining type of ArrayList, no need of
counting).
-
Arrays of objects: index.java
-
Object class and Interfaces: Students.java,
Excellent.java,
Ok.java,
students.txt
(Create interface Student and modify classes Excellent and Ok to implement
Student. Is casting needed?)
-
ArrayList of objects: Students.java,
Excellent.java,
Ok.java,
students.txt
(Create an ArrayList and fill it with Excellent and Ok objects. Use the
instanceof
operator and casting to print the array. Define the ArrayList of type
Student. Is casting needed?)
-
Assignments:
-
Read Sections 5.6, 7.1 7.9, 8.1 8.6
-
Run the programs and do the exercises described above
-
Do Exercises: 7.2, 7.3, 7.5, 8.1, 8.4 8.10
-
Do Programming Projects: 8.1, 8.3, 8.5, 8.6
-
Sep 5-6: Take Quiz 1 online in Blackboard
-
Sep 12: Submit Programming
Project 1
-
Sep 12, 14: Inheritance
-
Topics:
-
Creating subclasses and class hierarchies
-
Overriding methods.
-
Abstract methods and classes
-
Lecture Slides: LEWIS_09.ppt
-
Programs/Exercises:
-
Students.java,
Excellent.java,
Ok.java,
students.txt.
Create class Student and make Excellent and Ok subclasses of Student. Use
"super" to call the Student constructor and override the info() method.
- Make class Student abstract with abstract info() and non-abstract name(). In subclasses Excellent and Ok, implement info() by using name().
-
Words.java,
Dictionary.java,
Book.java.
Add a constructor to Dictionary (e.g Dictionary(int pages)), create a new
book class, e.g. Encyclopedia.java with constructor Encyclopedia(int pages,
int articles).
-
Staff.java,
Executive.java,
Worker.java.
Add toString() to print the type of worker (overriding methods) or use
super(name + " (executive)").
-
library.zip
(more elaborated book hierarchy).
-
In library.java create objects from each class and print them.
-
Add constructor to class Book to set up the title and pages (need to add/modify
constructors to other classes).
-
Add more programming books.
-
Assignments:
-
Read Sections 9.1 9.5
-
Run the programs and do the exercises described above
-
Answer Self-Review Questions: 9.1-9.5, 9.9, 9.11-9.15
-
Do Exercises: 9.3-9.5
-
Do Programming Projects: 9.2, 9.3
-
Sep 19, 21, 26: Polymorphism and sorting
-
Topics:
-
Polymorphism (via inheritance and via interfaces)
-
Object reference type casting
-
Using the Comparable interface, Collections and Arrays
-
The sorting problem: selection, insertion and bubble sorts
-
Sorting arrays of objects
-
Lecture Slides: LEWIS_10.ppt
-
Programs/Exercises:
-
Assignment:
-
Read sections 10.1 10.4
-
Run the programs and do the exercises described above
-
Answer Self-Review Questions: 10.1-10.16
-
Do Exercises: 10.1, 10.4
-
Do Programming Projects: 10.1, 10.2, 10.4
-
Sept 26-27: Take Quiz 2 online in Blackboard (Arrays, Inheritance,
Visibility modifiers, Abstract classes, Polymorphism and Sorting, Chapters
8, 9, 10)
-
Oct 3: Submit Programming
Project 2
-
Sept 28: Searching
-
Topics:
-
Linear search
-
Binary search
-
Slides: LEWIS_10.ppt
-
Programs/Exercises:
-
searching-students.zip
(search by name or by grade, evaluate complexity)
-
Use Searching.java and Sorting.java to search a list of 30 random numbers.
Define an object Numb implementing the Comparable interface and use a list
of objects of this type.
-
Assignments:
-
Read Section 10.5 10.6
-
Run the programs and do the exercises described above
-
Answer Self-Review Questions: 10.17-10.19
-
Do Exercises: 10.1, 10.4
-
Do Programming Projects: 10.1, 10.2, 10.4
-
Oct 3: Test #1 (Arrays, Inheritance, Visibility
modifiers, Abstract classes, Polymorphism and Sorting, Chapters 8, 9, 10).
-
Oct 5: Review of Test 1 and Chapters 8, 9, 10
-
Oct 10: Introduction to Graphics
-
Topics:
-
Introduction to graphics
-
Writing simple applets
-
Adding buttons and text fields to applets
-
Writing GUI applications: containers, frames, panels
-
Graphical objects
-
Lecture Slides: LEWIS_02.ppt,
LEWIS_03.ppt,
LEWIS_04.ppt
-
Programs/Exercises:
-
Applets: Einstein.java,
Pi1.java,
Grades.java
-
GUI applications, frames, panels: Authority.java
(add nested panels)
-
Graphical objects:
-
Extend JPanel
-
Define constructor to set the basic properties (e.g. setPreferredSize,
setBackground)
-
Override paintComponent(Graphics page): call super.paintComponent(page)
and draw objects (e.g. page.drawString(...), page.drawLine(...))
-
Assignments:
-
Read Sections 2,7 2.9, 3.9 3.11, 4.6 4.9
-
Run the programs and do the exercises described above
-
Answer Self-Review Questions: 2.42 - 2.47, 3.36 - 3.39, 4.30 - 4.35
-
Do Exercises: 2.16 - 2.18
-
Do Programming Projects: 3.10, 3.11, 4.14 - 4.16
-
Oct 12, 17: More Graphics
-
Topics:
-
Drawing with loops and conditionals
-
Events and listeners
-
Determining event sources
-
More GUI objects: buttons, dialog boxes, check boxes, and radio buttons
-
Lecture Slides: LEWIS_04.ppt,
LEWIS_05.ppt
-
Programs/Exercises:
-
Drawing with loops and conditionals: PiFrame.java,
PiSquare.java
-
Events: PushCounter.java,
PushCounterPanel.java
(add a Clear button with another listener class). Note the nested class
definitions and privite classes.
-
Determining event sources: LeftRight.java,
LeftRightPanel.java
(add buttons directly to LeftRightPanel, implement two listener classes)
-
Dialog boxes: Guess.java
(use class JOptionPane to create dialog boxes for prompting the user)
-
Reading a text field: CopyText.java,
CopyTextPanel.java
(add a listener to the text field, implement some statistics on the input
text, implement Guess.java with a text field)
-
Check boxes and Radio buttons: StyleOptions.java,
StyleOptionsPanel.java,
QuoteOptions.java,
QuoteOptionsPanel.java
(take off the button group, see what the event is)
-
Assignments:
-
Read Sections 5.7 5.8, 6.5 6.6
-
Run the programs and do the exercises described above
-
Oct 24: Submit Programming
Project 3
-
Oct 19: GUI Design
-
Topics:
-
GUI design
-
Layout managers
-
Containment hierarchies
-
Lecture Slides: LEWIS_07.ppt
-
Programs/Exercises:
-
Run layout.zip
-
Add different layouts to LeftRight.java, StyleOptions.java and QuoteOptions.java.
-
Assignments:
-
Read Sections 7.10 7.13
-
Run the programs and do the exercises described above
-
Oct 24: Polygons and polylines
-
Topics: Polygons and polylines
-
Lecture Slides: LEWIS_08.ppt
-
Programs/Exercises:
-
Assigmenent:
-
Read Section 8.7
-
Run the programs and do the exercises described above
-
Answer Self-Review Questions: 8.12-8.27
-
Do Programming Projects: 8.12-8.16
-
Oct 26, 31, Nov 2: Mouse and Key Events
-
Topics: Mouse events and key events.
-
Lecture Slides: LEWIS_08.ppt
-
Programs/Exercises:
-
Mouse events: Dots.java,
DotsPanel.java.
Connect dots with lines, draw dots by dragging the mouse, add a button
to clear the panel, add a button to remove dots, use the distance function.
-
Lines and distances: RubberLines.java,
RubberLinesPanel.java.
Compute the distance from the moving point to the line using Line2D and
Line2D.Double classes and ptLineDist and ptSegDist methods.
-
Key Events: Direction.java,
DirectionPanel.java.
Define different arrow classes that implement an arrow interface and draw
the arrows using polymorphic references)
-
Interactive trigonometry: trigonometry.zip,
(see http://en.wikipedia.org/wiki/Trigonometric_function,
http://en.wikipedia.org/wiki/Arctangent,
http://mathworld.wolfram.com/Collinear.html).
Add an arrow at the end of the line in Angle.java (use the arrow from Direction.java).
-
Drawing and representing graphs: Graph.java,
GraphPanel.java
-
Using graphs: Social
Networks and PageRank, PowerIteration.java
(ses also http://en.wikipedia.org/wiki/Eigenvector)
-
Assignment:
-
Read Sections 8.8 8.9
-
Run the programs and do the exercises described above
-
Answer Self-Review Questions: 8.28-8.31, 8.33, 8.34
-
Do Exercises: 8.12-8.15
-
Do Programming Projects: 8.19-8.23
-
Nov 2-6: Take Quiz 3 online in Blackboard
-
Nov 9: Submit Programming
Project 4
-
Nov 7: Adapter classes, event processing
-
Topics:
-
Extending adapter classes
-
Event processing and polymorphism
-
Lecture Slides: LEWIS_09.ppt,
LEWIS_10.ppt
-
Programs/Exercises:
-
Assignments:
-
Read Sections 9.7, 9.8, 10.7 10.10
-
Run the programs and do the exercises described above
-
Answer Self-Review Questions: 9.23 - 9.30
-
Nov 9: Test #2 (GUI applications)
-
Nov 14: Exceptions
-
Nov 21: Furlough day (No class)
-
Nov 16, 28: Recursion
-
Topics:
-
Recursive programming
-
Recursion versus iteration
-
Recursive functions
-
Recursive data structures, list processing
-
Problem solving
-
Tree/Graph search
-
Lecture Slides: LEWIS_12.ppt
-
Programs/Exercises:
-
Functions: Fact1.java,
Fact2.java,
Fibonacci1.java,
Fibonacci2.java,
implement gcd(a,b): {gcd(a,0)=a; gcd(a,b)=gcd(b,a%b)}
-
Recursive list processing: List.java,
Lists.java
-
Recursive lists: class List {int head; List tail}. List list = new List(1,new
List(2,new List(3,null)));
-
List membership: boolean member (int x, List list) { if (list==null) return
false; else if (x==list.head) return true; else return member(x,list.tail);
}
-
Problem solving: MazeSearch.java,
Maze.java,
Maze1.java
(all solutions),
Farmer.java,
State.java
-
Tree/Graph Search: Path.java,
use rescursive list to store the path,
AllPaths.java,
find the shortest path by iterative deepening
-
Assignments:
-
Read Sections 12.1 12.3
-
Run the programs and do the exercises described above
-
Answer Self-Review Questions: 12.1 - 12.13
-
Do Exercises: 12.1 - 12.8
-
Do Programming Projects: 12.1 - 12.3
-
Dec 7: Submit Programming
Project 6
-
Nov 30, Dec 5: Linked Lists
-
Topics:
-
Collections and data structures
-
Dynamic representations
-
Linked lists
-
Lecture Slides: LEWIS_13.ppt
-
Programs/Exercises: LinkedList.java
-
Define methods size(), get(int index), and set(int index, int item)
-
Add a pointer to the end of the list and rewrite the add method
-
Add a pointer to the previous node (doubly-linked list) and traverse the
list in reverse order
-
Assignments:
-
Read Sections 13.1, 13.2
-
Run the programs and do the exercises described above
-
Answer Self-Review Questions: TBA
-
Do Exercises: TBA
-
Do Programming Projects: TBA
-
Dec 5-6: Take Quiz 4 online in Blackboard
-
Dec 7: Recursion in graphics
-
Thursday 12/14, 10:30am - 12:30pm: Final Exam (includes all topics, textbook sections, and programs listed
in the syllabus except for Graphics)
Programming Project 1
Log on to Blackboard
Learn to see and submit the project.
Programming Project 2
Log on to Blackboard
Learn to see and submit the project.
Programming Project 3
Log on to Blackboard
Learn to see and submit the project.
Programming Project 4
Log on to Blackboard
Learn to see and submit the project.
Programming Project 5
Log on to Blackboard
Learn to see and submit the project.
Programming Project 6
Log on to Blackboard
Learn to see and submit the project.
Test 1 Sample Problems
1) What does the following code do? Assume list is an array of int
values, temp is some previously initialized int value, and c is an int
initialized to 0.
for (int j = 0; j < list.length; j++)
if (list[j] < temp) c++;
a) It finds the smallest value and stores it in temp
b) It finds the largest value and stores it in temp
c) It counts the number of elements equal to the smallest value in
list
d) It counts the number of elements in list that are less than temp
e) It sorts the values in list to be in ascending order
2) An int array stores the following values (in that order): 9,
4, 12, 2, 6, 8, 18
a) Demonstrate how the array is sorted in ascending order by
the Selection sort algorithm. Show the content of the array after each
pass of the outermost loop of the algorithm.
b) Demonstrate how the array is sorted in ascending order by the Insertion
sort algorithm. Show the content of the array after each pass of the outermost
loop of the algorithm.
3) The code below adds elements to an array of objects Numbers and
then prints the array. Add declarations for: Numbers, x, gen, and n, and
define the class Num with the minimum information so that the code below
runs. Hint: gen is an instance of the Random class.
for (int i = 0; i < 10; i++)
{
x = gen.nextInt(100);
Num n = new Num (x);
Numbers.add(n);
}
for (int index = 0; index < Numbers.size();
index++)
System.out.println (Numbers.get(index));
4) The following program generates a list of parts each one defined
with a name and an ID. Then it finds the ID of the part named Part 4
and prints its ID. Define the class Part accordingly. Hint: Part must implement
the Comparable interface (defining properly compareTo) and should also
include a constructor and a method toString().
public class Items
{
public static void main (String[] args)
{
Part [] list = new Part[6];
Part target = new Part ("Part 4",
0);
list[0] = new Part ("Part 1", 123);
list[1] = new Part ("Part 2", 127);
list[2] = new Part ("Part 3", 531);
list[3] = new Part ("Part 4", 131);
list[4] = new Part ("Part 5", 789);
list[5] = new Part ("Part 6", 254);
for (int i = 1; i < list.length;
i++)
if (list[i].compareTo(target)
== 0)
System.out.println(list[i]);
}
}
5) Consider the following partial class definitions:
public class A
{
public int x1;
private int y1;
protected int z1;
}
public class B extends A
{
public int x2;
private int y2;
protected int z2;
}
public class C extends A
{
public int x3;
private int y3;
}
public class D extends B
{
public int x4;
private int y4;
}
a) Draw a diagram showing the class hierarchy.
b) Explain the visibility (accessibility) of all variables.
Test 2 Review Topics
-
GUI applications
-
Objects: frames, panels, dialog boxes, check boxes, and radio buttons
-
Events, event sources: ActionListener, MouseListener, MouseMotionListener
interfaces
-
Event processing using the Adapter class: MouseAdapter, MouseMotionAdapter
(see AnglePanel.java,
Angle.java)
-
Programs: Authority.java,
PiFrame.java,
PiSquare.java,
Guess.java,
CopyText.java,
CopyTextPanel.java,
StyleOptions.java,
StyleOptionsPanel.java,
QuoteOptions.java,
QuoteOptionsPanel.java
-
Polygons and polylines