CSE115 / CSE503 Introduction to Computer Science I Dr. Carl Alphonce 343 Davis Hall Office hours:

Similar documents
CSE115 / CSE503 Introduction to Computer Science I. Dr. Carl Alphonce 343 Davis Hall Office hours:

CSE115 / CSE503 Introduction to Computer Science I Dr. Carl Alphonce 343 Davis Hall Office hours:

CSE115 / CSE503 Introduction to Computer Science I Dr. Carl Alphonce 343 Davis Hall Office hours:

CSE115 / CSE503 Introduction to Computer Science I Dr. Carl Alphonce 343 Davis Hall Office hours:

CSE115 / CSE503 Introduction to Computer Science I Dr. Carl Alphonce 343 Davis Hall Office hours:

CSE115 / CSE503 Introduction to Computer Science I. Dr. Carl Alphonce 343 Davis Hall Office hours:

OO software systems are systems of interacting objects.

CSE115 / CSE503 Introduction to Computer Science I. Dr. Carl Alphonce 343 Davis Hall Office hours:

CSE115 / CSE503 Introduction to Computer Science I Dr. Carl Alphonce 343 Davis Hall Office hours:

CSE115 / CSE503 Introduction to Computer Science I. Dr. Carl Alphonce 343 Davis Hall Office hours:

CSE443 Compilers. Dr. Carl Alphonce 343 Davis Hall

CSE443 Compilers. Dr. Carl Alphonce 343 Davis Hall

COMP 110 Introduction to Programming. What did we discuss?

CSE306 Software Quality in Practice. Dr. Carl Alphonce 343 Davis Hall

CSE 115 / 503 INTRODUCTION TO COMPUTER SCIENCE I. Dr. Carl Alphonce Dr. Jesse Hartloff

CSE443 Compilers. Dr. Carl Alphonce 343 Davis Hall

CSE443 Compilers. Dr. Carl Alphonce 343 Davis Hall

CSE443 Compilers. Dr. Carl Alphonce 343 Davis Hall

CSE443 Compilers. Dr. Carl Alphonce 343 Davis Hall

Loops. CSE 114, Computer Science 1 Stony Brook University

Control Structures II. Repetition (Loops)

CSE443 Compilers. Dr. Carl Alphonce 343 Davis Hall

CS171:Introduction to Computer Science II

CS1100 Introduction to Programming

Control Structure: Loop

Definite Loops. Computer Science S-111 Harvard University David G. Sullivan, Ph.D. Using a Variable for Counting

CSE 1223: Introduction to Computer Programming in Java Chapter 3 Branching

COSC 236 Section 101 Computer Science 1 -- Prof. Michael A. Soderstrand

Materials covered in this lecture are: A. Completing Ch. 2 Objectives: Example of 6 steps (RCMACT) for solving a problem.

1.00 Introduction to Computers and Engineering Problem Solving. Quiz 1 March 7, 2003

CSE410 aka CSE306 Software Quality

COMP-202: Foundations of Programming. Lecture 4: Flow Control Loops Sandeep Manjanna, Summer 2015

Expressions & Flow Control

CSE443 Compilers. Dr. Carl Alphonce 343 Davis Hall

CS115 - Module 3 - Booleans, Conditionals, and Symbols

Selec%on and Decision Structures in Java: If Statements and Switch Statements CSC 121 Spring 2016 Howard Rosenthal

MIPS Assembly: More about MIPS Instructions Using Functions in MIPS CS 64: Computer Organization and Design Logic Lecture #8

Programming in the Small II: Control

CSC 1051 Data Structures and Algorithms I

Building Java Programs

Building Java Programs

CS1150 Principles of Computer Science Loops (Part II)

Other conditional and loop constructs. Fundamentals of Computer Science Keith Vertanen

COMP-202: Foundations of Programming. Lecture 8: for Loops, Nested Loops and Arrays Jackie Cheung, Winter 2016

CSE 142, Summer 2013 Midterm Exam, Friday, July 26, 2013

Outline for Today CSE 142. Programming a Teller Machine. CSE142 Wi03 I-1. ATM Algorithm for Dispensing Money

Structured Programming. Dr. Mohamed Khedr Lecture 9

CS150 Intro to CS I. Fall Fall 2017 CS150 - Intro to CS I 1

CS61C Machine Structures. Lecture 3 Introduction to the C Programming Language. 1/23/2006 John Wawrzynek. www-inst.eecs.berkeley.

CSE443 Compilers. Dr. Carl Alphonce 343 Davis Hall

CSE443 Compilers. Dr. Carl Alphonce 343 Davis Hall

CS 101: Computer Programming and Utilization. Abhiram Ranade

Physics 2660: Fundamentals of Scientific Computing. Lecture 5 Instructor: Prof. Chris Neu

Control Statements. if for while

Programming Language. Control Structures: Selection (switch) Eng. Anis Nazer First Semester

