Selection Statement Chapter 3. A Java Language Program Is a Class A Class has data declarations and methods A Method has statements or instructions to.

Slides:



Advertisements
Similar presentations
ISBN Chapter 3 More Syntax –BNF –Derivations –Practice.
Advertisements

CS 330 Programming Languages 09 / 13 / 2007 Instructor: Michael Eckmann.
A basis for computer theory and A means of specifying languages
Slide 1 Chapter 3 Attribute Grammars. Slide 2 Attribute Grammars Certain language structures cannot be described using EBNF. Attribute grammars are extensions.
Repetition Structures: For Loop Constants CSC 1401: Introduction to Programming with Java Week 5 Wanda M. Kunkle.
Recursion Alice. Repetition In some situations, we don’t know exactly how many times a block of instructions should be repeated. All we know is that repetition.
Chapter 3: Formal Translation Models
Test review. When? Monday 9/27 in class Know Greenfoot How many classes? Top-most classes? What does each button do? Lowest child class?
CS190/295 Programming in Python for Life Sciences: Lecture 1 Instructor: Xiaohui Xie University of California, Irvine.
1 Syntax and Semantics The Purpose of Syntax Problem of Describing Syntax Formal Methods of Describing Syntax Derivations and Parse Trees Sebesta Chapter.
Imperative Programming
CIS Computer Programming Logic
Design Pattern Interpreter By Swathi Polusani. What is an Interpreter? The Interpreter pattern describes how to define a grammar for simple languages,
English Language Arts 7 Paragraphs “The Writing Process”
English Language Arts 7 Paragraphs “The Writing Process”
Object-Oriented Programming (OOP). Implementing an OOD in Java Each class is stored in a separate file. All files must be stored in the same package.
PAGES:51-59 SECTION: CONTROL1 : DECISIONS Decisions.
“The study of algorithms is the cornerstone of computer science.” Algorithms Fall 2011.
ISBN Chapter 3 Describing Syntax and Semantics.
Principles of programming languages 5: An operational semantics of a small subset of C Department of Information Science and Engineering Isao Sasano.
© Jalal Kawash Programming Peeking into Computer Science 1.
Assignment statements using the same variable in LHS and RHS.
JavaScript Syntax and Semantics. Slide 2 Lecture Overview Core JavaScript Syntax (I will not review every nuance of the language)
Parse & Syntax Trees Syntax & Semantic Errors Mini-Lecture.
CSCI/CMPE 4341 Topic: Programming in Python Review: Exam I Xiang Lian The University of Texas – Pan American Edinburg, TX 78539
CPS 506 Comparative Programming Languages Syntax Specification.
Introduction to Yacc Ying-Hung Jiang
Events (Alice In Action, Ch 6) Slides Credit: Joel Adams, Alice in Action CS 120 Lecture September 2012.
Copyright © 2006 Addison-Wesley. All rights reserved. Ambiguity in Grammars A grammar is ambiguous if and only if it generates a sentential form that has.
Chapter 3 Describing Syntax and Semantics
CSCE 121: Introduction to Program Design and Concepts Dr. J. Michael Moore Spring 2015 Set 4: Computation 1 Based on slides created by Bjarne Stroustrup.
Strings See Chapter 2 u Review constants u Strings, concatenation and repetition 1.
1 Printing in Python Every program needs to do some output This is usually to the screen (shell window) Later we’ll see graphics windows and external files.
Repetition Control Structure. Introduction Many applications require certain operations to be carried out more than once. Such situations require repetition.
Paragraphs and Beyond “The Writing Process”. 1. Writing for purpose: Why do we write? 2. The Writing Process. What you need to check for when submitting.
How the Session Works Outline Practical on arrival Talk 1 Reflect on practical Clarify concepts Practical exercises at your own pace Talk 2: Further concepts.
Writing Academic Essay versus Writing Computer Programs.
The Concept The Triangle Inequality Theorem states that any two sides of a triangle when added together will always be larger than the third. EX:
Chapter 5 – Decision Making. Structured Programming Sequence Selection Repetition yesno yes no.
CSCI 3328 Object Oriented Programming in C# Chapter 6: Methods – Exercises 1 Xiang Lian The University of Texas Rio Grande Valley Edinburg, TX 78539
Improving the Crab Mrs. C. Furman August 19, 2010.
English Language Arts 7 Paragraphs “The Writing Process”
Adding and Eating Worms Mrs. C. Furman August 23, 2010.
Pseudocode. Algorithm A procedure for solving a problem in terms of the actions to be executed and the order in which those actions are to be executed.
CMPSC 16 Problem Solving with Computers I Spring 2014 Instructor: Tevfik Bultan Lecture 6: Stepwise refinement revisited, Midterm review.
Review for Test 2 Chapters 5 (start at 5.4), 6.1, , 12, 13, 15.1, Python.
Chapter 3 – Describing Syntax CSCE 343. Syntax vs. Semantics Syntax: The form or structure of the expressions, statements, and program units. Semantics:
Chapter 4 - Finishing the Crab Game
Chapter 4 - Finishing the Crab Game
Functions Chapter 5 CS12 - Computer Programming 1 Chapter 5.
Chapter 3 – Improving the Crab Game
JavaScript Syntax and Semantics
The order in which statements are executed is called the flow of control. Most of the time, a running program starts at the first programming statement,
Control structures Chapter 3.
COMS W1004 Introduction to Computer Science and Programming in Java
CS190/295 Programming in Python for Life Sciences: Lecture 1
The Little Crab Scenario
CMPE 152: Compiler Design September 11/13 Lab
Control Structures: Selection Statement
Coding Concepts (Basics)
Pages:51-59 Section: Control1 : decisions
Object-oriented Design in Processing
Computer Science Core Concepts
Adding Behaviors (methods)
Final Review Bina Ramamurthy 4/5/2019 BR.
Methods, Data and Data Types
Final Review Bina Ramamurthy 4/15/2019 BR.
Control Structures: Selection Statement
Pages:51-59 Section: Control1 : decisions
Presentation transcript:

Selection Statement Chapter 3

A Java Language Program Is a Class A Class has data declarations and methods A Method has statements or instructions to perform the function of the method Statements can be: – Sequence statement; Ex: assignment statement – Selection statement; Ex: if statement – Repetition statement… we will learn it later It is similar to a writing an essay in any language: – Chapters, paragraphs, sentences, etc.

Sequence Statement Assignment statement; Syntax: (structure, format) LHS = RHS; Data = value; Example: gunReloadTime = 5; Semantics: (meaning) Assign gunReloadTime the value of 5

Selection Statement Implementing choices in the design Syntax: if (condition) { // do something } else { // do something else }

Condition How to express / write in Java language the condition for the selection statement? Using relational operators: < > <= >= == !=

Implementing Random Behavior Using random numbers generated by the Greenfoot environment. How to get a random number from the Greenfoot environment? Greenfoot itself is a class. Invoke a class method getRandomNumber (range) Example: percent = Greenfoot.getRandomNumber(100); percent will be assigned a random number between 0-99.

Adding new methods Lets add methods: turnAtEdge() randomTurn() lookForWorm()

10 Concepts Next class….