Objects, If, Routines. Creating Objects an object is a fundamental software element that has a state and a set of behaviors. Ex: bank account or student.

Slides:



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

If Statements, Try Catch and Validation. The main statement used in C# for making decisions depending on different conditions is called the If statement.
Flow of Control Usually the order of statement execution through a method is linear: one after another flow of control: the order statements are executed.
CSE 1301 Lecture 5B Conditionals & Boolean Expressions Figures from Lewis, “C# Software Solutions”, Addison Wesley Briana B. Morrison.
Python Programming Language
CSCI 51 Introduction to Programming Dr. Joshua Stough February 10, 2009.
10-Jun-15 Just Enough Java. Variables A variable is a “box” that holds data Every variable has a name Examples: name, age, address, isMarried Variables.
Flow of Control (1) : Logic Clark Savage Turner, J.D., Ph.D. Some lecture slides have been adapted from those developed.
1 Chapter 4 Language Fundamentals. 2 Identifiers Program parts such as packages, classes, and class members have names, which are formally known as identifiers.
Conditions What if?. Flow of Control The order of statement execution is called the flow of control Unless specified otherwise, the order of statement.
Python (yay!) November 16, Unit 7. Recap We can store values in variables using an assignment statement >>>x = We can get input from the user using.
ECE122 L7: Conditional Statements February 20, 2007 ECE 122 Engineering Problem Solving with Java Lecture 7 Conditional Statements.
Python November 18, Unit 7. So Far We can get user input We can create variables We can convert values from one type to another using functions We can.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Java Software Solutions Foundations of Program Design Sixth Edition by Lewis.
1 Random numbers Random  completely unpredictable. No way to determine in advance what value will be chosen from a set of equally probable elements. Impossible.
Boolean Expressions and If Flow of Control / Conditional Statements The if Statement Logical Operators The else Clause Block statements Nested if statements.
COMP 110 Introduction to Programming Mr. Joshua Stough September 19, 2007.
Quiz 1 Exam 1 Next Week. Nested if Statements if (myGrade >= 80) if (myGrade >= 90) cout
Chapter 5 Conditionals and Loops. © 2004 Pearson Addison-Wesley. All rights reserved2/33 Conditionals and Loops Now we will examine programming statements.
Chapter 9 IF Statement Bernard Chen. If Statement The main statement used for selecting from alternative actions based on test results It’s the primary.
C++ / G4MICE Course Session 3 Introduction to Classes Pointers and References Makefiles Standard Template Library.
NMED 3850 A Advanced Online Design January 26, 2010 V. Mahadevan.
Branching and Conditions CSIS 1595: Fundamentals of Programming and Problem Solving 1.
C Programming Tutorial – Part I CS Introduction to Operating Systems.
Programming in Java (COP 2250) Lecture 11 Chengyong Yang Fall, 2005.
PAGES:51-59 SECTION: CONTROL1 : DECISIONS Decisions.
© 2005 Lawrenceville Press Slide 1 Chapter 5 Relational Operators Relational OperatorMeaning =greater than.
Introduction to Computer Systems and the Java Programming Language.
If statements while loop for loop
Flow of Control Part 1: Selection
Session Three Review & Conditional Control Flow. Java File Hierarchy Projects Packages Classes Methods.
Copyright © 2012 Pearson Education, Inc. Lab 8: IF statement …. Conditionals and Loops.
If…else statements. Boolean Expressions Boolean expression - An expression whose value is either true or false true = 1 false = 0 Datatype: boolean.
Lecture 4 Control Structures MIT – AITI What are Control Structures? Control structures are a way to alter the natural sequence of execution in.
1 Week 6 Branching. 2 What is “Flow of Control”? l Flow of Control is the execution order of instructions in a program l All programs can be written with.
CSE 1301 Lecture 8 Conditionals & Boolean Expressions Figures from Lewis, “C# Software Solutions”, Addison Wesley Richard Gesick.
Introduction to Java Java Translation Program Structure
CSC 110 Using Python [Reading: chapter 1] CSC 110 B 1.
1 EMT 101 – Engineering Programming Dr. Farzad Ismail School of Aerospace Engineering Universiti Sains Malaysia Nibong Tebal Pulau Pinang Week 2.
BEGINNING PROGRAMMING.  Literally – giving instructions to a computer so that it does what you want  Practically – using a programming language (such.
Lecture 7: Making Decisions Professor: Dr. Miguel Alonso Jr. Fall 2008 CGS2423/COP1220.
Python 101 Dr. Bernard Chen University of Central Arkansas PyArkansas.
Conditional Loops CSIS 1595: Fundamentals of Programming and Problem Solving 1.
School of Computer Science & Information Technology G6DICP - Lecture 4 Variables, data types & decision making.
Think Possibility 1 Iterative Constructs ITERATION / LOOPS C provides three loop structures: the for-loop, the while-loop, and the do-while-loop. Each.
Controlling Program Flow with Decision Structures.
Variables  A piece of memory set aside to store data  When declared, the memory is given a name  by using the name, we can access the data that sits.
Chapter 2: Fundamental Programming Structures in Java Adapted from MIT AITI Slides Control Structures.
 2003 Prentice Hall, Inc. All rights reserved. 1 Basic C++ Programming.
Primitive Data Types. int This is the type you are familiar with and have been using Stores an integer value (whole number) between -2,147,483,648 (-2.
Lesson 4: Introduction to Control Statements 4.1 Additional Operators Extended Assignment Operators –The assignment operator can be combined with the.
Instructor: Alexander Stoytchev CprE 185: Intro to Problem Solving (using C)
 By the end of this section you should be able to: ◦ Differentiate between sequence, selection, and repetition structure. ◦ Differentiae between single,
CCSA 221 Programming in C CHAPTER 3 COMPILING AND RUNNING YOUR FIRST PROGRAM 1 ALHANOUF ALAMR.
Basic concepts of C++ Presented by Prof. Satyajit De
CIS3931 – Intro to JAVA Lecture Note Set 2 17-May-05.
COMP 14 Introduction to Programming
C Programming Tutorial – Part I
Operator Precedence Operators Precedence Parentheses () unary
Boolean Expressions and If
Conditionals & Boolean Expressions
Outline Boolean Expressions The if Statement Comparing Data
CS139 October 11, 2004.
Comparing Data & the ‘switch’ Statement
Comparing Data & the ‘switch’ Statement
CprE 185: Intro to Problem Solving (using C)
Just Enough Java 17-May-19.
C++ Basics CSci 107. A C++ program //include headers; these are modules that include functions that you may use in your //program; we will almost always.
Presentation transcript:

Objects, If, Routines

Creating Objects an object is a fundamental software element that has a state and a set of behaviors. Ex: bank account or student. a variable holds a primitive value (integer, float, double) or a reference to an object use the new operator to create an object

Random generator // creates a reference with the address of the object generator = new Random // calls the Random constructor to set up the new object numStudents 35 numStudents = 35; generator GradingSystem gs; GradingSystemgs= new GradingSystem(); Two class systems: Run main object (Read about this in Ch )

Two-way and Multi-branch If statements If-else Statement if ( condition ) statement1; else statement2; If the condition is true, statement1 is executed; if the condition is false, statement2 is executed One or the other will be executed, but not both

The statement controlled by the if is indented to show the relationship Remember that indentation is for the human reader, and is ignored by the compiler

if (depth >= UPPER_LIMIT) delta = 100; else System.out.println("Reseting Delta"); delta = 0; System.out.println("Delta" + delta); When value is printed. If depth is equal UPPER_LIMIT?

Multi-branch if is done using else if, to consider more options: If (num1 < num2) Win = “try again”; else if (num1 = num 2) Win = “you win”; else Win = “you lose”;

Three types of “routines” (named sequence of statements) Main – one per system. Execution starts here Constructor – usually one per class. Same name as the class. These are invoked to create objects using new. You must create objects before doing anything else with that class. Method – as many as needed. These give the objects their behavior. Can use any name you want.

General format The format for the constructor is similar except there is no return type. public gradingStstem()