Fundamentals of Software Development ISlide 1 Recap: Key ideas in WordGames ClassClass –versus instances –Defining –use of fields –Constructors E.g., to.

Slides:



Advertisements
Similar presentations
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.
Advertisements

Fundamental Programming Structures in Java: Control Flow, Arrays and Vectors.
Local Variables and Scope Benjamin Fein. Variable Scope A variable’s scope consists of all code blocks in which it is visible. A variable is considered.
July 13 th.  If/ Else if / Else  Variable Scope  Nested if/else's  Switch statements  Conditional Operator.
Java Programming, 3e Concepts and Techniques Chapter 5 Arrays, Loops, and Layout Managers Using External Classes.
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.
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.
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;
Chapter 2 - Java Programming Fundamentals1 Chapter 2 Java Programming Fundamentals.
The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL Adrian Ilie COMP 14 Introduction to Programming Adrian Ilie June 30, 2005.
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.
CSci 125 Lecture 10 Martin van Bommel. Simple Statements Expression followed by semicolon Assignments total = n1 + n2; Function calls printf(”Hello.\n”);
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.
1 CSC 1401 S1 Computer Programming I Hamid Harroud School of Science and Engineering, Akhawayn University
Hello.java Program Output 1 public class Hello { 2 public static void main( String [] args ) 3 { 4 System.out.println( “Hello!" ); 5 } // end method main.
CSC 1051 – Data Structures and Algorithms I Dr. Mary-Angela Papalaskari Department of Computing Sciences Villanova University Course website:
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.
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.
Loops (cont.). Loop Statements  while statement  do statement  for statement while ( condition ) statement; do { statement list; } while ( condition.
Fundamentals of Software Development ISlide 1 Recap: Key ideas in WordGames Defining a classDefining a class Extending a class versus implementing an interfaceExtending.
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.
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.
© 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.
 In the java programming language, a keyword is one of 50 reserved words which have a predefined meaning in the language; because of this,
CHAPTER 2 PROBLEM SOLVING USING C++ 1 C++ Programming PEG200/Saidatul Rahah.
2: Basics Basics Programming C# © 2003 DevelopMentor, Inc. 12/1/2003.
IF STATEMENTS AND BOOLEAN EXPRESSIONS. BOOLEAN EXPRESSIONS Evaluate to a value of true or false Use relational or equivalence operators Boolean operators.
IST 210: PHP Logic IST 210: Organization of Data IST2101.
CMSC201 Computer Science I for Majors Lecture 05 – Comparison Operators and Boolean (Logical) Operators Prof. Katherine Gibson Prof. Jeremy.
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
CS1010 Discussion Group 11 Week 5 – Functions, Selection, Repetition.
Java Programming Fifth Edition
Chapter 3 Control Statements
University of Central Florida COP 3330 Object Oriented Programming
Java Primer 1: Types, Classes and Operators
University of Central Florida COP 3330 Object Oriented Programming
EGR 2261 Unit 4 Control Structures I: Selection
Boolean Expressions and If
Chapter 3: Understanding C# Language Fundamentals
Conditionals & Boolean Expressions
Conditionals & Boolean Expressions
If statement.
Chapter 8 JavaScript: Control Statements, Part 2
Module 2: Understanding C# Language Fundamentals
CS139 October 11, 2004.
Chapter 2 Programming Basics.
Relational Operators.
Chap 2. Identifiers, Keywords, and Types
HNDIT11034 More Operators.
Presentation transcript:

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

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 aEvery expression has a –type and a value Simple expressionsSimple expressions –Names (variables) and literals are 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 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();} Note the indentation and curly- brace style in multiple cases if (score >= 90) { grade = ’A’; } else if (score >= 80) { grade = ’B’; } else { 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?