CS 15-111
Exam Two
Study Topics

The Structure of the Exam is as follows The Best way to study for the test is to read the lecture notes, classwork and review lab assignments. Given below is a sample set of questions. Read the following Material:
Lecture Notes:
Lecture 08- The Set Class
     - know the definition of a set, how to write new constructors and methods
Lecture 09 - Linear and Binary Search
     - Study the algorithm for linear and binary search, what are their complexities, what are the preconditions under each one can be applied
Lecture 10 -  Sorts
     - study the bubble sort and selection sort algorithms, write 3 versions of the bubble sort algorithm, why is selection sort better than bubble sort, what is quick sort, what are the complexities of each algorithm, sometimes quick sort is worse than the other two, when?
Lecture 11 - IO
    - study the ways to read input from keyboard, and from files, how do we write data to screen and external files. Undersand the process in each instance.
Lecture 12 - Inheritance and Polymorphism
    - why is inheritance important. Design an animal class and show how you can derive new classes, cow and rabbit. (use at least one constructor, one instance variable, one method in each)

TextBook References
pages 435, 45, 32, 35, 37, 38, 39, 40, 46-50,....

Lab Skills
1. How to design a new class (eg:set) and write constructors, and methods (lab3)
2. How to read a file into an array, manipulate (search, sort) and write output to a file.(lab4)

MULTIPLE CHOICE
The following topics will be covered in this section. Know the definitions of class, object, methods, public, private, program, ,model., library, references, messages, identifier, java byte code, String objects, signature, prototype, assignment statement, varaible, constructor, new operator, interactive data, disk files, reading from a disk file, writing to a disk file, exceptions, network computing, static methods, primitive data types, base class, inheritance, multiple inheritance, super, derived class etc.

WRITE NEW METHODS
1. Consider the Set class considered in lab3. Add a new constructor that will take one argument(int array) and create a set using the values.
2. Add a new method to the Set class, average, that returns the average of the set of integers.
3. Design a class Circle, with the following. 2 constructors, accessor methods, getCenter, getRadius, area, resize
3. Design a new class, Account with instace variables, balance, accountNumber, and methods deposit, withdraw, balanceInquiry
    and at least two constructors. Derive a new class, mutualFund from Account class.

TRACE THE CODE
1. . What is the purpose of the following method?
     boolean double foo(int x) {
          return (x > 0) ;
    }
2.   What is the purpose of the following method?
     public void printFile(File f){
       try {
        FileOutputStream fstream = new FileOutputStream(f);
        PrintStream target = new PrintStream(fstream);
     for (int i=0;i<array.size();i++)
         target.println(array.elementAt(i));
       }
       catch (FileNotFoundException e) {
   System.out.println("File not found.");
  }
 
    }
 
 


 
 
 

©Copyright 2001 Ananda Gunawardena. All rights reserved.

This document was last updated on 08/15/01 23:22:56