Fundamentals of Software Development ISlide 1 Recap: Key ideas in WordGames Defining a classDefining a class Extending a class versus implementing an interfaceExtending.

Slides:



Advertisements
Similar presentations
Programming with App Inventor Computing Institute for K-12 Teachers Summer 2012 Workshop.
Advertisements

C++ Statements represent the lowest-level building blocks of a program and it may be like:. A simple statement is a computation terminated by a semicolon.
Fundamental Programming Structures in Java: Control Flow, Arrays and Vectors.
Fundamentals of Software Development 1Slide 1 Today’s Summary Statements: Conditionals (if-then-else)Statements: Conditionals (if-then-else) Investigated.
Chapter 7 User-Defined Methods. Chapter Objectives  Understand how methods are used in Java programming  Learn about standard (predefined) methods and.
July 13 th.  If/ Else if / Else  Variable Scope  Nested if/else's  Switch statements  Conditional Operator.
Chapter 5 Selection Statements. Topics Controlling program flow selection –if –switch Boolean expressions –boolean primitive type –comparison operators.
CS107 Introduction to Computer Science Loops. Instructions Pseudocode Assign values to variables using basic arithmetic operations x = 3 y = x/10 z =
Fundamentals of Software Development ISlide 1 Recap: Key ideas in WordGames ClassClass –versus instances –Defining –use of fields –Constructors E.g., to.
1 Chapter 4 Language Fundamentals. 2 Identifiers Program parts such as packages, classes, and class members have names, which are formally known as identifiers.
Logical Operators Java provides two binary logical operators (&& and ||) that are used to combine boolean expressions. Java also provides one unary (!)
1 CS 105 Lecture 4 Selection Statements Wed, Jan 26, 2011, 6:05 pm.
Repetition Statements repeat block of code until a condition is satisfied also called loops Java supports 3 kinds of loops: while statement – repeats a.
COMP 14 Introduction to Programming Miguel A. Otaduy May 18, 2004.
Fundamentals of Software Development ISlide 1 Recap: Key ideas in WordGames ClassClass –versus instances –Defining –use of fields –Constructors E.g., to.
1 Conditionals In many cases we want our program to make a decision about whether a piece of code should be executed or not, based on the truth of a condition.
Aalborg Media Lab 23-Jun-15 Software Design Lecture 6 “Conditionals and Loops”
School of Computing Science CMT1000 Ed Currie © Middlesex University 1 CMT1000: Introduction to Programming Ed Currie Lecture 5B: Branch Statements - Making.
C. About the Crash Course Cover sufficient C for simple programs: variables and statements control functions arrays and strings pointers Slides and captured.
1 Chapter 2 Introductory Programs. 2 Getting started To create and run a Java program –Create a text file with a.java extension for the source code. For.
CS 117 Spring 2002 Review for Exam 2 March 6, 2002 open book, 1 page of notes.
1 Arithmetic in C. 2 Type Casting: STOPPED You can change the data type of the variable in an expression by: (data_Type) Variable_Name Ex: int a = 15;
Fundamental Programming Structures in Java: Comments, Data Types, Variables, Assignments, Operators.
Chapter 2 - Java Programming Fundamentals1 Chapter 2 Java Programming Fundamentals.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter Chapter 5 Selection Statements Primitive Type boolean.
Programming Concepts MIT - AITI. Variables l A variable is a name associated with a piece of data l Variables allow you to store and manipulate data in.
Fundamentals of Software Development 1Slide 1 Objects and Names There are two types of things in Java: – –Objects the button that the user just pressed.
JS Arrays, Functions, Events Week 5 INFM 603. Agenda Arrays Functions Event-Driven Programming.
Fruitful functions. Return values The built-in functions we have used, such as abs, pow, int, max, and range, have produced results. Calling each of these.
CSci 125 Lecture 10 Martin van Bommel. Simple Statements Expression followed by semicolon Assignments total = n1 + n2; Function calls printf(”Hello.\n”);
Chapter 4 The If…Then Statement
Primitive Data Types and Operations Identifiers, Variables, and Constants Primitive Data Types Byte, short, int, long, float, double, char, boolean Casting.
Fundamentals of Software Development 1Slide 1 Recap: Key ideas in WordGames Defining a classDefining a class Extending a class versus implementing an interfaceExtending.
2440: 211 Interactive Web Programming Expressions & Operators.
CSCI 3328 Object Oriented Programming in C# Chapter 5: C# Control Statement – Part II UTPA – Fall
Chapter 2 Overview of C++. A Sample Program // This is my first program. It calculates and outputs // how many fingers I have. #include using namespace.
CIS 234: LOOPS Adapted from materials by Dr. Donald Bell, 2000 (updated April 2007)
Fundamental Programming: Fundamental Programming Introduction to C++
If…else statements. Boolean Expressions Boolean expression - An expression whose value is either true or false true = 1 false = 0 Datatype: boolean.
©TheMcGraw-Hill Companies, Inc. Permission required for reproduction or display. Selection Statements Selection Switch Conditional.
Python uses boolean variables to evaluate conditions. The boolean values True and False are returned when an expression is compared or evaluated.
Chapter 7 Selection Dept of Computer Engineering Khon Kaen University.
Control Structures - Selections - Repetitions/iterations (part 2) 1 -Based on slides from Deitel & Associates, Inc. - Revised by T. A. Yang.
Python Primer 1: Types and Operators © 2013 Goodrich, Tamassia, Goldwasser1Python Primer.
Lesson Two: Everything You Need to Know
C++ / G4MICE Course Session 2 Basic C++ types. Control and Looping Functions in C Function/method signatures and scope.
CSCI 171 Presentation 6 Functions and Variable Scope.
Computing and Statistical Data Analysis Lecture 2 Glen Cowan RHUL Physics Computing and Statistical Data Analysis Variables, types: int, float, double,
Quiz 3 is due Friday September 18 th Lab 6 is going to be lab practical hursSept_10/exampleLabFinal/
ICT Introduction to Programming Chapter 4 – Control Structures I.
Advanced Arithmetic, Conditionals, and Loops INFSY 535.
© 2006 Pearson Education 1 Obj: to use assignment operators HW: Prelab Exercises 2 Quiz 3.1 – 3.4 in two class days  Do Now: 1.Read p.144 – 145 (3.4 “more.
In the last lesson we discussed about: Casting Precedence The “=“ used as an assignment operator Made a calculate average program.
Repetition Statements (Loops). 2 Introduction to Loops We all know that much of the work a computer does is repeated many times. When a program repeats.
Chapter 7 Conditional Statements. 7.1 Conditional Expressions Conditions - compare the values of variables, constants and literals using one or more relational.
Array Size Arrays use static allocation of space. That is, when the array is created, we must specify the size of the array, e.g., int[] grades = new int[100];
CMPSC 16 Problem Solving with Computers I Spring 2014 Instructor: Lucas Bang Lecture 11: Pointers.
IST 210: PHP Logic IST 210: Organization of Data IST2101.
1 C++ Programming C++ Basics ● C++ Program ● Variables, objects, types ● Functions ● Namespace ● Tests ● Loops ● Pointers, references.
Copyright © 2014 Pearson Addison-Wesley. All rights reserved. 4 Simple Flow of Control.
Principles of Programming - NI July Chapter 4: Basic C Operators In this chapter, you will learn about: Assignment operators Arithmetic operators.
Recap: Key ideas in WordGames
Java Programming Fifth Edition
Java Language Basics.
Java Primer 1: Types, Classes and Operators
If statement.
Module 2: Understanding C# Language Fundamentals
CMSC 202 Java Primer 2.
CS139 October 11, 2004.
Chapter 2 Programming Basics.
Presentation transcript:

Fundamentals of Software Development ISlide 1 Recap: Key ideas in WordGames Defining a classDefining a class Extending a class versus implementing an interfaceExtending a class versus implementing an interface Classes versus instancesClasses versus instances The use of fieldsThe use of fields Methods, parameters and local variablesMethods, parameters and local variables Blocks and scopeBlocks and scope ConstructorsConstructors –E.g., to initialize fields We will review these ideas in the next several slides Declaring variablesDeclaring variables ExpressionsExpressions StatementsStatements –Assignment –Conditionals –Blocks –Loops (later) We reviewed these ideas previously Now these ideas

Fundamentals of Software Development ISlide 2 Declaring variables We use names (also called variables) to refer to things:We use names (also called variables) to refer to things: –myCheckBox homeURL mobyDick Use the names to ask objects to do things:Use the names to ask objects to do things: –myCheckBox.displayCheck() Every name has a type that must be declared:Every name has a type that must be declared: –CheckBox myCheckBox;Book mobyDick; –double temperature;int weight; Exercise: Declare a variable appropriate for: Storing a person’s age Indicating whether or not Sonia passed her test Referring to a JButton Storing an approximation to PI int age; boolean passed; JButton button1; double pi; Questions?

Fundamentals of Software Development ISlide 3 Expressions Every expression has a type and a valueEvery expression has a type and a value Names (variables) and literals are simple expressionsNames (variables) and literals are simple expressions Expressions can be combined by using operators like:Expressions can be combined by using operators like: –Arithmetic operators: + – * / % –Comparison operators: >= == != –Logical operators: && || ! if ( (temperature > 101) && (bloodPressure > 140) ) { dosage = dosage + 30; } Exercise: Fill in the blanks. In the example below, there are: ___ literals ___ comparison expressions ___ boolean expressions ___ arithmetic expressions ___ assignment expressions Questions?

Fundamentals of Software Development ISlide 4 Assignment statements Exercises: Given the declarations to the right, write statements that:Exercises: Given the declarations to the right, write statements that: –Give age the value 12 age = 12; –Make button1 refer to the same JButton as button2 button1 = button2; –Make button3 refer to a new JButton button3 = new JButton(); –Increment weight by 10 weight = weight + 10; or equivalently: weight += 10; –Sets force appropriately (given mass and acceleration) force = mass * acceleration; –Makes henry wiggle henry.wiggle(); assuming the method’s name is wiggle int age; JButton button1; JButton button2; JButton button3; int weight; double force; double mass; double acceleration; Worm henry; Questions?

Fundamentals of Software Development ISlide 5 Conditional statements The statements executed depend on a conditionThe statements executed depend on a condition –The condition is evaluated left-to- right and may be short-circuited –Note the indentation and curly- brace style in multiple cases if (x < y) { min = x; min = x; } else { min = y; min = y;} if (naomi.winsRace()) { ++ count; ++ count;} if ( (fido != null) && (fido.isAlive() ) { fido.bark(); fido.bark();} if (score >= 90) { grade = ’A’; grade = ’A’; } else if (score >= 80) { grade = ’B’; grade = ’B’; } else { grade = ’C’; grade = ’C’;} Questions?

Fundamentals of Software Development ISlide 6 Blocks Use curly-braces to enclose blocks of codeUse curly-braces to enclose blocks of code –Note the code convention for where to place the curly braces if (x < y) { min = x; min = x; max = y; max = y; } else { min = y; min = y; max = x; max = x;} Questions?