CS 152 - Computer Science II

Fall-2008

Classes: TR 12:30 pm - 1:45 pm, Maria Sanford Hall 210
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: TR 10:00am - 12:30pm, or by appointment

Catalog description: Computer Science II [c] Prereq.: CS 151 and MATH 152. Further topics in object-oriented programming: enhancing classes (inheritance, polymorphism) and using Application Programmer Interface. Event-driven programming. Elementary searching and sorting techniques. Introduction to software engineering issues. Recursion.

Prerequisites: CS 151 and MATH 152

Course objectives: Upon successful completion of the course the student will be able to:

Required textbook: Lewis & Loftus, Java Software Solutions: Foundations of Program Design, 5-th Edition, Addison-Wesley, 2007.

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 2 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 (the project descriptions are given on separate pages). All projects must be submitted through the Vista course management system available through CentralPipeline (Student > Blackboard Vista Courses > CS 152) or directly at https://vista.csus.ct.edu/webct/logon/192803068061

Grading: The final grade will be based on projects (60%), 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: It is expected that all students will conduct themselves in an honest manner (see the CCSU Student handbook), 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. However, students are allowed to discuss projects with others and receive debugging help from others.

Tentative schedule of classes, assignments, projects and tests (by week)

Note: Dates will be assigned for all projects due days and tests. Check the schedule regularly for updates!
  1. September 2-11: Object Oriented Design and Arrays
  2. September 16-18: Inheritance
  3. September 23 - October 2: Polymorphism and sorting
  4. October 7-9: Searching
  5. October 14: Test #1 (Inheritance, Polymorphism and Sorting, Chapters 7, 8, and 9).
  6. October 16: Introduction to Graphics
  7. October 21-23: More Graphics
  8. October 28-30: GUI Design
  9. Novemner 4-6: Polygons and polylines
  10. November 11-13: Mouse and Key Events
  11. November 18-20: Adapter classes, event processing
  12. November 20: Test #2 (on applets and GUI applications)
  13. November 25: Exceptions
  14. December 2-4: Recursion
  15. December 9-11: Recursion in graphics
  16. December 18, 11:00am-1:00pm: Final Exam (includes all topics, textbook sections, and programs listed in the syllabus)

Programming Project 1

Not available at this time.

Programming Project 2

Not available at this time.

Programming Project 3

Not available at this time.

Programming Project 4

Not available at this time.

Programming Project 5

Not available at this time.

Programming Project 6

Not available at this time.

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

  1. Applets
  2. GUI applications
  3. Polygons and polylines