Take Final Exam in class on December 11, 1:00pm-3:00pm
Project 6 was due on December 2
CS 152 - Computer Science II
Fall-2019
Classes: MW 1:40pm - 2:55pm, 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 4:30pm-6:00pm, TR 1:30pm-3:00pm
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.
-
Design, implement, debug and test non-trivial Java applications
(with multiple classes and/or interfaces with methods requiring
advanced algorithms).
-
Write graphics and GUI event driven programs.
-
Write recursive methods with integers, arrays, and graphics.
-
Apply, trace, and informally analyze linear and binary search and
selection and insertion sorting algorithms.
-
Implement and use linked lists.
Required textbook: Lewis & Loftus, Java Software Solutions:
Foundations of Program Design, 9-th Edition, Addison-Wesley, 2017.
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 28, Sep 4, 9: 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: Chapter7,
Chapter8
-
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)
- Create an array to store the Slogan objects and print it after creating all objects. Make intance variable phrase static and explain the changes in the output.
-
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 9-10: Take Quiz 1 online in Blackboard
-
Sep 16: Submit Programming
Project 1
-
Sep 11, 16: Inheritance
-
Topics:
-
Creating subclasses and class hierarchies
-
Overriding methods.
-
Abstract methods and classes
-
Lecture Slides: Chapter9
-
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 18, 23, 25: 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: Chapter10
-
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
-
Sep 25-29: Take Quiz 2 online in Blackboard (Arrays, Inheritance,
Visibility modifiers, Abstract classes, Polymorphism and Sorting, Chapters
8, 9, 10)
-
Oct 2: Submit Programming
Project 2
-
Sep 30: Review for Test 1 (Arrays, Inheritance, Visibility
modifiers, Abstract classes, Polymorphism and Sorting, Chapters 8, 9, 10)
-
Oct 2: Test 1
-
Oct 7: Searching
-
Topics:
-
Linear search
-
Binary search
-
Slides: Chapter10
-
Programs/Exercises:
-
searching-students.zip
(search by name or by grade, evaluate complexity by counting the calls to equals)
-
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 9: Introduction to Graphics
-
Topics:
-
JavaFX API
-
Basic shapes and coordinate system
-
Hierarchy of scene elements
-
Application, Stage, Scene, Group classes
-
Lecture Slides: Chapter3
-
Programs/Exercises:
- Run JavaFX application from command line:
Hello.java
-
Writing a GUI application (theatre analogy):
- Extend Application class
- Define the start method
- Create scene elements (e.g. text, shapes)
- Create a group of elements
- Create a scene with the group
- Set the scene on the stage and show the stage
- Examples: HelloJavaFX.java,
Snowman.java
- Adding graphical elements with loops, main and launch methods:
PiPolygon.java
-
Assignments:
-
Read Sections 3.9 3.11
-
Run the programs and do the exercises described above
-
Answer Self-Review Questions: 3.36 - 3.47
-
Do Exercises: 3.14 - 3.19
-
Do Programming Projects: 3.10, 3.11
-
Oct 14, 16, 21: More Graphics
-
Topics:
-
Drawing with loops and conditionals
-
Graphic transformations
-
Events, event handler (method or class implementing the EventHandler interface)
-
Determining event sources
- Layouts: FlowPane, GridPane, HBox, VBox
-
More GUI objects: text fields, check boxes, and radio buttons
-
Lecture Slides: Chapter4,
Chapter5,
Chapter6
-
Programs/Exercises:
-
Drawing with loops and conditionals: PiRandom.java,
Boxes.java.
-
Graphic transformations:
RobotFace.java,
Robots.java.
-
Events, event handlers: PushCounter.java
(add a Clear button).
-
Using EventHandler interface: PushCounter1.java
(add a Clear button using an interface). Note the use of a private nested class and generic type <ActionEvent>.
-
Determining event sources: LeftRight.java
(use a single handler for both buttons or a separate handler for each button, implement it with EventHandler).
- Layouts: PushCounter2.java (change layout panes FlowPane, GridPane, HBox, VBox).
-
Text fields: FahrenheitConverter.java,
FahrenheitPane.java
(implement FahrenheitPane in class Fahrenheit: Fahrenheit.java,
add Compute button, add Clear button).
-
Radio buttons: QuoteOptions.java,
QuoteOptionsPane.java
(remove buttons from ToggleGroup, change layout VBox and HBox, implement QuoteOptionsPane in QuoteOptions class).
-
Check boxes: StyleOptions.java,
StyleOptionsPane.java
(use the EventHandler interface).
-
Assignments:
-
Read Sections 4.6 - 4.9, 5.7 5.10, 6.5 6.6
-
Run the programs and do the exercises described above
-
Oct 23: Submit Programming
Project 3
-
Oct 23: Polygons and polylines
-
Topics: Polygons and polylines
-
Lecture Slides: Chapter8
-
Programs/Exercises:
-
Assigmenent:
-
Read Section 8.7
-
Run the programs and do the exercises described above
-
Answer Self-Review Questions: 8.25-8.27
-
Do Programming Projects: 8.12-8.16
-
Oct 28, 30, Nov 4: Mouse and Key Events
-
Topics: Mouse events and key events.
-
Lecture Slides: Chapter7
-
Programs/Exercises:
-
Mouse events, removing object from the scene: Dots.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.
-
Interactive trigonometry (lines, distances, angles, graphic transformations): ClickDistance.java,
RubberLines.java,
Lines.java.
Add a button to delete rubber lines by clicks (use the distance from Lines), attach the arrowhead to the end of the moving line.
-
Key Events: Direction.java
(set limits for moving the arrow).
-
Drawing and representing graphs: Graph.java.
Add an arrowhead to the edges, add a button to remove nodes and edges.
-
Using graphs: Social
Networks and PageRank, PowerIteration.java
(ses also http://en.wikipedia.org/wiki/Eigenvector)
-
Assignment:
-
Read Sections 7.10 7.12
-
Run the programs and do the exercises described above
-
Answer Self-Review Questions: 7.28-7.33
-
Do Exercises: 7.18-7.19
-
Do Programming Projects: 7.10-7.12
-
Oct 30-Nov 3: Take Quiz 3 (GUI Applications) online in Blackboard
-
Nov 6: Submit Programming
Project 4
-
Nov 6: Test 2 (Review Topics)
-
Nov 11: Exceptions
-
Nov 13, 18, 20: Recursion
-
Topics:
-
Recursive programming
-
Recursion versus iteration
-
Recursive functions
-
Recursive data structures, list processing
-
Problem solving
-
Tree/Graph search
-
Lecture Slides: Chapter12
-
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: 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.15
-
Do Exercises: 12.1 - 12.8
-
Do Programming Projects: 12.1 - 12.3
-
Dec 2: Submit Programming
Project 6
-
Nov 25, Dec 2: Linked Lists
-
Topics:
-
Collections and data structures
-
Dynamic representations
-
Linked lists
-
Lecture Slides: Chapter13
-
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: 13.1 - 13.9
-
Do Exercises: 13.1 - 13.5
-
Do Programming Projects: 13.1 - 13.4
-
Dec 2-3: Take Quiz 4 online in Blackboard
-
Dec 4: Recursion in graphics
-
Wednesday, December 11, 1:00pm-3:00pm: 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.
Solution:
Problem_3.java,
Num.java.
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().
Solution:
Items.java
Part.java.
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.
GUI Review Topics
- Basic shapes and coordinate system
- Application, Stage, Scene, Group classes:
HelloJavaFX.java
- Hierarchy of scene elements: Snowman.java
- Drawing with loops and conditionals: Boxes.java
- Graphic transformations: RobotFace.java,
Robots.java
- Events, event handlers: PushCounter.java
- Using EventHandler interface: PushCounter1.java
- Determining event sources: LeftRight.java
- Layouts (FlowPane, GridPane, HBox, VBox): PushCounter2.java
- Text fields: Fahrenheit.java
- Radio buttons: QuoteOptions.java,
QuoteOptionsPane.java
- Check boxes: StyleOptions.java,
StyleOptionsPane.java
- Polygons and polylines: RegularPolygon.java,
RandomPolygon.java
- Mouse and key events: Dots.java,
ClickDistance.java,
RubberLines.java,
Lines.java,
Direction.java