Bjarne Stroustrup. creator of C++

CSCE 206: Structured Programming in C++

COMP 110 Introduction to Programming. What did we discuss?

CSE 115. Introduction to Computer Science I

2/5/2018. Learn Four More Kinds of C Statements. ECE 220: Computer Systems & Programming. C s if Statement Enables Conditional Execution

Problem Solving through Programming In C Prof. Anupam Basu Department of Computer Science & Engineering Indian Institute of Technology, Kharagpur

There are algorithms, however, that need to execute statements in some other kind of ordering depending on certain conditions.

Controls Structure for Repetition

CSE443 Compilers. Dr. Carl Alphonce 343 Davis Hall

CIS March 1, 2018

CS 117 Programming II, Spring 2018 Dr. Ghriga. Midterm Exam Estimated Time: 2 hours. March 21, DUE DATE: March 28, 2018 at 12:00 PM

Nested Loops ***** ***** ***** ***** ***** We know we can print out one line of this square as follows: System.out.

Lecture 8 CSE11 Fall 2013 While Loops, Switch Statement, Simplifying Conditionals

Recap: Assignment as an Operator CS 112 Introduction to Programming

CS 101 Spring 2007 Midterm 2 Name: ID:

Enumerated Types. CSE 114, Computer Science 1 Stony Brook University

Top-Down Program Development

CSC 111 Introduction to Computer Science (Section C)

CSE 115 / 503 INTRODUCTION TO COMPUTER SCIENCE I. Dr. Carl Alphonce Dr. Jesse Hartloff

Lecture 9. Assignment. Logical Operations. Logical Operations - Motivation 2/8/18

Selection Statements and operators

Basic computer skills such as using Windows, Internet Explorer, and Microsoft Word. Chapter 1 Introduction to Computers, Programs, and Java

CSCD 255 HW 2. No string (char arrays) or any other kinds of array variables are allowed

H212 Introduction to Software Systems Honors

Review: Object Diagrams for Inheritance. Type Conformance. Inheritance Structures. Car. Vehicle. Truck. Vehicle. conforms to Object

CS 112 Introduction to Programming

CSCE 110 Dr. Amr Goneid Exercise Sheet (7): Exercises on Recursion

CSCE 145 Exam 1 Review. This exam totals to 100 points. Follow the instructions. Good luck!

CS Introduction to Programming Fall 2016

Java. Programming: Chapter Objectives. Why Is Repetition Needed? Chapter 5: Control Structures II. Program Design Including Data Structures

Java Basic Programming Constructs

CSE115 Introduction to Computer Science I Coding Exercise #7 Retrospective Fall 2017

CS Programming I: Branches

Program Development. Program Development. A Foundation for Programming. Program Development

} Evaluate the following expressions: 1. int x = 5 / 2 + 2; 2. int x = / 2; 3. int x = 5 / ; 4. double x = 5 / 2.

C212 Early Evaluation Exam Mon Feb Name: Please provide brief (common sense) justifications with your answers below.

Outline for Today CSE 142. CSE142 Wi03 G-1. withdraw Method for BankAccount. Class Invariants

Assignment 2.4: Loops

Lec 7. for loops and methods

3/12/2018. Structures. Programming in C++ Sequential Branching Repeating. Loops (Repetition)

Public-Service Announcements

Some Sample AP Computer Science A Questions - Solutions

Algorithmic Thinking and Structured Programming (in Greenfoot) Teachers: Renske Smetsers-Weeda Sjaak Smetsers Ana Tanase

Functions in Processing

Cisdem AppCrypt Tutorial

Transcription:

CSE115 / CSE503 Introduction to Computer Science I Dr. Carl Alphonce 343 Davis Hall alphonce@buffalo.edu Office hours: Tuesday 10:00 AM 12:00 PM * Wednesday 4:00 PM 5:00 PM Friday 11:00 AM 12:00 PM OR request appointment via e-mail *Tuesday adjustments: 11:00 AM 1:00 PM on 10/11, 11/1 and 12/6

Dr. Carl Alphonce Last time Control structures (selection) Coding exercise ROADMAP Today Control structures (repetition) Coding exercises Coming up Collections

EXERCISE REVIEW Dr. Carl Alphonce

PAIR CODING EXERCISE Define a class quiz.question. In this class define a method named answer. Dr. Carl Alphonce Define this method so that it returns "NEGATIVE" if its int argument is negative, "POSITIVE" if its argument is positive, and "ZERO" otherwise. Submit to Exercise-02 in Web-CAT enter the usernames of everyone in your group! You have 15 minutes to complete this exercise.

