JAVA_4 - Control Statements: Part I decrement operators....

Info iconThis preview shows pages 1–4. Sign up to view the full content.

View Full Document Right Arrow Icon
decrement operators. These additional operators abbreviate and simplify many program statements. Finally, we present an overview of the primitive data types available to programmers . 4.2 . Algorithms 4.3 . Pseudocode 4.4 . Control Structures Figure 4.1. Sequence structure activity diagram . 4.5 . if Single-Selection Statement Figure 4.2. if single-selection statement UML activity diagram . 4.6 . if ... else Double-Selection Statement Good Programming Practice 4.1 Indent both body statements of an if ... else statement .
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
OBJECTIVES In this chapter you will learn : To use basic problem-solving techniques . To develop algorithms through the process of top-down, stepwise refinement . To use the if and if ... else selection statements to choose among alternative actions . To use the while repetition statement to execute statements in a program repeatedly . To use counter-controlled repetition and sentinel-controlled repetition . To use the assignment, increment and decrement operators . 4.1 . Introduction Before writing a program to solve a problem, it is essential to have a thorough understanding of the problem and a carefully planned approach to solving it. When writing a program, it is also essential to understand the types of building blocks that are available and to employ proven program-construction techniques. In this chapter and in Chapter 5 , Control Statements: Part 2, we discuss these issues in our presentation of the theory and principles of structured programming. The concepts presented here are crucial in building classes and manipulating objects . In this chapter, we introduce Java's if , if ... else and while statements, three of the building blocks that allow programmers to specify the logic required for methods to perform their tasks. We devote a portion of this chapter (and Chapters 5 and 7 ) to further developing the GradeBook class introduced in Chapter 3 . In particular, we add a method to the GradeBook class that uses control statements to calculate the average of a set of student grades. Another example demonstrates additional ways to combine control statements to solve a similar problem. We introduce Java's compound assignment operators and explore Java's increment and 4 import java.util.Scanner; // program uses class Scanner 5 6 public class GradeBook 7 }
Background image of page 2
8 private String courseName; // name of course this GradeBook represents 9 10 // constructor initializes courseName 11 public GradeBook( String name ( 12 } 13 courseName = name; // initializes courseName 14 { // end constructor 15 16 // method to set the course name 17 public void setCourseName( String name ( 18 } 19 courseName = name; // store the course name 20 { // end method setCourseName 21 22 // method to retrieve the course name 23 public String getCourseName () 24 } 25 return courseName ; 26 { // end method getCourseName 27 28 // display a welcome message to the GradeBook user 29 public void displayMessage () 30 } 31 // getCourseName gets the name of the course
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 4
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 11/14/2011 for the course MATH 401 taught by Professor H.ayad during the Spring '11 term at Cairo University.

Page1 / 21

JAVA_4 - Control Statements: Part I decrement operators....

This preview shows document pages 1 - 4. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online