《JAVA OOP开发》英文版 Chapter 6 Selection statements

Chapter 6 Selection Statements 2000 McGraw-Hl‖ Introduction to Object-Oriented Programming with Java-Wu Chapter 6-1
© 2000 McGraw-Hill Introduction to Object-Oriented Programming with Java--Wu Chapter 6 - 1 Chapter 6 Selection Statements

Chapter 6 objectives After, you have read and studied this chapter, you shoula be able to e Implement selection control in a program using if statements e Implement selection control in a program using switch statements e Write boolean expressions using relational and boolean operators. e Evaluate given boolean expressions correctly e Nest an if statement inside another if statement's then or else part correctly e Choose the appropriate selection control statement for a gIven task e Write applications using the List Box class from javabook and the Color class from the standard java. awt package C 2000 McGraw-Hill Introduction to Object-Oriented Programming with Java--Wu Chapter 6-2
© 2000 McGraw-Hill Introduction to Object-Oriented Programming with Java--Wu Chapter 6 - 2 Chapter 6 Objectives After you have read and studied this chapter, you should be able to Implement selection control in a program using if statements. Implement selection control in a program using switch statements. Write boolean expressions using relational and boolean operators. Evaluate given boolean expressions correctly. Nest an if statement inside another if statement’s then or else part correctly. Choose the appropriate selection control statement for a given task. Write applications using the ListBox class from javabook and the Color class from the standard java.awt package

The if statement //Assume messageBox and inputBox are declared and created //Assume testscore is declared testscore inputBox. getInteger("Enter test score: )i f(testscore 70) This statement is messageBox. show("You did not pass)i executed if the testscore ess than 70 else This statement is messageBox. show("You did pass") executed if the testscore is 70 or higher C 2000 McGraw-Hill Introduction to Object-Oriented Programming with Java--Wu Chapter 6-3
© 2000 McGraw-Hill Introduction to Object-Oriented Programming with Java--Wu Chapter 6 - 3 The if Statement //Assume messageBox and inputBox are declared and created //Assume testScore is declared testScore = inputBox.getInteger("Enter test score:"); if (testScore < 70) messageBox.show("You did not pass"); else messageBox.show("You did pass"); This statement is executed if the testScore is 70 or higher. This statement is executed if the testScore is less than 70

Syntax for the if statement if( 1 se Boolean Expression ·°····。···。··。······ °。。。。。。。。。 ··················.··着·····················。 Then block messageBox. show("You did not pass")i else Else block messageBox. show( You did pass )i C 2000 McGraw-Hill Introduction to Object-Oriented Programming with Java--Wu Chapter 6-4
© 2000 McGraw-Hill Introduction to Object-Oriented Programming with Java--Wu Chapter 6 - 4 if ( testScore ) else Then Block Else Block Boolean Expression

Control flow se true testscore< 70? messageBox. show messageBox.show C You did pass"); C You did not pass"); C 2000 McGraw-Hill troduction to Object-Oriented Programming with Java--Wu Chapter 6-5
© 2000 McGraw-Hill Introduction to Object-Oriented Programming with Java--Wu Chapter 6 - 5 Control Flow messageBox.show ("You did pass"); false testScore < 70 ? messageBox.show ("You did not pass"); true

Relational Operators //less than //less than or equal to equal to //not equal to //greater than //greater than or equal to =350 2大Math. PI radi 359.99 C 2000 McGraw-Hill troduction to Object-Oriented Programming with Java--Wu Chapter 6-6
© 2000 McGraw-Hill Introduction to Object-Oriented Programming with Java--Wu Chapter 6 - 6 testScore = 350 30 //greater than >= //greater than or equal to

