Building Java Programs

Slides:



Advertisements
Similar presentations
Programming for Beginners Martin Nelson Elizabeth FitzGerald Lecture 3: Flow Control I: For Loops.
Advertisements

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.
Nested for loops Cont’d. 2 Drawing complex figures Use nested for loops to produce the following output. Why draw ASCII art? –Real graphics require a.
Lecture 3: Topics If-then-else Operator precedence While loops Static methods Recursion.
Fibonacci Numbers A simple example of program design.
Copyright 2008 by Pearson Education 1 Class constants and scope reading: 2.4 self-check: 28 exercises: 11 videos: Ch. 2 #5.
Repetition Structures: For Loop Constants CSC 1401: Introduction to Programming with Java Week 5 Wanda M. Kunkle.
Loops Chapter 4. It repeats a set of statements while a condition is true. while (condition) { execute these statements; } “while” structures.
Loops Chapter 4. It repeats a set of statements while a condition is true. while (condition) { execute these statements; } “while” structures.
CS305j Introduction to ComputingNested For Loops 1 Topic 6 Nested for Loops "Complexity has and will maintain a strong fascination for many people. It.
Copyright 2006 by Pearson Education 1 Building Java Programs Chapter 3: Parameters, Return, and Interactive Programs.
Building Java Programs
Building Java Programs Chapter 2 Primitive Data and Definite Loops.
1 BUILDING JAVA PROGRAMS CHAPTER 2 PRIMITIVE DATA AND DEFINITE LOOPS.
Copyright 2008 by Pearson Education 1 Building Java Programs Chapter 2 Lecture 2-3: Loop Figures and Constants reading: self-checks: 27 exercises:
1 BUILDING JAVA PROGRAMS CHAPTER 2 PRIMITIVE DATA AND DEFINITE LOOPS.
1 BUILDING JAVA PROGRAMS CHAPTER 2 Pseudocode and Scope.
1 Building Java Programs Chapter 3: Introduction to Parameters and Objects These lecture notes are copyright (C) Marty Stepp and Stuart Reges, They.
CS 112 Introduction to Programming Variable Scoping; Nested Loops; Parameterized Methods Yang (Richard) Yang Computer Science Department Yale University.
Copyright 2010 by Pearson Education 1 Building Java Programs Chapter 2 Lecture 4: Loop Figures and Constants reading:
Building Java Programs Chapter 2 Primitive Data and Definite Loops.
1 BUILDING JAVA PROGRAMS CHAPTER 2 PRIMITIVE DATA AND DEFINITE LOOPS.
10/9/07 ______ \ ^__^ \ (oo)\_______ (__)\ )\/\ ||----w | || ||
Topic 6 loops, figures, constants Based on slides bu Marty Stepp and Stuart Reges from "Complexity has and will maintain.
Structured Programming Dr. Atif Alhejali Lecture 4 Modifiers Parameters passing 1Structured Programming.
Chapter 2 Wrap Up 2/18/16 & 2/22/16. Topics Review for Exam I DecimalFormat More Style Conventions Debugging using eclipse The Java API.
Copyright 2008 by Pearson Education 1 Nested loops reading: 2.3 self-check: exercises: videos: Ch. 2 #4.
CS305j Introduction to Computing Parameters and Methods 1 Topic 8 Parameters and Methods "We're flooding people with information. We need to feed it through.
Copyright 2006 by Pearson Education 1 Building Java Programs Chapter 2: Primitive Data and Definite Loops.
1 Lecture # 2. * Introducing Programming with an Example * Identifiers, Variables, and Constants * Primitive Data Types * Byte, short, int, long, float,
Building Java Programs Chapter 2
Building Java Programs
Building Java Programs
Building Java Programs
CSCI 161 – Introduction to Programming I William Killian
Building Java Programs
CSc 110, Autumn 2017 Lecture 5: The for Loop and user input
Building Java Programs Chapter 2
A simple example of program design
Building Java Programs Chapter 2
CSc 110, Spring 2017 Lecture 5: Constants and Parameters
Topic 7 Nested Loops Case Study
CSc 110, Autumn 2016 Lecture 5: Loop Figures and Constants
Building Java Programs
Building Java Programs
Building Java Programs
CSc 110, Spring 2018 Lecture 7: input and Constants
Building Java Programs
Building Java Programs Chapter 2
CSc 110, Spring 2018 Lecture 5: Loop Figures and Constants
Building Java Programs
Topic 6 loops, figures, constants
Building Java Programs
CSE 190D, Winter 2013 Building Java Programs Chapter 2
Building Java Programs
Building Java Programs
Chapter 2 Programming Basics.
CSE 142 Lecture Notes Global Constants, Parameters, Return Values
Building Java Programs
Building Java Programs
Building Java Programs
Scope scope: The part of a program where a variable exists. From its declaration to the end of the { } braces A variable declared in a for loop exists.
Suggested self-checks:
Building Java Programs
Drawing complex figures
Building Java Programs
Building Java Programs Chapter 2
Building Java Programs
Corresponds with Chapter 5
Chapter 2 Lecture 2-3: Loop Figures and Constants reading:
Presentation transcript:

Building Java Programs 7/29/2019 Building Java Programs Chapter 2 Lecture 2-3: Loop Figures and Constants reading: 2.4 - 2.5 1

1. Pseudo-code pseudo-code: An English description of an algorithm. Example: Drawing a 12 wide by 7 tall box of stars print 12 stars. for (each of 5 lines) { print a star. print 10 spaces. } ************ * *

Scope scope: The part of a program where a variable exists. From its declaration to the end of the { } braces A variable declared in a for loop exists only in that loop. A variable declared in a method exists only in that method. public static void example() { int x = 3; for (int i = 1; i <= 10; i++) { System.out.println(x); } // i no longer exists here } // x ceases to exist here x's scope i's scope

Scaling the mirror Let's modify our Mirror program so that it can scale. The current mirror (left) is at size 4; the right is at size 3. We'd like to structure the code so we can scale the figure by changing the code in just one place. #================# | <><> | | <>....<> | | <>........<> | |<>............<>| #============# | <><> | | <>....<> | |<>........<>|

Class constants class constant: A fixed value visible to the whole program. value can be set only at declaration; cannot be reassigned, hence the name: constant Syntax: public static final type name = expression; name is usually in ALL_UPPER_CASE Examples: public static final int HOURS_IN_WEEK = 7 * 24; public static final double INTEREST_RATE = 3.5; public static final int SSN = 658234569;

Assignment 2: ASCII Art || __/||\__ __/:::||:::\__ __/::::::||::::::\__ __/:::::::::||:::::::::\__ |""""""""""""""""""""""""| \_/\/\/\/\/\/\/\/\/\/\/\_/ \_/\/\/\/\/\/\/\/\/\_/ \_/\/\/\/\/\/\/\_/ \_/\/\/\/\/\_/ |%%||%%|