Warm Up As you enter get out a half sheet of loose paper. Write the HelloWorld program on it. Be prepared to correct your code.

Slides:



Advertisements
Similar presentations
Copyright 2008 by Pearson Education Building Java Programs Chapter 3 Lecture 3-1: Parameters reading: 3.1 self-check: #1-6 exercises: #1-3 videos: Ch.
Advertisements

Introduction to Programming
BUILDING JAVA PROGRAMS CHAPTER 3 PARAMETERS AND OBJECTS.
Building Java Programs Chapter 1 Lecture 1-2: Static Methods reading:
Java Programs + Algorithms
Mr. Wortzman INTRO. TO COMPUTER SCIENCE. UNIT 1 – CUSTOM BLOCKS.
Basic Java programs with println statements. 2 Compile/run a program 1.Write it –code or source code: the set of instructions in a program 2.Compile it.
1 Procedural decomposition using static methods suggested reading:1.4.
1 Procedural decomposition using static methods. 2 Algorithms Recall: An algorithm is a list of steps for solving a problem. What is the algorithm to.
© 2011 wheresjenny.com BROWNIES SERVINGS: 16 PIECES PREPARATION TIME : ONE HOUR.
Building Java Programs Chapter 1 Introduction to Java Programming.
Copyright 2010 by Pearson Education Building Java Programs Chapter 1 Lecture 1-2: Static Methods reading:
Copyright 2008 by Pearson Education Building Java Programs Chapter 3: Parameters, Return, and Interactive Programs Lecture 3-1: Parameters (reading: 3.1)
Copyright 2008 by Pearson Education 1 Class constants and scope reading: 2.4 self-check: 28 exercises: 11 videos: Ch. 2 #5.
Copyright 2008 by Pearson Education Building Java Programs Chapter 1 Lecture 1-2: Static Methods, Avoiding Redundancy reading: self-check:
Copyright 2008 by Pearson Education Building Java Programs Chapter 1: Introduction to Java Programming.
Copyright 2006 by Pearson Education 1 Building Java Programs Chapter 3: Parameters, Return, and Interactive Programs.
Topic 7 parameters Based on slides bu Marty Stepp and Stuart Reges from "We're flooding people with information. We.
Copyright 2008 by Pearson Education Building Java Programs Chapter 1 Lecture 1-2: Static Methods reading:
Topic 3 static Methods and Structured Programming "The cleaner and nicer the program, the faster it's going to run. And if it doesn't, it'll be easy to.
Copyright 2006 by Pearson Education 1 Building Java Programs Chapter 1: Introduction to Java Programming.
Static methods. 2 Algorithms algorithm: a list of steps for solving a problem Example algorithm: "Bake sugar cookies" –Mix the dry ingredients. –Cream.
Building Java Programs Chapter 1 Introduction to Java Programming Copyright (c) Pearson All rights reserved.
CS 112 Introduction to Programming Lecture 3: Java Methods Yang (Richard) Yang Computer Science Department Yale University 308A Watson, Phone:
1 CSE 142 Lecture Notes Introduction These lecture notes are copyright (C) Marty Stepp May not be rehosted, copied, sold, or modified without Marty.
1 BUILDING JAVA PROGRAMS CHAPTER 2 Pseudocode and Scope.
Building Java Programs Parameters and Objects. 2 Redundant recipes Recipe for baking 20 cookies: –Mix the following ingredients in a bowl: 4 cups flour.
Copyright 2010 by Pearson Education Building Java Programs Chapter 1 Lecture 1-2: Static Methods reading:
Building Java Programs Chapter 3 Lecture 3-1: Parameters reading: 3.1.
CS 112 Introduction to Programming Lecture 3: Java Methods Yang (Richard) Yang Computer Science Department Yale University 308A Watson, Phone:
Copyright 2010 by Pearson Education Building Java Programs Chapter 3 Lecture 3-1: Parameters reading: 3.1.
Copyright 2009 by Pearson Education Building Java Programs Chapter 3 Lecture 3-1: Parameters reading: 3.1 self-check: #1-6 exercises: #1-3 videos: Ch.
CSc 110, Autumn 2016 Lecture 2: Functions. Review What is the output of the following print statements? print("this class\tis' the \"best\"") Write a.
Lecture 1: Basic Java Syntax
Building Java Programs
Static Methods and Method Calls
CSc 110, Autumn 2017 Lecture 2: Functions.
Building Java Programs Chapter 3
Building Java Programs
Lecture 2: Static Methods Expressions reading: 1.4 – 2.1
Building Java Programs
SELECTION STATEMENTS (1)
AP Computer Science Mr. Wortzman.
Building Java Programs
Adapted from slides by Marty Stepp and Stuart Reges
Topic 3 static Methods and Structured Programming
Topic 7 parameters "We're flooding people with information. We need to feed it through a processor. A human must turn information into intelligence or.
Building Java Programs
Redundant recipes Recipe for baking 20 cookies:
Building Java Programs
Building Java Programs
Lecture 1: Basic Java Syntax
Building Java Programs
CSc 110, Spring 2018 Lecture 3: Functions.
Building Static Methods
Building Java Programs
CSc 110, Spring 2018 Lecture 2: Functions.
Lecture 2: Static Methods Expressions reading: 1.4 – 2.1
Building Java Programs
Building Java Programs
Building Java Programs
Building Java Programs
Building Java Programs
Chapter 1 Lecture 1-2: Static Methods reading:
Building Java Programs
Building Java Programs
Building Java Programs
Building Java Programs
Building Java Programs
Building Java Programs
Presentation transcript:

