CSE 201 Java Programming I. Smart Coding School website:

Similar documents
CSE 142, Summer 2014

CSE 142, Summer 2015

Building Java Programs

Building Java Programs

Building Java Programs

clicker question Comments Using comments Topic 3 static Methods and Structured Programming

Static Methods & Decomposition

CSc 110, Autumn Lecture 2: Functions

CS 112 Introduction to Programming

Recap: Structure of a Java program CS 112 Introduction to Programming. A Foundation for Programming Why Introduce Static Methods?

Entering the world of Javatar

Topic 3 static Methods and Structured Programming

Lecture 1: Basic Java Syntax

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

Introduction to Computer Programming

CSc 110, Spring Lecture 2: Functions. Adapted from slides by Marty Stepp and Stuart Reges

Building Java Programs

Building Java Programs

Building Java Programs Chapter 1

Procedural decomposition using static methods

Building Java Programs

Building Java Programs Chapter 1

COMPUTATIONAL THINKING

A Unicorn Named Sparkle Word Search. A New Friend for Sparkle Coloring Sheet. A Unicorn Named Sparkle s First Christmas Coloring Sheet

Building Java Programs

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

Building Java Programs

Java Programming. What is a program? Programs Recipes. Programs as Recipes 8/16/12. Pancakes In one bowl. mix: 1½ cup flour

CP122 CS I. Hello, World!

Algorithms: The recipe for computation

Building Java Programs. Introduction to Java Programming

CP122 CS I. Chapter 1: Introduction

Building Java Programs. Introduction to Programming and Simple Java Programs

Topic 7 parameters. Based on slides from Marty Stepp and Stuart Reges from

Graded Project. HTML Coding

Introduction Jan. 22, Ch 1

Java Programming. What is a program? Programs as Recipes. Programs Recipes 8/20/15. Pancakes In one bowl

Getting started with Java

WELCOME TO CS 24! Enrollment status: 105/105, Read the syllabus. Know what s required. Know how to get help. Problem Solving with Computers-II

Chapter Two: Classes and Objects

The diagram below is only partially complete. Use the terms in the word list to complete the empty boxes. Make dinner

Java objects: a first view [Reading: chapters 1 & 2] CSC 142 B 1


INDEX. A SIMPLE JAVA PROGRAM Class Declaration The Main Line. The Line Contains Three Keywords The Output Line

AP Computer Science Summer Assignment (updated 5/29/2018) DUE : Sept. 4, 2018

CSc 110, Autumn 2016 Lecture 6: Parameters. Adapted from slides by Marty Stepp and Stuart Reges

CIS 110: Introduction to Computer Programming. Lecture 2 Decomposition and Static Methods ( 1.4)

Food Storage Newsletter #9 - FREE monthly newsletter - September, 1999

Foreword. Agenda 22/09/2009 INTRODUCTION TO VBA PROGRAMMING. Foundations. Tools

Building Java Programs. Chapter 2: Primitive Data and Definite Loops

SDKs - Eclipse. SENG 403, Tutorial 2

Introduction to Computer Programming concepts using StarLogo TNG

The cuisine package. Ben Cohen. 2000/08/01, v0.5

Introduction to Java. Java Programs Classes, Methods, and Statements Comments Strings Escape Sequences Identifiers Keywords

Important Dates. Please refer to the 2017 Fall Product Program large white envelope. These dates are permanent, and cannot be changed.

Building Java Programs

CIS 110: Introduction to Computer Programming

COMP15111: Introduction to Architecture

COMP1400 Programming for Designers. Claude Sammut

(A) 99 (B) 100 (C) 101 (D) 100 initial integers plus any additional integers required during program execution

COMPUTER PROGRAMMING LOOPS

CSE 201 JAVA PROGRAMMING I. Copyright 2016 by Smart Coding School

shaping covering with chocolate Macro Cookbook for Microsoft Word sweet, sweet success! testing Jack Lyon

Parallelism I. John Cavazos. Dept of Computer & Information Sciences University of Delaware

CSE 1223: Introduction to Computer Programming in Java Chapter 1 Computer Basics

Java Programming Fundamentals - Day Instructor: Jason Yoon Website:

ITC213: STRUCTURED PROGRAMMING. Bhaskar Shrestha National College of Computer Studies Tribhuvan University

ALICE: An introduction to progamming

Creating a Program in JCreator. JCreator is then used to create our program. But the first step is to create a new file.

Object-oriented programming. and data-structures CS/ENGRD 2110 SUMMER 2018

Discrete Mathematics. Kruskal, order, sorting, induction

AP Computer Science A Summer Assignment 2017

Problem Solving. Chapter Problem Solving. Analysis (inquiry, examination, study) Goal

MASSACHUSETTS VOCATIONAL TECHNICAL TEACHER TESTING PROGRAM SCOPE OF TEST CODE #11 - CULINARY ARTS WRITTEN EXAM QUESTIONS TIME ALLOWED: 3 HOURS

Algorithmic Problem Solving. Penny Rheingans University of Maryland Baltimore County

Data and Variables. Data Types Expressions. String Concatenation Variables Declaration Assignment Shorthand operators. Operators Precedence

Building Java Programs

(A) 99 ** (B) 100 (C) 101 (D) 100 initial integers plus any additional integers required during program execution

Section 2.2 Your First Program in Java: Printing a Line of Text

Producing Shapes on Screen

AP Computer Science Unit 1. Writing Programs Using BlueJ

CS141 Programming Assignment #6

Welcome to Python! If you re the type of person who wants to know

