## CPSC 120 -- Test #2 Review

### Topics

• Machine Representation of Integers (Class notes, handout on twos complement, Lab 5 Prelab and Lab, exercise handouts, Section 2.3 and Appendix B of the text)
• Be able to convert a number in any base to its equivalent base 10 representation.
• Be able to convert a base 10 number to any other base.
• Be able to convert among bases 2 (binary), 8 (octal), and 16 (hexadecimal) without using base 10.
• Be able to find the n-bit (where n is specified) twos complement representation of a base 10 integer (positive or negative).
• Be able to find the base 10 value of a number represented in twos complement.
• Be able to find the largest (and smallest) base 10 unsigned number that can be stored in n-bits; be able to find the largest (and smallest) base 10 signed twos complement number that can be stored in n-bits.
• Be able to add base 2 and twos complement numbers; understand the problem of overflow (what it means and how to recognize it) and be able to demonstrate it.

• Objects and Classes (Sections 4.1-4.5, Labs 5, 6, and 7, class notes and handouts)
• Understand the difference between objects and primitive values, including the difference in how they are stored (directly vs. references).
• Be able to create (instantiate) an object given the type signature of one or more constructors of the appropriate class.
• Be able to use an object appropriately given the type signatures and reasonable documentation for its methods.
• Understand the meaning of the public and private modifiers and when each is appropriate.
• Understand the meaning of encapsulation (related to the idea that an object should be self-governing and how visibility modifiers are used to enforce it.
• Understand the concepts of attributes and behaviors (or operations) of objects and how these relate to instance variables and methods in the classes we write.
• Understand the difference between instance data (variables) and local data (variables).
• Know what a constructor is and how a constructor differs from other methods (when a constructor is executed and other differences).
• Be able to write a class given a description of the capabilities required of it.

• Methods (Sections 4.2-4.4, Labs 5, 6, and 7, class notes and handouts)
• Be able to write a method to perform a given task.
• Understand all components of a method's signature -- public/private, static/instance, return type, method name, formal parameters.
• Understand what it means for a method to return a value, and be able to both write and use such methods. In particular, understand the difference between a method that has void return type and one that returns a value.
• Understand the difference between formal and actual parameters.
• Be able to write methods (including main) that call other methods as appropriate. Understand the difference between calling a method from a client program (when you must use the dot operator on an object, or in the case of a static method, on the class name) and calling a method from the class the method is defined in (when you just use the method name along with its parameter list).
• Understand the purpose of a toString method - what should such a method do and how is the method used.

• Selection Statements and Boolean Expressions (Sections 5.1 - 5.4 of the text plus handouts, labs and prelabs)
• Know how to write if ... else ... statements in their various forms (with no else clause, nested, cascading). Know when you need to use braces!!!
• Know how to write and evaluate boolean expressions using relational operators (such as == and <=) and boolean operators (&&, ||, and !); know that the relational operators such as == work only on primitive data not on objects (to compare objects you must use methods - equals or compareTo).
• Know about the boolean data type -- how to declare a boolean variable and assign the result of a boolean expression to the variable.
• Know how to write a method with a boolean return type.
• Know that the switch statement is another selection statement that can be used when your selection condition is to test to see if a single variable is equal to one of several different possible values (the cases in the switch). Understand the role of the break statement in the switch -- without it once a condition is true all remaining statements in the switch would be executed rather than just the one where the condition is true. You will not have to write a switch statement on the test but you may be asked some general question or given a switch statement and asked something about it.
• Be able to trace code with if statements, switch statements, and boolean expressions to show what it would do (or to determine if it is correct).

• Logic (Handouts - one labeled "Logic" and one labeled "Logic and Programming Exercises")
• Know the logic operators AND, OR, and NOT and both the mathematical and Java symbols for these.
• Be able to construct truth tables for boolean expressions (propositions/ logic statements).
• Know DeMorgan's law of logic - be able to use it both on mathematical statements and in the context of programming
• Be able to show two boolean expressions are equivalent using truth tables.