Sections 4.10-4.15 © Copyright 1992-2012 by Pearson Education, Inc. All Rights Reserved.

Slides:



Advertisements
Similar presentations
4 Control Statements: Part 1.
Advertisements

STRING AN EXAMPLE OF REFERENCE DATA TYPE. 2 Primitive Data Types  The eight Java primitive data types are:  byte  short  int  long  float  double.
Chapter 41 Variables and JSP Control Structures JavaServer Pages By Xue Bai.
 2006 Pearson Education, Inc. All rights reserved Control Statements: Part 1.
C How to Program, 6/e Summary © by Pearson Education, Inc. All Rights Reserved.
INSTRUCTOR: SHIH-SHINH HUANG Windows Programming Using Java Chapter4: Control Statements Part I.
©2004 Brooks/Cole Chapter 2 Variables, Values and Operations.
 2002 Prentice Hall. All rights reserved. 1 Outline 4.1 Introduction 4.2 Algorithms 4.3 Pseudocode 4.4 Control Structures 4.5 The if Selection Structure.
Introduction to Computers and Programming Lecture 7:
Chapter 4 - Control Structures: Part 1 Outline 4.4Control Structures 4.5The if Selection Structure 4.6The if/else Selection Structure 4.7The while Repetition.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Chapter 3 - Structured Program Development Outline.
Java Syntax Primitive data types Operators Control statements.
 2008 Pearson Education, Inc. All rights reserved Control Statements: Part 1.
 2003 Prentice Hall, Inc. All rights reserved. 1 Outline 4.1 Introduction 4.2 Algorithms 4.3 Pseudocode 4.4 Control Structures 4.5 if Single-Selection.
Structured Program Development in C
 2003 Prentice Hall, Inc. All rights reserved. 1 Outline 4.1 Introduction 4.2 Algorithms 4.3 Pseudocode 4.4 Control Structures 4.5 if Single-Selection.
Java™ How to Program, 9/e © Copyright by Pearson Education, Inc. All Rights Reserved.
Chapter 2: Basic Elements of Java J ava P rogramming: From Problem Analysis to Program Design, From Problem Analysis to Program Design, Second Edition.
Object-Oriented Programming Using C++ Third Edition Chapter 2 Evaluating C++ Expressions.
Chapter 2 Basic Elements of Java. Chapter Objectives Become familiar with the basic components of a Java program, including methods, special symbols,
1 Do you have a CS account? Primitive types –“ building blocks ” for more complicated types Java is strongly typed –All variables in a Java program must.
LESSON 6 – Arithmetic Operators
Introduction to Java Applications Part II. In this chapter you will learn:  Different data types( Primitive data types).  How to declare variables?
Java™ How to Program, 9/e © Copyright by Pearson Education, Inc. All Rights Reserved.
CSCI 1100/1202 January 28, The switch Statement The switch statement provides another means to decide which statement to execute next The switch.
C++ Programming: Basic Elements of C++.
Nested Control Structures * Conditional Operator (?:) * Preincrement and Postincrement * Predecrement and Postdecrement * Counter-Controlled Repetition.
Java Programming: From Problem Analysis to Program Design, 4e Chapter 2 Basic Elements of Java.
 2008 Pearson Education, Inc. All rights reserved Control Statements: Part 1.
Lesson 3 – Primitive Data Types Objective: Students will investigate the definition and usage of objects and primitive data types in Java in order to practice.
Internet & World Wide Web How to Program, 5/e © by Pearson Education, Inc. All Rights Reserved.
 2003 Prentice Hall, Inc. All rights reserved. 1 Chapter 4 - Control Structures: Part 1.
1 Outline 4.1 Introduction 4.2 Algorithms 4.3 Pseudocode 4.4 Control Structures 4.5 The if Selection Structure 4.6 The if / else Selection Structure 4.7.
© 2013 Ken Howard, Southern Methodist University CSE 1341 Topic 3 Control Statements.
Android How to Program, 2/e © Copyright by Pearson Education, Inc. All Rights Reserved.
 2008 Pearson Education, Inc. All rights reserved JavaScript: Control Statements I.
 Pearson Education, Inc. All rights reserved Control Statements: Part 1.
 2003 Prentice Hall, Inc. All rights reserved. 1 Outline 4.1 Introduction 4.2 Algorithms 4.3 Pseudocode 4.4 Control Structures 4.5 if Single-Selection.
 2008 Pearson Education, Inc. All rights reserved Control Statements: Part 1.
Visual C# 2012 How to Program © by Pearson Education, Inc. All Rights Reserved. 1.
Java™ How to Program, 9/e © Copyright by Pearson Education, Inc. All Rights Reserved.
Java™ How to Program, 9/e © Copyright by Pearson Education, Inc. All Rights Reserved.
Introduction to Java Applications Part II. In this chapter you will learn:  Different data types( Primitive data types).  How to declare variables?
Introduction to Computers and Programming Lecture 7:
 2006 Pearson Education, Inc. All rights reserved Control Statements: Part 1.
 2003 Prentice Hall, Inc. All rights reserved. 1 Will not cover 4.14, Thinking About Objects: Identifying Class Attributes Chapter 4 - Control Structures.