Introduce a three step process that outlines the development of a program that runs on a computer.

Building Java Programs

AP Computer Science Unit 1. Writing Programs Using BlueJ

CISC-124. Passing Parameters. A Java method cannot change the value of any of the arguments passed to its parameters.

CS298 Project Presentation By Priya Gangaraju

How to make a "hello world" program in Java with Eclipse *

CS 152: Data Structures with Java Hello World with the IntelliJ IDE

Announcements Tues., Aug and 2. to call them ( ) ! For next time, read Learning Computing with Robots, chs.

Java: Comment Text. Introduction. Concepts

Photoshop for Geeks Photoshop Scripting for Beginners Photoshop World Orlando, 2008 Jeffrey Tranberry Adobe Systems, QE Product Lead

So lets start! 8/26/16. Did you register your clicker? Key concept: The COMPUTER does the recipe! Make it as hard, tedious, complex as you want!

CS 302 Week 9. Jim Williams

Building Java Programs Chapter 3

Lecture Notes CPSC 224 (Spring 2012) Today... Java basics. S. Bowers 1 of 8

public Twix() { calories = 285; ingredients = "chocolate, sugar, cookie, caramel"; }

CT 229 Methods Continued

Everyday Algorithms. Algorithms and Introduction to Programming. bake a cake. start. mix sugar and butter. stir in 2 eggs. stir in flour.

Transcription:

CSE 201 Java Programming I Smart Coding School website: http://www.smartcodingschool.com

Definition: A named group of statements public static void methodname() { statements

Usage: 1. denotes the structure of a program 2. eliminates redundancy by code reuse public static void methodname() { statements

Pound Cake 1. With a mixer, cream butter and shortening together. 2. Add sugar, a little at a time. 3. Add eggs, 1 at a time, beating after each addition. 4. Stir dry ingredients together in a bowl and add to mixer alternately with milk, starting with the flour and ending with the flour. 5. Mix in vanilla. 6. Pour into a greased and floured tube pan and bake for 1 to 1 7. 1/2 hours, until a toothpick inserted in the center of the cake comes out clean.

Make it more structural Pound Cake Preparation: 1. With a mixer, cream butter and shortening together. 2. Add sugar, a little at a time. 3. Add eggs, 1 at a time, beating after each addition. Mix Step: 4. Stir dry ingredients together in a bowl and add to mixer alternately with milk, starting with the flour and ending with the flour. 5. Mix in vanilla. 6. Pour into a greased and floured tube pan and bake for 1 to 1 Bake Step: 7. 1/2 hours, until a toothpick inserted in the center of the cake comes out clean.

class main method: statement1 statement2 statement3 statement4 statement5 statement6

class main method: call methoda call methodb methoda: statement1 statement2 methodb: statement3 statement4 statement5 statement6

Syntax: public static void methodname() { statements Example: public static void printmessage() { System.out.println( This is the error ); System.out.println( in the lab. );

class Example { Static Method public static void main(string[] args) { printmessage(); printhello(); public static void printmessage() { System.out.println( This is the error ); System.out.println( in the lab. ); public static void printhello() { System.out.println( Hello ); System.out.println( World! );

You can call the same static method as many times as you want class Example { public static void main(string[] args) { printmessage(); printmessage(); printmessage(); public static void printmessage() { System.out.println( This is the error ); System.out.println( in the lab. );

a method can call other static method class Example { public static void main(string[] args) { printmessage(); public static void printmessage() { System.out.println( This is the error ); printhello(); public static void printhello() { System.out.println( Hello ); System.out.println( Hello )

Static Method Principle Place statements into a static method if: 1. The statements are related structurally 2. The statements are repeated Don t create a static method if: 1. A single print or println statement 2. Blank lines like System.out.println(); (Put them in main method) 3. Unrelated or weakly related statements (splitting them into 2 smaller methods)

Static Method Question: /\ write a program to print this rocket using methods //// \\\\

Static Method Question: /\ cap write a program to print this rocket using methods top part //// \\\\ body bottom

/\ //// \\\\ cap body bottom public static void toppart() { System.out.println( ); System.out.println( );

/\ //// \\\\ cap body bottom Static Method public static void toppart() { System.out.println( \\ ); System.out.println( ); public static void cap() { System.out.println( /\\ ); toppart(); System.out.println( );

/\ //// \\\\ cap body bottom Static Method public static void toppart() { System.out.println( \\ ); System.out.println( ); public static void cap() { System.out.println( /\\ ); toppart(); System.out.println( ); public static void body() { toppart(); System.out.println( ); System.out.println( );

/\ //// \\\\ cap body bottom Static Method public static void toppart() { System.out.println( \\ ); System.out.println( ); public static void cap() { System.out.println( /\\ ); toppart(); System.out.println( ); public static void body() { toppart(); System.out.println( ); System.out.println( ); public static void bottom() { toppart(); System.out.println( ); System.out.println( ); System.out.println( ////\\\\\\\\ );

/\ //// \\\\ cap body bottom public static void toppart() { System.out.println( \\ ); System.out.println( ); public static void cap() { System.out.println( /\\ ); toppart(); System.out.println( ); public static void body() { toppart(); System.out.println( ); System.out.println( ); public static void bottom() { toppart(); System.out.println( ); System.out.println( ); System.out.println( ////\\\\\\\\ );

/\ cap body class Example { public static void main(string[] args) { cap(); body(); bottom(); public static void toppart() { public static void cap() { //// \\\\ bottom public static void body() { public static void bottom() {

Now write the code without redundancy