Project 6 is due on Thursday, May 15

The Final Exam (includes all topics, textbook sections, and programs listed in the syllabus) is on May 15 at 6:15pm

CS 152 - Computer Science II

Spring-2008

Classes: TR 5:15 pm - 6:30 pm, 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: TR 9:30am - 12:00pm, 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 interactive Java programming environment (www.bluej.org)

Class Participation: Active participation in class is expected of all students. Regular attendance is expected. If you must miss a test, try to inform the instructor of this in advance.

Assignments and tests: Reading and problem assignments are listed below. 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 (CentralPipeline > Student > Vista Courses > CS 152 - 01).

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 placed for all projects due days and tests. Check the schedule regularly for updates!
  1. Object Oriented Design and Arrays
  2. February 12-14: Inheritance
  3. February 19-21: Polymorphism and sorting
  4. February 26-28: Searching
  5. March 4-6: Introduction to Graphics
  6. March 6: Test #1 (Inheritance, Polymorphism and Sorting, Chapters 7, 8, and 9).
  7. March 25-27: More Graphics
  8. April 1-3: GUI Design
  9. April 3: Polygons and polylines
  10. April 8-10: Mouse and Key Events
  11. April 15-17: Adapter classes, event processing
  12. April 17: Test #2 (on applets and GUI applications).
  13. April 22-24: Exceptions
  14. April 29, May 1: Recursion
  15. May 6: Recursion in graphics
  16. May 15 (6:15-8:15p): Final Exam (includes all topics, textbook sections, and programs listed in the syllabus)

Programming Project 1

Write a program in Java according to the following specifications:

Description:

The user enters student names (first and last separated by white space) and grades (integers between 0 and 100) on separate lines. After the and of the input (indicated by entering Ctrl-Z, prompting the user after each line, or using an end of input marker) the program prints the names and grades grouped by grade (excellent: >=90, failure: <60, ok: otherwise) followed by the total number of students, their grade average, and the students with highest and lowest grade. For example, if the user inputs the following data:

John Smith 90
Al Clark   80
Ann Miller 75
Sue Taylor 55
the program prints the following:
Studentts with excellent grades:
John Smith 90

Students with ok grades
Al Clark   80
Ann Miller 75

Students with failure grades:
Sue Taylor 55

Total number of students: 4
Average grade: 75
Highest grade: John Smith 90
Lowest grade: Sue Taylor 55

Restrictions: Use an ArrayList of objects to store the student records. Define a class Student that represent a student record (student name and grade). Compile and run the program using BlueJ.

Documentation: Run your program and make sure it is designed  and works exactly as described above. Then add your name in the beginning of the code as a comment. Add also comments to explain the classes and methods used. Note that comments and the way you format your program will be graded too.

Submission: Submit the following files as attachments through CentralPipeline > Student > Vista Courses > CS 152 > Project 1:

  1. The sources of all classes used.
  2. A screen copy (an MS Word file with the image included) of the BlueJ Programs window showing all classes used with the "uses" relations between them.
  3. A screen copy or a text file with the content of the BlueJ Terminal Window showing an example run of your program with at least 5 student records including all three types of grades.

Programming Project 2

Write a program in Java according to the following specifications:

Description:

The program reads a file with student names (first and last separated by white space) and grades (integers between 0 and 100) on separate lines. Then the program prints the student names and grades sorted by first name, by last name or by grade. The type of sorting (by grade, first name or last name) is specified by the user. For example, if the input file includes the following data:

John Smith   90
Sarah Barnes 75
Mark Riley   80
Laura Getz   72
Larry Smith  95
Frank Phelps 75
Mario Guzman 60
Marsha Grant 85
the program proceeds as follows (the user answer is "l", that is sort by last name):
Sort by first name (f), last name (l), or grade (g)? l

Sarah Barnes 75
Laura Getz   72
Marsha Grant 85
Mario Guzman 60
Frank Phelps 75
Mark Riley   80
John Smith   90
Larry Smith  95

