• /  55
  • 下載費用: 9.90積分  

Java語言程序設計10E LiangPPT習題案例10slide.ppt

'Java語言程序設計10E LiangPPT習題案例10slide.ppt'
*Chapter 10 Thinking in Objects*MotivationsYou see the advantages of object-oriented programming from the preceding chapter. This chapter will demonstrate how to solve problems using the object-oriented paradigm. *ObjectivesTo apply class abstraction to develop software (§10.2).To explore the differences between the procedural paradigm and object-oriented paradigm (§10.3).To discover the relationships between classes (§10.4).To design programs using the object-oriented paradigm (§§10.5–10.6).To create objects for primitive values using the wrapper classes (Byte, Short, Integer, Long, Float, Double, Character, and Boolean) (§10.7).To simplify programming using automatic conversion between primitive types and wrapper class types (§10.8).To use the BigInteger and BigDecimal classes for computing very large numbers with arbitrary precisions (§10.9).To use the String class to process immutable strings (§10.10).To use the StringBuilder and StringBuffer classes to process mutable strings (§10.11).*Class Abstraction and EncapsulationClass abstraction means to separate class implementation from the use of the class. The creator of the class provides a description of the class and let the user know how the class can be used. The user of the class does not need to know how the class is implemented. The detail of implementation is encapsulated and hidden from the user. *Designing the Loan ClassTestLoanClassRunLoan *Object-Oriented ThinkingChapters 1-8 introduced fundamental programming techniques for problem solving using loops, methods, and arrays. The studies of these techniques lay a solid foundation for object-oriented programming. Classes provide more flexibility and modularity for building reusable software. This section improves the solution for a problem introduced in Chapter 3 using the object-oriented approach. From the improvements, you will gain the insight on the differences between the procedural programming and object-oriented programming and see the benefits of developing reusable code using objects and classes.*The BMI ClassUseBMIClassRunBMI *Object CompositionComposition is actually a special case of the aggregation relationship. Aggregation models has-a relationships and represents an ownership relationship between two objects. The owner object is called an aggregating object and its class an aggregating class. The subject object is called an aggregated object and its class an aggregated class. *Class RepresentationAn aggregation relationship is usually represented as a data field in the aggregating class. For example, the relationship in Figure 10.6 can be represented as follows:*Aggregation or Composition Since aggregation and composition relationships are represented using classes in similar ways, many texts don’t differentiate them and call both compositions.*Aggregation Between Same ClassAggregation may exist between objects of the same class. For example, a person may have a supervisor. public class Person { // The ty。省略部分。rns The replaceAll, replaceFirst, and split methods can be used with a regular expression. For example, the following statement returns a new string that replaces $, +, or # in "a+b$#c" by the string NNN.String s = "a+b$#c".replaceAll("[$+#]", "NNN");System.out.println(s);Here the regular expression [$+#] specifies a pattern that matches $, +, or #. So, the output is aNNNbNNNNNNc. *Matching, Replacing and Splitting by Patterns The following statement splits the string into an array of strings delimited by some punctuation marks.String[] tokens = "Java,C?C#,C++".split("[.,:;?]"); for (int i = 0; i < tokens.length; i++) System.out.println(tokens[i]);*Convert Character and Numbers to StringsThe String class provides several static valueOf methods for converting a character, an array of characters, and numeric values to strings. These methods have the same name valueOf with different argument types char, char[], double, long, int, and float. For example, to convert a double value to a string, use String.valueOf(5.44). The return value is string consists of characters ‘5’, ‘.’, ‘4’, and ‘4’. *StringBuilder and StringBufferThe StringBuilder/StringBuffer class is an alternative to the String class. In general, a StringBuilder/StringBuffer can be used wherever a string is used. StringBuilder/StringBuffer is more flexible than String. You can add, insert, or append new contents into a string buffer, whereas the value of a String object is fixed once the string is created. *StringBuilder Constructors*Modifying Strings in the Builder*ExamplesstringBuilder.append("Java");stringBuilder.insert(11, "HTML and ");stringBuilder.delete(8, 11) changes the builder to Welcome Java.stringBuilder.deleteCharAt(8) changes the builder to Welcome o Java.stringBuilder.reverse() changes the builder to avaJ ot emocleW.stringBuilder.replace(11, 15, "HTML") changes the builder to Welcome to HTML.stringBuilder.setCharAt(0, 'w') sets the builder to welcome to Java. *The toString, capacity, length, setLength, and charAt Methods *Problem: Checking Palindromes Ignoring Non-alphanumeric CharactersThis example gives a program that counts the number of occurrence of each letter in a string. Assume the letters are not case-sensitive. PalindromeIgnoreNonAlphanumeric Run*Regular ExpressionsA regular expression (abbreviated regex) is a string that describes a pattern for matching a set of strings. Regular expression is a powerful tool for string manipulations. You can use regular expressions for matching, replacing, and splitting strings. Appendix H*Matching Strings"Java".matches("Java");"Java".equals("Java");"Java is fun".matches("Java.*")"Java is cool".matches("Java.*")"Java is powerful".matches("Java.*")Appendix H*Regular Expression SyntaxAppendix H*Replacing and Splitting StringsAppendix H*ExamplesString s = "Java Java Java".replaceAll("v\\w", "wi") ;String s = "Java Java Java".replaceFirst("v\\w", "wi") ;String[] s = "Java1HTML2Perl".split("\\d");Appendix H
關 鍵 詞:
10 liangppt 習題 10e 案例 程序設計 10slide 語言 java slide
 天天文庫所有資源均是用戶自行上傳分享,僅供網友學習交流,未經上傳用戶書面授權,請勿作他用。
關于本文
本文標題:Java語言程序設計10E LiangPPT習題案例10slide.ppt
鏈接地址: http://www.476824.live/p-51617564.html
關于我們 - 網站聲明 - 網站地圖 - 資源地圖 - 友情鏈接 - 網站客服點擊這里,給天天文庫發消息,QQ:1290478887 - 聯系我們

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

[email protected] 2017-2027 http://www.476824.live 網站版權所有

粵ICP備19057495號 

收起
展開
球探网即时蓝球比分 配资咨询 快乐8玩法 股票的交易规则 陕西快乐十分基本走势图 时时彩玩法中奖规则 最安全的理财软件 黑龙江11选5开奖结果最新 幸运28评测网 浙江体彩6 1预测 股票指数怎么买