Neal Stublen What's a class?  A class is comprised of a set of data and the actions taken on that data  Each action is represented.

Slides:



Advertisements
Similar presentations
Java Planning our Programs Flowcharts Arithmetic Operators.
Advertisements

1 Chapter 2 Introduction to Java Applications Introduction Java application programming Display ____________________ Obtain information from the.
Introduction to Programming with Java, for Beginners Primitive Types Expressions Statements Variables Strings.
Introduction to Computers and Programming Lecture 4: Mathematical Operators New York University.
CMT Programming Software Applications
Program Design and Development
Chapter 2: Input, Processing, and Output
Program Elements We can now examine the core elements of programming (as implemented in Java) We focuse on: data types variable declaration and use, constants.
The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL Adrian Ilie COMP 14 Introduction to Programming Adrian Ilie June 27, 2005.
Fundamental Programming Structures in Java: Comments, Data Types, Variables, Assignments, Operators.
Chapter 2: Introduction to C++.
Programming Logic and Design Sixth Edition Chapter 2 Working with Data, Creating Modules, and Designing High-Quality Programs.
Copyright 2006 Addison-Wesley Brief Version of Starting Out with C++ Chapter 2 Introduction to C++
Chapter 2: Basic Elements of Java J ava P rogramming: From Problem Analysis to Program Design, From Problem Analysis to Program Design, Second Edition.
Chapter 2 Basic Elements of Java. Chapter Objectives Become familiar with the basic components of a Java program, including methods, special symbols,
Chapter 3 Processing and Interactive Input. 2 Assignment  The general syntax for an assignment statement is variable = operand; The operand to the right.
CNG 140 C Programming Lecture Notes 2 Processing and Interactive Input Spring 2007.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley STARTING OUT WITH Python Python First Edition by Tony Gaddis Chapter 2 Input,
Input, Output, and Processing
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 2-1 Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley.
CHAPTER 4: CONTROL STRUCTURES - SEQUENCING 10/14/2014 PROBLEM SOLVING & ALGORITHM (DCT 1123)
Introduction to Programming David Goldschmidt, Ph.D. Computer Science The College of Saint Rose Java Fundamentals (Variables, Arithmetic, etc.)
Copyright © 2012 Pearson Education, Inc. Chapter 2: Introduction to C++
CIS 260: App Dev I. 2 Programs and Programming n Program  A sequence of steps designed to accomplish a task n Program design  A detailed _____ for implementing.
Java Programming: From Problem Analysis to Program Design, 4e Chapter 2 Basic Elements of Java.
 Pearson Education, Inc. All rights reserved Introduction to Java Applications.
Programming for Beginners Martin Nelson Elizabeth FitzGerald Lecture 2: Variables & Data Types.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 2 Input, Processing, and Output.
Programming Logic and Design Seventh Edition
Lecture 2: Introduction to C Programming. OBJECTIVES In this lecture you will learn:  To use simple input and output statements.  The fundamental data.
Copyright © 2015, 2012, 2009 Pearson Education, Inc., Publishing as Addison-Wesley All rights reserved. Chapter 2: Introduction to C++
1 Chapter 3 Syntax, Errors, and Debugging Fundamentals of Java: AP Computer Science Essentials, 4th Edition Lambert / Osborne.
Chapter 3 Syntax, Errors, and Debugging Fundamentals of Java.
Program Development C# Programming January 30, 2007 Professor J. Sciame.
A Simple Java Program //This program prints Welcome to Java! public class Welcome { public static void main(String[] args) { public static void main(String[]
Operators and Expressions. 2 String Concatenation  The plus operator (+) is also used for arithmetic addition  The function that the + operator performs.
Chapter Topics 2.1 Designing a Program 2.2 Output, Input, and Variables 2.3 Variable Assignment and Calculations 2.4 Variable Declarations and Data Types.
Variables in C Topics  Naming Variables  Declaring Variables  Using Variables  The Assignment Statement Reading  Sections
CMSC 104, Version 8/061L09VariablesInC.ppt Variables in C Topics Naming Variables Declaring Variables Using Variables The Assignment Statement Reading.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 2 Introduction to C++
Java Programming: From Problem Analysis to Program Design, Second Edition 1 Lecture 1 Objectives  Become familiar with the basic components of a Java.
1 1 Chapter 2 Elementary Programming. 2 2 Motivations In the preceding chapter, you learned how to create, compile, and run a Java program. Starting from.
Chapter 4: Variables, Constants, and Arithmetic Operators Introduction to Programming with C++ Fourth Edition.
Introduction to Algorithmic Processes CMPSC 201C Fall 2000.
Lecture 3: More Java Basics Michael Hsu CSULA. Recall From Lecture Two  Write a basic program in Java  The process of writing, compiling, and running.
2.1 The Part of a C++ Program. The Parts of a C++ Program // sample C++ program #include using namespace std; int main() { cout
Information and Computer Sciences University of Hawaii, Manoa
Topics Designing a Program Input, Processing, and Output
BASIC ELEMENTS OF A COMPUTER PROGRAM
Chapter 2: Input, Processing, and Output
Data Types, Identifiers, and Expressions
Revision Lecture
Multiple variables can be created in one declaration
Variables, Expressions, and IO
Chapter Topics 2.1 Designing a Program 2.2 Output, Input, and Variables 2.3 Variable Assignment and Calculations 2.4 Variable Declarations and Data Types.
Java Programming: From Problem Analysis to Program Design, 4e
An Object-Oriented Approach to Programming Logic and Design Fourth Edition Chapter 2 Applications and Data.
Data Types, Identifiers, and Expressions
2.1 Parts of a C++ Program.
Chapter 2: Basic Elements of Java
elementary programming
Chapter 2: Introduction to C++.
Topics Designing a Program Input, Processing, and Output
Topics Designing a Program Input, Processing, and Output
Fundamental OOP Programming Structures in Java: Comments, Data Types, Variables, Assignments, Operators.
Chapter 2: Input, Processing, and Output
In this class, we will cover:
Unit 3: Variables in Java
Variables in C Topics Naming Variables Declaring Variables
PYTHON - VARIABLES AND OPERATORS
Presentation transcript:

Neal Stublen

What's a class?  A class is comprised of a set of data and the actions taken on that data  Each action is represented by a method  A method is a set of statements that performs a specific task  Program execution will begin in a “main” method

What's an identifier?  An identifier is a name we give to a class or method  No whitespace - spaces, tabs, line breaks, etc.  Not a keyword - words reserved by the programming language  Most likely case-sensitive, so "count" is not the same as "Count"

Identifier "Casing"  UPPERCASE  lowercase  PascalCase or UpperCamelCase  lowerCamelCase  Each language typically has its own style for casing

Examples Pseudocode class Hello main() output "Hello” return endClass

Examples Java public class Hello { public static void main(String[] args) { System.out.println("Hello"); }

Examples C# public class Hello { static void Main() { System.Console.WriteLine("Hello"); }

What's a variable?  Data resides in the computer's memory  A variable names the data stored at a specific location in the computer's memory  Computer programs use variables to access and modify data stored in memory

What's a literal constant?  Data that doesn't change is a constant  Fixed values that appear in a computer program are called literals or literal constants

Examples input myNumber myAnswer = myNumber * 2 myAnswer = myAnswer + 42 output myAnswer  myNumber is a variable  myAnswer is a variable  2 is a literal constant  42 is a literal constant

Examples myName = "John Smith" output myName  myName is a variable  “John Smith” is a literal constant

Data Types  Numeric types Integer Floating point  String types  Casting converts between data types

Variable Declaration  Variables are declared with a data type  Variables are initialized with a value num myNumber num myNumber = 12 string myName string myName = "John"

Named Constants  Variables can refer to values that are fixed area = * radius * radius circumference = 2 * * radius

Named Constants  Variables can refer to values that are fixed num PI = area = PI* radius * radius circumference = 2 * PI* radius

Uninitialized Variables  Initialization places a known value into the memory location represented by a variable  Without initialization, the contents of a memory location could be anything  Typically called garbage And the source of many headaches

Assignment  Assign values to variables  Assign using a literal constant  Assign using another variable or expression  In some languages assignment can only be performed between matching types

Examples a = 1// ‘a’ now has the value ‘1’ b = a// ‘b’ now has the value ‘1’ c = a + b// ‘c’ now has the value ‘2’ num a = 1 string name = “John” name = a// Not allowed

Arithmetic Operations  Addition, +  Subtraction, -  Multiplication, *  Division, /  Modulus, %

Precedence  Multiplication and division precede addition and subtraction  Parentheses are evaluated from the inside out  * ( ( ) / )  * ( 9 / )  * ( )  * 4   14

Good Practices  Use code comments to clarify what is intended  Choose identifiers that are clear  Variable names are typically nouns (things, e.g. radius)  Method names typically combine a verb and noun (act on a thing, e.g. calculateArea)  Code that is easily readable can become self- documenting  What's clear now may not be clear later or clear to someone else

Searching for something?  a = w * l  area = width * length  aTmp = 98.6  avgTemp = 98.6  averageTemperature = 98.6  crntSpd  currentSpeed  ct  cnt  count

Readability  employeename  employeeName  employee_name  getTestComplete  isTestComplete

Spacing and Line Breaks  Use consistent spacing and line breaks  Indentation can show structure class Circle calculateArea apply area formula return endClass

Use Temporary Variables  Break complex algorithms down into component parts total = subtotal * (1 - discountRate) * (1 + taxRate) discount = subtotal * discountRate discountedTotal = subtotal - discount salesTax = dscountedTotal * taxRate total = discountedTotal + salesTax

Write Clear Prompts  Calculation error.  The starting balance is not valid.

Comment First, Code Second  Alternative to pseudocode and flowcharting  Stub out a class or method  Write comments to document what should happen within a method  “Rewrite” the comments as code

Example fillContactList() { // Retrieve contacts from a database // Sort contacts by last name // Add each contact to the contact list }

Programming Structures  Sequence structure Performs a series of actions in order  Selection structure Performs one action or sequence or another action or sequence based on a decision  Loop structure Repeats an action or sequence

Review  What is the value of: 8 – 4 * 6 / 4 ( 8 – 4 ) * 6 / 4 8 – 4 * ( 6 / 4 )

Exercise  Case Projects, p. 61, #1

Summary  Classes  Identifiers  Variables  Data types  Arithmetic operations and precedence  Good practices  Programming structures