If the user answer is "g", then the program prints:
Larry Smith  95
John Smith   90
Marsha Grant 85
Mark Riley   80
Sarah Barnes 75
Frank Phelps 75
Laura Getz   72
Mario Guzman 60
Restrictions and implementation: Use an array of objects to store the student records. Define a class Student that represents a student record (student's first name, last name and grade) and implements the Comparable interface. Use the bubble sort algorithm for sorting objects. Compile and run the program using BlueJ. Hint: Define a variable in class Student to represent the type of sorting and pass its value (e.g. int 0,1, or 2) as a parameter to the Student constructor. Then use it in the compareTo method to compare first names, last names, or grades respectively.

Documentation: Run your program and make sure it is designed  and works exactly as described above. Then add your name in the beginning of the code as a comment. Add also comments to explain the classes and methods used. Note that comments and the way you format your program will be graded too.

Submission: Submit the following files as attachments through CentralPipeline > Student > Vista Courses > CS 152  > Project 2:

  1. The source code (.java) of all classes used.
  2. The input file with student names and grades that you used to test the program.
  3. A screen copy (an MS Word file with the image included) of the BlueJ Programs window showing all classes used with the relations between them.
  4. A screen copy or a text file with the content of the BlueJ Terminal Window showing an example run of your program.

Programming Project 3

Write a program in Java following the specifications of programming project 5.39 (Lewis&Loftus, page 290). Implement only the word count statistics and instead of those specified in the project use the following GUI objects (see CopyTextPanel.java): Make your application run in a window (JFrame) and use proper backgrounds and colors to make all objects clearly visible.

Extra credit (maximum 5 points) will be given for additional statistics (for example, maximum, minimum or average word size, number of numeric tokens, word frequencies etc.).

Documentation: Run your program and make sure it compiles without errors and works as described above. Then add your name in the beginning of the code as a comment. Add also comments to explain the classes and methods used. Note that comments and the way you format your program will be graded too.

Submission: Submit the following files as attachments through CentralPipeline > Student > Vista Courses > CS 152 > Project 3:

  1. The source code (.java) of all classes used.
  2. A screen copy (an MS Word file with the image included) of the BlueJ Programs window showing all classes used with the relations between them.
  3. A screen copy showing an example run of your program.



Programming Project 4

Write a graph drawing program in Java. Use the program discussed in class (Graph.java, GraphPanel.java) and make the following changes and additions: Extra credit (maximum 5 points) will be given for computing the prestige score of the graph nodes. Use the power iteration algorithm described in Social Networks and PageRank. See the example of power iteration PowerIteration.java. For more information about matrices see http://mathworld.wolfram.com/Matrix.html and for vectors and norms see http://mathworld.wolfram.com/VectorNorm.html. You may also use JAMA (Java Matrix Package) from http://math.nist.gov/javanumerics/jama/.

Documentation: Run your program and make sure it compiles without errors and works as described above. Then add your name in the beginning of the code as a comment. Add also comments to explain the classes and methods used. Note that comments and the way you format your program will be graded too.

Submission: Submit the following files as attachments through CentralPipeline > Student > Vista Courses > CS 152 > Project 4:

  1. The source code (.java) of all classes used.
  2. A screen copy (an MS Word file with the image included) of the BlueJ Programs window showing all classes used with the relations between them.
  3. A screen copy showing an example run of your program including the graph panel and the terminal window output with the adjacency matrix or the prestige score of the nodes.

Programming Project 5

Use the program you created for Project 2 and make the following changes and additions: Documentation: Run your program and make sure it compiles without errors and works as described above. Then add your name in the beginning of the code as a comment. Add also comments to explain the classes and methods used. Note that comments and the way you format your program will be graded too.

Submission: Submit the following files as attachments through CentralPipeline > Student > Vista Courses > CS 152  > Project 5:

  1. The source code (.java) of all classes used.
  2. A screen copy (an MS Word file with the image included) of the BlueJ Programs window showing all classes used with the relations between them.
  3. Terminal window copies demonstrating each exception as well as runs without exceptions (prepare and also submit all text inputs files needed).

Programming Project 6

Extend the graph drawing program you created for Project 4 making the following changes and additions: Extra credit (maximum 5 points) will be given for extending the program so that it prints all possible paths from node X to node Y. Hint: see AllPaths.java

Documentation: Run your program and make sure it compiles without errors and works as described above. Then add your name in the beginning of the code as a comment. Add also comments to explain the classes and methods used. Note that comments and the way you format your program will be graded too.

Submission: Submit the following files as attachments through CentralPipeline > Student > Vista Courses > CS 152  > Project 6:

  1. The source code (.java) of all classes used.
  2. A screen copy (an MS Word file with the image included) of the BlueJ Programs window showing all classes used with the relations between them.
  3. Screen copies showing example runs of your program including graph panel and terminal window outputs.

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.length; 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