Java語言程序設計與數據結構 基礎篇原書第11版PPT及其他教輔資源02slide.ppt


'Java語言程序設計與數據結構 基礎篇原書第11版PPT及其他教輔資源02slide.ppt'
*Chapter 2 Elementary Programming*MotivationsIn the preceding chapter, you learned how to create, compile, and run a Java program. Starting from this chapter, you will learn how to solve practical problems programmatically. Through these problems, you will learn Java primitive data types and related subjects, such as variables, constants, data types, operators, expressions, and input and output.*ObjectivesTo write Java programs to perform simple computations (§2.2).To obtain input from the console using the Scanner class (§2.3).To use identifiers to name variables, constants, methods, and classes (§2.4).To use variables to store data (§§2.5–2.6).To program with assignment statements and assignment expressions (§2.6).To use constants to store permanent data (§2.7).To name classes, methods, variables, and constants by following their naming conventions (§2.8).To explore Java numeric primitive data types: byte, short, int, long, float, and double (§2.9.1).To read a byte, short, int, long, float, or double value from the keyboard (§2.9.2).To perform operations using operators +, -, *, /, and % (§2.9.3).To perform exponent operations using Math.pow(a, b) (§2.9.4).To write integer literals, floating-point literals, and literals in scientific notation (§2.10).To write and evaluate numeric expressions (§2.11).To obtain the current system time using System.currentTimeMillis() (§2.12).To use augmented assignment operators (§2.13).To distinguish between postincrement and preincrement and between postdecrement and predecrement (§2.14).To cast the value of one type to another type (§2.15).To describe the software development process and apply it to develop the loan payment program (§2.16).To write a program that converts a large amount of money into smaller units (§2.17).To avoid common errors and pitfalls in elementary programming (§2.18).*Introducing Programming with an ExampleListing 2.1 Computing the Area of a Circle This program computes the area of the circle.RunComputeAreaNote: Clicking the blue button runs the code from Windows. If you cannot run the buttons, see IMPORTANT NOTE: If you cannot run the buttons, see Clicking the green button displays the source code with interactive animation. You can also run the code in a browser. Internet connection is needed for this button.*Trace a Program Executionpublic class ComputeArea { /** Main method */ public static void main(String[] args) { double radius; double area; // Assign a radius radius = 20; // Compute area area = radius * radius * 3.14159; // Display results System.out.println("The area for the circle of radius " + radius + " is " + area); }}no valueradiusallocate memory for radiusanimation*Trace a Program Executionpublic class ComputeArea { /** Main method */ public static void main(String[] args) { double radius; double area; // Assign a。省略部分。cess in terms of data flow, and to identify the system’s input and output. Part of the analysis entails modeling the system’s behavior. The model is intended to capture the essential elements of the system and to define services to the system. *System Design The process of designing the system’s components. This phase involves the use of many levels of abstraction to decompose the problem into manageable components, identify classes and interfaces, and establish relationships among the classes and interfaces.*IPO The essence of system analysis and design is input, process, and output. This is called IPO. *Implementation The process of translating the system design into programs. Separate programs are written for each component and put to work together. This phase requires the use of a programming language like Java. The implementation involves coding, testing, and debugging. *Testing Ensures that the code meets the requirements specification and weeds out bugs. An independent team of software engineers not involved in the design and implementation of the project usually conducts such testing.*Deployment Deployment makes the project available for use. For a Java program, this means installing it on a desktop or on the Web. *Maintenance Maintenance is concerned with changing and improving the product. A software product must continue to perform and improve in a changing environment. This requires periodic upgrades of the product to fix newly discovered bugs and incorporate changes. *Problem: Computing Loan PaymentsRunThis program lets the user enter the interest rate, number of years, and loan amount, and computes monthly payment and total payment.ComputeLoan*Problem: Monetary UnitsThis program lets the user enter the amount in decimal representing dollars and cents and output a report listing the monetary equivalent in single dollars, quarters, dimes, nickels, and pennies. Your program should report maximum number of dollars, then the maximum number of quarters, and so on, in this order. RunComputeChange*Common Errors and PitfallsCommon Error 1: Undeclared/Uninitialized Variables and Unused Variables Common Error 2: Integer OverflowCommon Error 3: Round-off ErrorsCommon Error 4: Unintended Integer DivisionCommon Error 5: Redundant Input ObjectsCommon Pitfall 1: Redundant Input Objects*Common Error 1: Undeclared/Uninitialized Variables and Unused Variables double interestRate = 0.05;double interest = interestrate * 45;*Common Error 2: Integer Overflowint value = 2147483647 + 1; // value will actually be -2147483648*Common Error 3: Round-off ErrorsSystem.out.println(1.0 - 0.1 - 0.1 - 0.1 - 0.1 - 0.1);System.out.println(1.0 - 0.9);*Common Error 4: Unintended Integer Division*Common Pitfall 1: Redundant Input ObjectsScanner input = new Scanner(;System.out.print("Enter an integer: ");int v1 = input.nextInt(); Scanner input1 = new Scanner(;System.out.print("Enter a double value: ");double v2 = input1.nextDouble();
關 鍵 詞:
基礎 ppt 11 及其他 結構 數據 資源 程序設計 02slide 語言
本文標題:Java語言程序設計與數據結構 基礎篇原書第11版PPT及其他教輔資源02slide.ppt
關于我們 - 網站聲明 - 網站地圖 - 資源地圖 - 友情鏈接 - 網站客服點擊這里,給天天文庫發消息,QQ:1290478887 - 聯系我們

本站為“文檔C2C交易模式”,即用戶上傳的文檔直接賣給(下載)用戶,本站只是中間服務平臺,本站所有文檔下載所得的收益歸上傳人(含作者)所有【成交的100%(原創)】。本站是網絡服務平臺方,若您的權利被侵害,侵權客服QQ:1290478887 歡迎舉報。

[email protected] 2017-2027 網站版權所有


球探网即时蓝球比分 广西十一选五今天开奖号码 内蒙古十一选五走势图表 上海11远5今天开奖结果 体彩十一选五技巧与诀窍 浙江11选5有什么规律 山东11选五走势图 江西多乐彩今天开奖号 黑龙江36选7开奖视频 怎么开户买股票 广东11选5平台