110 likes | 128 Views
This lecture covers instance variables, conditionals, and assignments in computer programming. Topics include class layout, instance variables, conditional statements, and an introduction to the coding style. Relevant code examples and resources are provided.
E N D
Introduction to Computer Programming CS 126 Lecture 6 Zeke Maier
Plan for Today • Questions • Administrivia • Quiz • Instance Variables • Conditionals • Assignment
Administrivia • http://students.cec.wustl.edu/~ejm3/ • Lab assignment due Wednesday
Method Example Code • http://students.cec.wustl.edu/~ejm3/CS126/web/code.html#instance • Pay attention to the coding style!
Variables • Def: A symbol which can hold a value of a particular type <dataType> <name>; int count;
Instance/Data Variables • How do we create an instance variable? <dataType> <name>; int count; • Which variable is the instance variable? class Student { String name; public static void main(String args[]) { } void printName() { String fullName = “Mr./Ms. ” + name; System.out.println(“Name: ” + name); } }
Class Layout • A Class is a blueprint for an object • It models something • Class consists of: • Instance/Data Variables • Describe • Methods • Perform Actions
Instance Example Code • http://students.cec.wustl.edu/~ejm3/CS126/web/code.html#instance
Conditional Statements • Allows us to change the behavior of the program based on certain conditions • Example: absolute value If (condition) { //Statements to execute if the condition is true } else { //Statements to execute if the condition is false }
Assignment • Lab 1 due Wednesday in Lab • Readings • Wednesday • AD Chapter 4: 4.1 - 4.7 • KG Notes