Compound statements r Use braces if the or block has multiple statements if (testscore 70 messageBox. show("You did not pass")i Then block messageBox. show(Try harder next time")i else messageBox. show("You did pass")i Else block message Box. show("Keep up the good work")i C 2000 McGraw-Hill Introduction to Object-Oriented Programming with Java--Wu Chapter 6-7
© 2000 McGraw-Hill Introduction to Object-Oriented Programming with Java--Wu Chapter 6 - 7 if (testScore or block has multiple statements. Then Block Else Block

Style guide f( ) else I Style 1 f( Style 2 else C 2000 McGraw-Hill troduction to Object-Oriented Programming with Java--Wu Chapter 6-8
© 2000 McGraw-Hill Introduction to Object-Oriented Programming with Java--Wu Chapter 6 - 8 if ( ) { … } else { … } Style Guide if ( ) { … } else { … } Style 1 Style 2

The if-then statement if( Boolean Expression testscore >=95 ····························································· Then block messageBox show("You are an honor student)i C 2000 McGraw-Hill Introduction to Object-Oriented Programming with Java--Wu Chapter 6-9
© 2000 McGraw-Hill Introduction to Object-Oriented Programming with Java--Wu Chapter 6 - 9 The if-then Statement if ( testScore >= 95 ) messageBox.show("You are an honor student"); if ( ) Then Block Boolean Expression

Control flow of if-then true testscore > 95? messageBox. show false C You are an honor student); C 2000 McGraw-Hill troduction to Object-Oriented Programming with Java--Wu Chapter 6-10
© 2000 McGraw-Hill Introduction to Object-Oriented Programming with Java--Wu Chapter 6 - 10 Control Flow of if-then testScore >= 95? false messageBox.show ("You are an honor student"); true
按次数下载不扣除下载券;
注册用户24小时内重复下载只扣除一次;
顺序:VIP每日次数-->可用次数-->下载券;
- 《JAVA OOP开发》英文版 Chapter 5 Processing Input with Applets.ppt
- 《JAVA OOP开发》英文版 Chapter 4 Defining Instantiable Classes.ppt
- 《JAVA OOP开发》英文版 Chapter 3 Numerical Data.ppt
- 《JAVA OOP开发》英文版 Chapter 2 Java Programming Basics.ppt
- 《JAVA OOP开发》英文版 Chapter 1 Introduction to Object-oriented Programming and Software Development.ppt
- 《JAVA OOP开发》英文版 Introduction to Computers and Programming Languages.ppt
- 《Windows DNA应用程式》 面向对象分析与设计讲义.ppt
- 北大青鸟:《程序设计基础:C语言实现》课程教学资源(PPT课件讲稿)第四章 第四讲 分支结构.ppt
- 北大青鸟:《程序设计基础:C语言实现》课程教学资源(PPT课件讲稿)第十二章 文件.ppt
- 北大青鸟:《程序设计基础:C语言实现》课程教学资源(PPT课件讲稿)第十一章 复杂数据类型及排序.ppt
- 北大青鸟:《程序设计基础:C语言实现》课程教学资源(教案讲义)第六讲 数组.doc
- 北大青鸟:《程序设计基础:C语言实现》课程教学资源(PPT课件讲稿)第六讲 数组.ppt
- 北大青鸟:《程序设计基础:C语言实现》课程教学资源(PPT课件讲稿)第七章(7-2)指针与指针变量.ppt
- 北大青鸟:《程序设计基础:C语言实现》课程教学资源(PPT课件讲稿)第五章 循环结构.ppt
- 北大青鸟:《程序设计基础:C语言实现》课程教学资源(PPT课件讲稿)第二章 数据类型与运算符.ppt
- 北大青鸟:《程序设计基础:C语言实现》课程教学资源(教案讲义)第二讲 数据类型与算术运算.doc
- 北大青鸟:《程序设计基础:C语言实现》课程教学资源(教案讲义)第九讲 函数.doc
- 北大青鸟:《程序设计基础:C语言实现》课程教学资源(PPT课件讲稿)第九章 函数.ppt
- 北大青鸟:《程序设计基础:C语言实现》课程教学资源(PPT课件讲稿)第三章 运算符与表达式.ppt
- 北大青鸟:《程序设计基础:C语言实现》课程教学资源(教案讲义)第三讲 运算与顺序结构.doc
- 《JAVA OOP开发》英文版 Chapter 7 Repetition Statements.ppt
- 《JAVA OOP开发》英文版 Chapter 8 Characters and strings.ppt
- 《JAVA OOP开发》英文版 Chapter 9 objectives.ppt
- 《JAVA OOP开发》英文版 Chapter 10 Sorting and Searching.ppt
- 《JAVA OOP开发》英文版 Chapter 11 File Input and Output.ppt
- 《JAVA OOP开发》英文版 Chapter 12 Reusable classes and packages.ppt
- 《JAVA OOP开发》英文版 Chapter 13 GUI Objects and Event-Driven Programming.ppt
- 《JAVA OOP开发》英文版 Chapter 14 Inheritance and Polymorphism.ppt
- 《JAVA OOP开发》英文版 Chapter 15 Case Study Class Roster Maintenance program.ppt
- 《JAVA OOP开发》英文版 Chapter 16 Chapter 16 Recursive algorithms.ppt
- 人民邮电出版社:高职高专现代信息技术系列教材《单片机原理与接口技术》课程电子教案(PPT课件讲稿)第一章 绪论.ppt
- 人民邮电出版社:高职高专现代信息技术系列教材《单片机原理与接口技术》课程电子教案(PPT课件讲稿)第七章 牛行接与应用.ppt
- 人民邮电出版社:高职高专现代信息技术系列教材《单片机原理与接口技术》课程电子教案(PPT课件讲稿)第三章 MCS-51单片机指令系统.ppt
- 人民邮电出版社:高职高专现代信息技术系列教材《单片机原理与接口技术》课程电子教案(PPT课件讲稿)第九章 A/D、D/A转换接口.ppt
- 人民邮电出版社:高职高专现代信息技术系列教材《单片机原理与接口技术》课程电子教案(PPT课件讲稿)第二章 MCS-51学机组成理.ppt
- 人民邮电出版社:高职高专现代信息技术系列教材《单片机原理与接口技术》课程电子教案(PPT课件讲稿)第五章 输入/输出与中断.ppt
- 人民邮电出版社:高职高专现代信息技术系列教材《单片机原理与接口技术》课程电子教案(PPT课件讲稿)第八章 并行接口与应用.ppt
- 人民邮电出版社:高职高专现代信息技术系列教材《单片机原理与接口技术》课程电子教案(PPT课件讲稿)第六章 定时器/计数器及应用.ppt
- 人民邮电出版社:高职高专现代信息技术系列教材《单片机原理与接口技术》课程电子教案(PPT课件讲稿)第十章 单片机应用系统设计与开发.ppt
- 人民邮电出版社:高职高专现代信息技术系列教材《单片机原理与接口技术》课程电子教案(PPT课件讲稿)第四章 MCS-51单片机存储器的扩展.ppt