物件導向實習 07 97.11.17. 極高的忘記答題率 … AB 卷都有的題目 : 4(1). Define method overloading 明明寫出了方法, 卻不回答老師的題目 (1)( 只要 寫出定義就好了 ) 另外, 讀題一定要仔細 : Two overloaded methods average.

Slides:



Advertisements
Similar presentations
 Overloading Methods  The Scope of Variables  The Math Class  Floating point Format [Sample code] TestMethodOverloading.java 、 AmbiguousOverloading.java.
Advertisements

Introduction to Java Programming Lecture 10 Method Benefits, Declaring, and Calling Methods.
1 生物計算期末作業 暨南大學資訊工程系 2003/05/13. 2 compare f1 f2  只比較兩個檔案 f1 與 f2 ,比完後將結果輸出。 compare directory  以兩兩比對的方式,比對一個目錄下所有檔案的相 似程度。  將相似度很高的檔案做成報表輸出,報表中至少要.
Divide-and-Conquer. 什麼是 divide-and-conquer ? Divide 就是把問題分割 Conquer 則是把答案結合起來.
Introduction to Java Programming Lecture 13 Classes I OO Programming.
第 10 章 Java 的執行緒 10-1 執行緒的基礎 10-2 Java 執行緒的使用方法 10-3 Java 執行緒的同步 10-4 管道串流的執行緒.
: A-Sequence 星級 : ★★☆☆☆ 題組: Online-judge.uva.es PROBLEM SET Volume CIX 題號: Problem D : A-Sequence 解題者:薛祖淵 解題日期: 2006 年 2 月 21 日 題意:一開始先輸入一個.
Event Sampling 事件取樣法. 關心重點為「事件」本身明確的焦點 行為 清楚掌握主題 - 當「事件」出現時才開 始記錄 記錄程序 等待目標事件的發生 開始記錄 事件結束,停止記錄.
Advanced Chemical Engineering Thermodynamics
Reference, primitive, call by XXX 必也正名乎 誌謝 : 部份文字取於前輩 TAHO 的文章.
Introduction to Constructor, Overloading, and Accessibility CS340100, NTHU Yoshi.
Using High and Low Level Communication in Agile Method Presenter: 花金地.
What is static?. Static? 靜態 ? class Test { static int staticX; int instanceX; public Test(int var1, int var2) { this.staticX = var1; this.instanceX =
中央大學。范錚強 1 其他 ER 相關觀念 以及 OO 模型 國立中央大學 資訊管理系 范錚強 2007.
Review of Chapter 3 - 已學過的 rules( 回顧 )- 朝陽科技大學 資訊管理系 李麗華 教授.
建立靜態資料成員 關鍵字: static 靜態資料成員不屬於特定物件,而是該類物件 所共同擁有的,可做為類別範圍裡的靜態變數。
1 Introduction to Java Programming Lecture 4 Using JOptionPane Spring 2008.
Hint of Homework 4 jinnjy. Outline Hint of exercise 3.18.
Introduction to Java Programming Lecture 5: Using Java Classes : String & Math Spring 2009.
圖片索引專題 指導教授:陳淑媛 教授 黃伯偉 林育瑄. 動機 & 理念  目前圖像檢索系統中使用的大多都為利用文字 標籤圖像或是圖像輪廓特徵來進行搜尋,然而 輪廓特徵的缺點卻是所有組成圖像的線條都要 逐一處理相當耗時。  所以本研究的目標在於,提出一個以像素點為 特徵的有效率與正確率的圖像檢索演算法實作。
第 1 章 PC 的基本構造. 本章提要 PC 系統簡介 80x86 系列 CPU 及其暫存器群 記憶體: Memory 80x86 的分節式記憶體管理 80x86 的 I/O 結構 學習組合語言的基本工具.
Introduction to Java Programming Lecture 15 Objects and Classes.
Chapter 13 塑模靜態觀點:物件圖 Static View : Object Diagram.
Introduction to Java Programming Lecture 17 Abstract Classes & Interfaces.
第 1 章 認識資料庫系統 著作權所有 © 旗標出版股份有限公司.
Introduction to Java Programming Lecture 10 Array I Declaring, Creating, and Initializing Arrays.
Chapter 20 塑模動態觀點:狀態圖 Statechart Diagram. 學習目標  說明狀態圖的目的  定義狀態圖的基本記號  展示狀態圖的建構  定義活動、內部事件及遞延事件的狀態 圖記號.
: Fast and Easy Data Compressor ★★☆☆☆ 題組: Problem Set Archive with Online Judge 題號: 10043: Fast and Easy Data Compressor 解題者:葉貫中 解題日期: 2007 年 3.
McGraw-Hill/Irwin © 2003 The McGraw-Hill Companies, Inc.,All Rights Reserved. 參 資料蒐集的方法.
1 透過 IT 電子商務和知識管 理應用之探討 指導老師:李富民 教授 報告者:許志傑 學號: 職 1A 報告日期 :97/01/14.
Outline Overloading Methods The Scope of Variables The Math Class Floating point Format [Sample code] TestMethodOverloading.java.
: Multisets and Sequences ★★★★☆ 題組: Problem Set Archive with Online Judge 題號: 11023: Multisets and Sequences 解題者:葉貫中 解題日期: 2007 年 4 月 24 日 題意:在這個題目中,我們要定義.
資料結構實習-一 參數傳遞.
企二 A 管理程式設計 Visual Basic 6.0 Visual Basic 6.0 Visual Basic 6.0 企二 A 管理程式設計 Visual Basic 6.0 Visual Basic 6.0 Visual Basic 6.0許翠婷
1 Introduction to Java Programming Lecture 2: Basics of Java Programming Spring 2008.
: A-Sequence ★★★☆☆ 題組: Problem Set Archive with Online Judge 題號: 10930: A-Sequence 解題者:陳盈村 解題日期: 2008 年 5 月 30 日 題意: A-Sequence 需符合以下的條件, 1 ≤ a.
Section 4.2 Probability Models 機率模式. 由實驗看機率 實驗前先列出所有可能的實驗結果。 – 擲銅板:正面或反面。 – 擲骰子: 1~6 點。 – 擲骰子兩顆: (1,1),(1,2),(1,3),… 等 36 種。 決定每一個可能的實驗結果發生機率。 – 實驗後所有的實驗結果整理得到。
Teacher : Ing-Jer Huang TA : Chien-Hung Chen 2015/6/25 Course Embedded Systems : Principles and Implementations Weekly Preview Question CH 2.4~CH 2.6 &
JAVA 程式設計與資料結構 第二十章 Searching. Sequential Searching Sequential Searching 是最簡單的一種搜尋法,此演 算法可應用在 Array 或是 Linked List 此等資料結構。 Sequential Searching 的 worst-case.
演算法 8-1 最大數及最小數找法 8-2 排序 8-3 二元搜尋法.
2010 MCML introduction 製作日期: 2010/9/10 製作人 : 胡名霞.
Windows Processing Design1 Chapter 1 C/C++ 概論 畫面輸出與鍵盤輸入 程式流程 程式流程的迴圈 函數的基礎 指標與陣列 字串 類別 利用 BCB 開發程式.
Introduction to Java Programming Lecture 9 Flow Control : while do-while and for loops II.
第 17 章 樣板 17-1 樣板的基礎 17-1 樣板的基礎 17-2 樣板函數 17-2 樣板函數 17-3 樣板類別 17-3 樣板類別 17-4 非型態參數的樣板類別 17-4 非型態參數的樣板類別 17-5 樣板類別的繼承 17-5 樣板類別的繼承 17-6 特化樣板與靜態成員 17-6 特化樣板與靜態成員.
Chapter 10 m-way 搜尋樹與B-Tree
: Function Overloading ★★★☆☆ 題組: Problem Set Archive with Online Judge 題號: 11032:Function Overloading 解題者:許智祺 解題日期: 2007 年 5 月 8 日 題意:判對輸入之數字是否為.
Extreme Discrete Summation ★★★★☆ 題組: Contest Archive with Online Judge 題號: Extreme Discrete Summation 解題者:蔡宗翰 解題日期: 2008 年 10 月 13 日.
1 Introduction to Java Programming Lecture 4 Using JOptionPane Spring 2010.
Inheritance and Polymorphism
組合語言與系統程式 軟體使用教學. 軟體下載及安裝 下載 到課程網頁下載 tw/~jiun/ 安裝 解壓縮後將 System Software 資料夾放在 D 槽 (C 槽版本放在 C 之下 )
1 Introduction to Java Programming Lecture 2: Basics of Java Programming Spring 2009.
2005/7 Linear system-1 The Linear Equation System and Eliminations.
McGraw-Hill/Irwin © 2003 The McGraw-Hill Companies, Inc.,All Rights Reserved. 壹 企業研究導論.
Java class Outline Defining a method Calling Method Passing parameters [Sample code] TestMethod.java 、 TestMethod2.java 、 GCD.java 、 prime.java.
Introduction to Java Programming Lecture 12 Method Benefits, Declaring, and Calling Methods.
04/8/19資工研所李桐照 暑期進度報告. Outline Visual C++ Visual C++ Data Compression Data Compression 未來進度 未來進度.
Visual C++重點複習.
資料結構實習-六.
1 Introduction to Java Programming Lecture 3 Mathematical Operators Spring 2008.
1 Introduction to Java Programming Lecture 2: Basics of Java Programming Spring 2010.
C 語言練習題 2010/12/2. C 程式的格式 一、 C 程式的格式 (1). /* …. */ 是 C 程式的 ______ main() 的內容是由敘述構成的 (2). 敘述要以 __ 為結束符號 (3). 變數、函數都要做 ____ 的宣告 (4). ‘=’ 是 ____ 用的算符 (5).
Introduction to Java Programming Lecture 16 Super and Sub Classes.
: Finding Paths in Grid ★★★★☆ 題組: Contest Archive with Online Judge 題號: 11486: Finding Paths in Grid 解題者:李重儀 解題日期: 2008 年 10 月 14 日 題意:給一個 7 個 column.
幼兒行為觀察與記錄 第八章 事件取樣法.
1 Introduction to Java Programming Lecture 3 Mathematical Operators Spring 2009.
第 1 章 PC 的基本構造. 本章提要 PC 系統簡介 80x86 系列 CPU 及其暫存器群 記憶體: Memory 80x86 的分節式記憶體管理 80x86 的 I/O 結構 學習組合語言的基本工具.
C++ Control Structures 程式的控制、運算、判斷跟你之前學過的程式語言是類 似的,所以這裡我們只用程式碼來說明。 你應該而且必須能看得懂這些程式 !!
1 運算子多載 鄭士康國立台灣大學 電機工程學系 / 電信工程研究所 / 資訊網路與多媒體研究所.
P. 1 C++ 的多面性 (Overloading) o 使一個算符或函式具有處理多種資料型別能力的方法稱為複載 (Overloading) o C++ 中對複載的意義為 : 讓同一種名稱或用法具有多種意義 o 當我們定義多個具有相同名稱, 但卻 m 有不同參數個數或 m 相同參數個數但參數型別不同.
Speaker: Liu Yu-Jiun Date: 2009/4/15
Presentation transcript:

物件導向實習

極高的忘記答題率 … AB 卷都有的題目 : 4(1). Define method overloading 明明寫出了方法, 卻不回答老師的題目 (1)( 只要 寫出定義就好了 ) 另外, 讀題一定要仔細 : Two overloaded methods average are used in C2. 那就是要寫 兩個同名字的 method.

A1 – A2 1. Write an application that uses an enhanced for statement to sum the integer values passed by the command-line arguments. Finally, prints the sum and the number of integers entered. 2. Finish the following program by completing the main method and giving the class C2. In class C2, the method add adds a row of array a and a row of b and places the result in sum. The method display outputs the array sum. public class Problem2 { public static void main( String args[] ) { int a[][]= {{1,2,3}, {4,5,6}}; int b[][]= {{5,7,3}, {1,3,9}}; int sum[][]... ; C2 obj2 = new C2();.... obj2.add(a[], b[], sum[]);.... obj2.display(sum); }

解題 A a b sum

A3 3. (1) Define Method Overloading (2) Complete the following program by giving the class C2, which returns the maximum of two integers or three integers. Two overloaded methods max are used in C2. public class Problem3 { public static void main( String args[] ) { System.out.println(C2.max(4, 5)); // print the maximum of two integers System.out.println(C2.max(1, 5, 7)); // print the maximum of three integers }

A4 4. Finish the following Java program by completing the class Problem4. The program creates an array of Student. That is, an array of NUMBER_OF_STUDENT objects. Each of them have a field score. The program inputs the score in every object and increments the scores by one. Finally, outputs the scores. Method increment increases the score by one and method display outputs the final score. You are not allowed to change class Student. public class Problem4 { public static void main( String args[] ) { Student list3a[]; final int NUMBER_OF_STUDENTS = 5; int num; Scanner input = new Scanner( System.in ); list3a = new Student[NUMBER_OF_STUDENTS]; for (int i = 0; i < NUMBER_OF_STUDENTS; i++) { // create object and input an integer } incandprint(....); } public static void incandprint(....) {....// call increment( ) and display( ) }

A4 public class Student { private int score; public Student(int num) { score = num; } public void increment() { score++; } public void display() { System.out.printf("%4d", score); }

B1 同 A4 1. Finish the following Java program by completing the class Problem1. The program creates an array of Student. That is, an array of NUMBER_OF_STUDENT objects. Each of them have a field score. The program inputs the score in every object and increments the scores by one. Finally, outputs the scores. Method increment increases the score by one and method display outputs the final score. You are not allowed to change class Student. public class Problem1 { public static void main( String args[] ) { Student list3a[]; final int NUMBER_OF_STUDENTS = 5; int num; Scanner input = new Scanner( System.in ); list3a = new Student[NUMBER_OF_STUDENTS]; for (int i = 0; i < NUMBER_OF_STUDENTS; i++) { // create object and input an integer } incandprint(....); } public static void incandprint(....) {....// call increment( ) and display( ) }

B1 public class Student { private int score; public Student(int num) { score = num; } public void increment() { score++; } public void display() { System.out.printf("%4d", score); }

B2-B3 (B3 同 A2) 2. Write an application that gets an integer passed by the command-line arguments. Suppose the integer is n. Create an array of n integers. The array is filled by the integers between 1 and 10 generated by the class Random. Finally, output the integers in the array sequentially and the frequency (the number of appearances) of each integer. 3. Finish the following program by completing the main method and giving the class C2. In class C2, the method add adds array a and b and places the result in sum.The method display outputs the array sum. public class Problem3 { public static void main( String args[] ) { int a[][]= {{1,2,3}, {4,5,6}}; int b[][]= {{5,7,3}, {1,3,9}}; int sum[][]... ; C2 obj2 = new C2(); obj2.add(a, b, sum);.... obj2.display(sum[]); }

B4 類似於 A3 4. (1) Define Method Overloading (2) Complete the following program by giving the class C2, which returns the average of two integers or three integers. Two overloaded methods average are used in C2. public class Problem4 { public static void main( String args[] ) { System.out.println(C2.average(4, 5)); //print the average of two integers System.out.println(C2.average(1, 6, 8)); //print the average of three integers }

Method Overloading 方法多載 Methods of the same name can be declared in the same class, as long as they have different sets of parameters (number, types and order of the parameters). Void method1(int a, float b) Void method1(float a, int b) 多載是指利用相同的名字, 不同的參數及不同 的資料型態, 定義屬性和方法. 多載化程式的目 的是希望以相同的介面處理不同的物件, 以簡 化系統發展的複雜性并增加其彈性.