package quiz; Define a class quiz.question. In this class define a method named answer. public class Question { Exercise-01 public String answer(int x) { if (x < 0) { return "NEGATIVE"; else if (x > 0) { else { return "POSITIVE"; return "ZERO"; Define this method so that it returns "NEGATIVE" if its int argument is negative, "POSITIVE" if its argument is positive, and "ZERO" otherwise.

package quiz; Define a class quiz.question. In this class define a method named answer. public class Question { Exercise-01 public String answer(int x) { if (x < 0) { return "NEGATIVE"; else if (x > 0) { else { return "POSITIVE"; return "ZERO"; Define this method so that it returns "NEGATIVE" if its int argument is negative, "POSITIVE" if its argument is positive, and "ZERO" otherwise.

package quiz; Define a class quiz.question. In this class define a method named answer. public class Question { Exercise-01 public String answer(int x) { if (x < 0) { return "NEGATIVE"; else if (x > 0) { else { return "POSITIVE"; return "ZERO"; Define this method so that it returns "NEGATIVE" if its int argument is negative, "POSITIVE" if its argument is positive, and "ZERO" otherwise.

package quiz; Define a class quiz.question. In this class define a method named answer. public class Question { Exercise-01 public String answer(int x) { if (x < 0) { return "NEGATIVE"; else if (x > 0) { else { return "POSITIVE"; return "ZERO"; Define this method so that it returns "NEGATIVE" if its int argument is negative, "POSITIVE" if its argument is positive, and "ZERO" otherwise.

package quiz; Define a class quiz.question. In this class define a method named answer. public class Question { Exercise-01 public String answer(int x) { if (x < 0) { return "NEGATIVE"; else if (x > 0) { else { return "POSITIVE"; return "ZERO"; Define this method so that it returns "NEGATIVE" if its int argument is negative, "POSITIVE" if its argument is positive, and "ZERO" otherwise.

package quiz; Define a class quiz.question. In this class define a method named answer. public class Question { Exercise-01 public String answer(int x) { if (x < 0) { return "NEGATIVE"; else if (x > 0) { else { return "POSITIVE"; return "ZERO"; Define this method so that it returns "NEGATIVE" if its int argument is negative, "POSITIVE" if its argument is positive, and "ZERO" otherwise.

package quiz; Define a class quiz.question. In this class define a method named answer. public class Question { Exercise-01 public String answer(int x) { if (x < 0) { return "NEGATIVE"; else if (x > 0) { else { return "POSITIVE"; return "ZERO"; Define this method so that it returns "NEGATIVE" if its int argument is negative, "POSITIVE" if its argument is positive, and "ZERO" otherwise.

package quiz; Define a class quiz.question. In this class define a method named answer. public class Question { Exercise-01 public String answer(int x) { if (x < 0) { return "NEGATIVE"; else if (x > 0) { else { return "POSITIVE"; return "ZERO"; Define this method so that it returns "NEGATIVE" if its int argument is negative, "POSITIVE" if its argument is positive, and "ZERO" otherwise.

MOVING ON Dr. Carl Alphonce

Dr. Carl Alphonce Control Structures à repetition à while statement

Control structure overview while statement while statement while ( <expr> ) <stmt> <expr> true <stmt> false

Control structure overview while statement while statement while ( <expr> ) <stmt> <expr> true <stmt> false

Control structure overview if statement if ( <expr> ) <stmt> if statement <expr> false true <stmt>

Control structure overview if statement if ( <expr> ) <stmt> Recall the flow chart for an if statement: if <expr> is true, then <stmt> is executed once. Afterwards execution continues with the next statement in the program. <expr> false true <stmt>

Control structure overview while statement while ( <expr> ) <stmt> The flow chart for a while statement is different from that of the if statement in one very important respect. <expr> false true <stmt> A LOOP! In the case that <expr> is true, <stmt> is executed. Control goes back and reevaluates <expr>, thus creating a loop in the flow of control. In the case that <expr> is false the loop is not entered and program execution continues with the next statement.

public void message() { while loop example System.out.print("I "); int timesalreadyprinted = 0; while (timesalreadyprinted < 3) { System.out.print("really "); timesalreadyprinted = timesalreadyprinted + 1; System.out.println(" like spring break!");

public void message(int numberofrepetitions) { while loop example System.out.print("I "); int timesalreadyprinted = 0; while (timesalreadyprinted < numberofrepetitions){ System.out.print("really "); timesalreadyprinted = timesalreadyprinted + 1; System.out.println(" like spring break!");

Dr. Carl Alphonce tracing code We spent some time tracing the execution of the code on the previous slide, keeping track of the value of the variable timesalreadyprinted and the corresponding output. Being able to trace the execution of code by hand is an important skill.

PAIR CODING EXERCISE Define a class quiz.question. In this class define a method named answer. Dr. Carl Alphonce Define this method so that it returns a String consisting of all the integers from 0 to n inclusive, comma-separated, if n >= 0, and the String "0" otherwise. For example: answer(-1) must return "0" answer(0) must return "0" answer(3) must return "0, 1, 2, 3" Submit to Exercise-03 in Web-CAT enter the usernames of everyone in your group! You have 20 minutes to complete this exercise.