Java Programming: From Problem Analysis to Program Design, Second Edition 1 Lecture 1 Objectives  Become familiar with the basic components of a Java.
Lecture 5: Layers of Control. Nested while Loops Problem Multiplying two numbers and outputting the result only if they are both less than 5. (i.e. Start.
ECE122 Feb 10, Unary Operator An operator that takes only a single operand Plus: + Minus: – Cast: (type). E.g. (double)
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Chapter 3 - Structured Program Development Outline.
 2006 Pearson Education, Inc. All rights reserved if…else Double-Selection Statement if – Performs action if condition true if…else – Performs.
Chapter 3 Structured Program Development in C Part II C How to Program, 8/e, GE © 2016 Pearson Education, Ltd. All rights reserved.1.
1 Chapter 4 - Control Statements: Part 1 Outline 4.1 Introduction 4.4 Control Structures 4.5 if Selection Structure 4.6 if/else Selection Structure 4.7.
Chapter 7 JavaScript: Control Statements, Part 1
Appendix C Control Statements
Control Statements: Part 1
Topic 3, Selection Statements
Formulating Algorithms, Repetition Control Statements
Chapter 5- part 2 Control Statements: Loops 2
CET 3640 – Lecture 2 Java Syntax Chapters 2, 4, 5
Structured Program
3 Control Statements:.
Chapter 5 Control Statements: Loops 2
Assignment Operators Topics Increment and Decrement Operators
Java Programming Language
Chapter 4 - Control Structures: Part 1
EPSII 59:006 Spring 2004.
OBJECT ORIENTED PROGRAMMING I LECTURE 4 PART 2 GEORGE KOUTSOGIANNAKIS
Chapter 3 Introduction to Classes, Objects Methods and Strings
Assignment Operators Topics Increment and Decrement Operators
Presentation transcript:

Sections © Copyright by Pearson Education, Inc. All Rights Reserved.

 This case study examines nesting one control statement within another.  A college offers a course that prepares students for the state licensing exam for real estate brokers. Last year, ten of the students who completed this course took the exam. The college wants to know how well its students did on the exam. You’ve been asked to write a program to summarize the results. You’ve been given a list of these 10 students. Next to each name is written a 1 if the student passed the exam or a 2 if the student failed. © Copyright by Pearson Education, Inc. All Rights Reserved.

 This case study examines nesting one control statement within another.  Your program should analyze the results of the exam as follows:  Input each test result (i.e., a 1 or a 2). Display the message “Enter result” on the screen each time the program requests another test result.  Count the number of test results of each type.  Display a summary of the test results, indicating the number of students who passed and the number who failed.  If more than eight students passed the exam, print the message “Bonus to instructor!” © Copyright by Pearson Education, Inc. All Rights Reserved.

 Compound assignment operators abbreviate assignment expressions.  Statements like variable = variable operator expression; where operator is one of the binary operators +, -, *, / or % can be written in the form variable operator= expression;  Example: c = c + 3; can be written with the addition compound assignment operator, +=, as c += 3;  The += operator adds the value of the expression on its right to the value of the variable on its left and stores the result in the variable on the left of the operator. © Copyright by Pearson Education, Inc. All Rights Reserved.

 Unary increment operator, ++, adds one to its operand  Unary decrement operator, --, subtracts one from its operand  An increment or decrement operator that is prefixed to (placed before) a variable is referred to as the prefix increment or prefix decrement operator, respectively.  An increment or decrement operator that is postfixed to (placed after) a variable is referred to as the postfix increment or postfix decrement operator, respectively. © Copyright by Pearson Education, Inc. All Rights Reserved.

 Using the prefix increment (or decrement) operator to add (or subtract) 1 from a variable is known as preincrementing (or predecrementing) the variable.  Preincrementing (or predecrementing) a variable causes the variable to be incremented (decremented) by 1; then the new value is used in the expression in which it appears.  Using the postfix increment (or decrement) operator to add (or subtract) 1 from a variable is known as postincrementing (or postdecrementing) the variable.  This causes the current value of the variable to be used in the expression in which it appears; then the variable’s value is incremented (decremented) by 1. © Copyright by Pearson Education, Inc. All Rights Reserved.

 Appendix D lists the eight primitive types in Java.  Java requires all variables to have a type.  Java is a strongly typed language.  Primitive types in Java are portable across all platforms.  Instance variables of types char, byte, short, int, long, float and double are all given the value 0 by default. Instance variables of type boolean are given the value false by default.  Reference-type instance variables are initialized by default to the value null. © Copyright by Pearson Education, Inc. All Rights Reserved.