Presentation is loading. Please wait.

Presentation is loading. Please wait.

Introduction to Computer Programming

Similar presentations


Presentation on theme: "Introduction to Computer Programming"— Presentation transcript:

1 Introduction to Computer Programming
CS 126 Lecture 6 Zeke Maier

2 Plan for Today Questions Administrivia Quiz Instance Variables
Conditionals Assignment

3 Questions Boolean backed by 1/0? 3 == true (syntax error) Windows 7…
Recovery.gov Microsoft job cuts

4 Administrivia http://students.cec.wustl.edu/~ejm3/
Lab assignment due Wednesday

5 Method Example Code Pay attention to the coding style!

6 Variables Def: A symbol which can hold a value of a particular type
<dataType> <name>; int count; Variable Instance Variable Defined within a method Defined within a class Can only be accessed within its method Can be accessed anywhere in the class Used as a temporary holder of intermediate values Used to hold values describing the class A symbol which can hold a value of a particular type

7 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); AKA attributes

8 Class Layout A Class is a blueprint for an object Class consists of:
It models something Class consists of: Instance/Data Variables Describe Methods Perform Actions 1 class to model a user, many users Usually, a class represents a person, place, or thing - it is an abstraction of a concept within a computer program. Fundamentally, it encapsulates the state and behavior of that which it conceptually represents. It encapsulates state through data placeholders called member variables; it encapsulates behavior through reusable code called methods. Instance variables: noun Methods: verbs Let’s sketch out a car class

9 Instance Example Code

10 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 } How would we write a method to calculate the abs value for us Now let’s shorten it: double abs(double x) { if (x >= 0) return x; return -x; } How about even vs. odd method else { //Statements to execute if the condition is false }

11 Assignment Lab 1 due Wednesday in Lab Readings Wednesday
AD Chapter 4: KG Notes


Download ppt "Introduction to Computer Programming"

Similar presentations


Ads by Google