Introduction to Computer Programming

Slides:



Advertisements
Similar presentations
Classes And Objects II. Recall the LightSwitch Class class LightSwitch { boolean on = true; boolean isOn() { return on; } void switch() { on = !on; }
Advertisements

AP Computer Science Anthony Keen. Computer 101 What happens when you turn a computer on? –BIOS tries to start a system loader –A system loader tries to.
Chapter 3 DATA: TYPES, CLASSES, AND OBJECTS. Chapter 3 Data Abstraction Abstract data types allow you to work with data without concern for how the data.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter Chapter 4 Defining Your Own Classes.
Object-Based Design/Programming An Informal Introduction and Overview CS340100, NTHU Yoshi.
Road Map Introduction to object oriented programming. Classes
Iteration and Loop Statements Horstmann Chapter 7 Loop statements control repeated execution of a block of statements Each time the statements in the block.
Java An introduction. Example 1 public class Example1 { public static void main (String [] args) { System.out.println (“This is the first example”); int.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter Chapter 4 Defining Your Own Classes.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter Chapter 4 Defining Your Own Classes.
1 Chapter 8 Objects and Classes. 2 Motivations After learning the preceding chapters, you are capable of solving many programming problems using selections,
Lecture 2: Classes and Objects, using Scanner and String.
Chapter 7 Objects and Classes 1 Fall 2012 CS2302: Programming Principles.
5-Aug-2002cse Arrays © 2002 University of Washington1 Arrays CSE 142, Summer 2002 Computer Programming 1
Introduction to Programming David Goldschmidt, Ph.D. Computer Science The College of Saint Rose Java Methods (a.k.a. Functions)
Lecture 2: Introduction to C Programming. OBJECTIVES In this lecture you will learn:  To use simple input and output statements.  The fundamental data.
An Introduction to Java – Part 1 Dylan Boltz. What is Java?  An object-oriented programming language  Developed and released by Sun in 1995  Designed.
Introduction to Computer Programming CS 126 Lecture 4 Zeke Maier.
Introduction to Computer Programming CS 126 Lecture 2 Zeke Maier.
Programming for Beginners Martin Nelson Elizabeth FitzGerald Lecture 6: Object-Oriented Programming.
CMP-MX21: Lecture 4 Selections Steve Hordley. Overview 1. The if-else selection in JAVA 2. More useful JAVA operators 4. Other selection constructs in.
Classes and Objects in Java
BEGINNING PROGRAMMING.  Literally – giving instructions to a computer so that it does what you want  Practically – using a programming language (such.
Objects and Classes Mostafa Abdallah
IT108 Objects and Classes Part I George Mason University Revised 4/3/2012.
Chapter 2 Input, Variables and Data Types. JAVA Input JAVA input is not straightforward and is different depending on the JAVA environment that you are.
Review TEST 2 Chapters 4,5,7. QUESTION For which type of operands does the == operator always work correctly: (a) int, (b) double, or (c) String?
School of Computer Science & Information Technology G6DICP - Lecture 4 Variables, data types & decision making.
1 More data types Character and String –Non-numeric variables –Examples: char orange; String something; –orange and something are variable names –Note.
COMP 110: Introduction to Programming Tyler Johnson Feb 16, 2009 MWF 11:00AM-12:15PM Sitterson 014.
Chapter 9 - Classes with Class Members Class Variables Class Methods How to Access Class Members When to Use Class Members Class Constants Example Program.
C# Classes ISYS 350. Introduction to Classes A class is the blueprint for an object. – It describes a particular type of object. – It specifies the properties.
1 Class 1 Lecture Topic Concepts, Definitions and Examples.
A: A: double “4” A: “34” 4.
Chapter 5 : Methods Part 2. Returning a Value from a Method  Data can be passed into a method by way of the parameter variables. Data may also be returned.
5.1 Basics of defining and using classes A review of class and object definitions A class is a template or blueprint for an object A class defines.
CSCI 51 Introduction to Programming Dr. Joshua Stough February 24, 2009.
1 Lecture # 2. * Introducing Programming with an Example * Identifiers, Variables, and Constants * Primitive Data Types * Byte, short, int, long, float,
Introduction to Programming G50PRO University of Nottingham Unit 6 : Control Flow Statements 2 Paul Tennent
The Essentials of a Java Program JavaMethods An Introduction to Object-Oriented Programming Maria Litvin Gary Litvin Copyright © 2003 by Maria Litvin,
CS 106 Introduction to Computer Science I 02 / 15 / 2008 Instructor: Michael Eckmann.
GC211 Data structure Lecture 3 Sara Alhajjam.
Introduction to Computer Programming
Elementary Programming
ALGORITHMS CONDITIONAL BRANCH CONTROL STRUCTURE
Yanal Alahmad Java Workshop Yanal Alahmad
Lecture 2: Data Types, Variables, Operators, and Expressions
Road Map Introduction to object oriented programming. Classes
CS 302 Week 11 Jim Williams, PhD.
Review Operation Bingo
Class Structure 16-Nov-18.
An Introduction to Java – Part I, language basics
Group Status Project Status.
Introduction to Computer Programming
Introduction to Computer Programming
Introduction to Computer Programming
Class Structure 7-Dec-18.
Introduction to Computer Programming
Class Structure 2-Jan-19.
CS2011 Introduction to Programming I Objects and Classes
CS2011 Introduction to Programming I Methods (I)
Class Structure 25-Feb-19.
CS2011 Introduction to Programming I Selections (I)
Classes, Objects and Methods
Announcements Assignment 2 and Lab 4 due Wednesday.
LOOPS The loop is the control structure we use to specify that a statement or group of statements is to be repeatedly executed. Java provides three kinds.
LCC 6310 Computation as an Expressive Medium
CS 1054: Lecture 2, Chapter 1 Objects and Classes.
Loops CGS3416 Spring 2019 Lecture 7.
Presentation transcript:

Introduction to Computer Programming CS 126 Lecture 6 Zeke Maier

Plan for Today Questions Administrivia Quiz Instance Variables Conditionals Assignment

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

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; 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

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

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

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 } 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 }

Assignment Lab 1 due Wednesday in Lab Readings Wednesday AD Chapter 4: 4.1 - 4.7 KG Notes