CS 1713 Week 6:
Review and Exam 2
- Review concepts covered during the first part of the course.
- Practice writing classes and methods.
No reading this week
Reminder: Exam 2 this week
- Most of chapters 1 through 8.5 of textbook
- Lectures Weeks 1-5
- Laboratories 1 through 3
- Case studies 1 through 9
About 3/4 of the exam will concern Weeks 3-5. The rest will involve
general Java programming that you should have learned before this course.
Types of problems that you can expect on the exam:
- Questions about object-oriented terminology: The relevant concepts are:
- Class - a blueprint for an object. (A class definition reserves
no memory, rather it says how objects of a certain kind should be created
and what they can do.)
- Object - has state and behavior
- Instantiate - create a object from the blueprint (using
- Constructor - specifies how the object should be set up
when it is created. (The constructor has the same name as the class name.)
- Variable - name for a memory location that holds a particular
type of object or value.
- Method - group of programming statements that is given
a name. (Methods define the actions that an object can take.)
- Accessor method - a type of method that gets information
about an object, but does not change its state.
- Modifier method - a type of method that can change the internal
state of an object in some way.
- Attribute or field - contains internal state information of an object.
- Interface - a collection of constants and abstract methods
- public - indicates that an identifier can be accessed outside of the class
in which it is defined.
- private - indicates that an identifier can only be accessed inside the class
in which it is defined.
- implements - indicates that a class has a certain collection of public methods.
- extends - indicates that a class inherits properties of another class.
- Client code - code that creates an object and/or asks it
to do something.
- Design and implement a class.
- See Recitation 4, Part 1, Problem 3 for an example.
- Complete partially written class definitions.
- Write statements to instantiate objects and call methods of an
already written class to solve a problem.
- Determine appropriate fields or methods for a class definition
from a word problem.
- Diagram the state of program variables: For example, draw an
accurate schematic of the program variables after the following code segment
has been executed:
int x = 3;
y = x;
String z = new String("Apple");
String w = new String("Apple");
String v = new String("Pear");
String u = z;
z = v;
Rules for drawing diagrams:
- Each variable is represented by a named box on the left side of the diagram that can contain several values.
- For primitive variables, put the value of the variable in a box.
When the value of the variable changes, put a single line through the old
value and insert the new value.
It should be possible to see all the values that the variable had.
- For reference variables (variables that corresponds to objects, including arrays),
draw an arrow from the box to the corresponding object.
When the value of the variable changes, put hash marks on the old arrow and draw a new arrow.
- Put objects (including arrays) on the right side of the diagram.
- An array is represented by a vertical list of boxes, each corresponding to an element of the array.
These boxes are treated as unnamed variables.
- An object is represented by a rectangle containing information about the attributes of the object.
Each attribute is represented the same way as with a variable, with a name and a box.
You can find more problems of this type here.
- Understand and know how to use the String methods:
length, charAt, indexOf, and substring.
- Be able to code or trace using the three different types of loops
(for, while, and do).
- Use loops with arrays.
- Understand common loop errors such as the fence post or infinite loop.
- Be able to code using arrays of primitive types or arrays of strings, or arrays of objects.
- Using arrays whose underlying type is an interface (as in gcs02).
- Understand how to pass an array as a parameter to a method.
- Understand how to use an array as a field within a class.
- Find the sum or average of the elements in an array or the maximum or minimum element in an array.
- Other types of problems:
- Write a method to do X.
- Write a code segment to do X.
- Determine what a code segment does including evaluating expressions.
- Tracing of
if-else can be found in
Practice Problems #2
Additional practice problems are available from the recitation