Warm Up As you enter get out a half sheet of loose paper. Write the HelloWorld program on it. Be prepared to correct your code.

INTRODUCTION TO JAVA PROGRAMMING, CHAPTER 1 Procedural decomposition

At the end of this class, you will be able to Define subtasks for multistep problems. Declare and call static methods to eliminate redundancy in your programs. Examine the control flow of programs which use static methods.

Algorithms Revisited Making cookies Mix dry ingredients. Cream butter and sugar. Beat in eggs. Stir dry ingredients into wet. Set the oven to 400 Put the cookies into the oven. Bake for 10 minutes Remove the cookies from the oven. Mix ingredients for frosting. Frost the cookies. Making a double batch of cookies … Set the oven to 400 Put the first batch of cookies into the oven. Bake for 10 minutes. Remove the first batch of cookies from the oven. Bake for 10 minutes Remove the second batch of cookies from the oven. …

Algorithms Revisited Making cookies Make the batter Bake the cookies Frost the cookies Making a double batch of cookies Make the double batch of batter Bake the first batch of cookies Bake the second batch of cookies Frost the first batch of cookies Frost the second batch of cookies Bake the cookies Set the oven to 400 Make the batter Bake the cookies Remove the cookies from the oven.

Procedural Decomposition Decomposition is the separation of a problem into discernible parts. Each part should be simpler than the whole.

Static methods A block of Java statements that is given a name. Break a program into several static methods that each solve a piece of the overall problem. public static void () { ; … } Syntax Yoda

Steps to creating static methods Problem: Write a program that produces the following output: | |

Steps to creating static methods: Design, Define, Call 1. Design the method: A method that draws a box. 2. Define the method: public static void drawBox() { System.out.println(" "); System.out.println("| |"); System.out.println(" "); } 3. Call the method: drawBox(); System.out.println(); drawBox();

Flow of control The order in which the statements of a Java program are executed. public static void main (String args[]) { drawBox(); System.out.println(); drawBox(); } public static void drawBox() { System.out.println(" "); System.out.println("| |"); System.out.println(" "); }

Think, Pair, Share… Describe what methods would be useful for writing a program that produces the following output: \ / /\ \ /

Methods that call other methods public static void bar() { foo(); System.out.println(”bar"); foo(); } public static void foo() { System.out.println(”foo"); } public static void main(String args[]) { foo(); bar(); }

Questions?

Homework Read 1.4 Self Check 1.17 Exercise 1.3, 1.8