[考古] 物件導向設計/張貴忠/971-期中考

看板FCUProblems作者 (秦缺)時間16年前 (2009/03/14 15:48), 編輯推噓0(001)
留言1則, 1人參與, 最新討論串1/1
[開課學院]:資電學院 (ex:金融學院,商學院,理工學院,資電學院,建設學院,文學院...) [開課系所]:資訊系 (ex:中文系,外文系,電機系,財稅系..) [課程名稱]:物件導向設計 [老師名稱]:張貴忠 老師 [開課學期]:971 [類型]:97-1 期中考 ex:(第n次)小考/98-2期中考/98-2期末考 Totally 100 points 1. (Basic Concept - 20 pts) Just a brief explanation (a) Class Constructor (b) Class vs. Object (c) Encapsulation (d) Overloading 2. (Class Concept - 15 pts) When used with objects, what is the equality (==) operator really comparing? How to design a real equality operation to compare the content of two objects (briefly describe)? 3. (Defining Class - 25 pts) Write a Java class that represents a Student with String-type instance variables name and id. In addition, please define at least 2 constructors, 2 accessor methods and 2 mutator methods for the class. Write a simple main program to create a Student object. 4. (Basic Flow Control - 20 pts) Write a complete Java program that uses a "for loop" to compute the sum of the even numbers and the sum of the odd numbers between 1 and 25. 5. (Advanced Class & Object Concept - 25 pts) Find all errors in the following code, and give brief explanation. Please write down the output of the program when you correct all errors. ------------------------------------------------------------------------------ public calss ToyClass2 { private String name; private int number; private static int count; public ToyClass2(int n) { name = ""; number = n; count = 0; } public void set(String newName, int newNumber) { name = newName; number = newNumber; count ++; } public void set(String newName1, double newNumber1) { name = newName1; } public boolean set(String newName2, double newNumber2) { name = newName2; return true; } public static int getNumber() { return number; } public String toString() { return (name + " " + number ); } public void makeEqual(ToyClass2 anObject) { anObject.name = this.name; anObject.number = this.number; } }//End of class ------------------------------------------------------------------------------ ------------------------------------------------------------------------------ public class ParametersDemo { public static void main(String[] args) { ToyClass2 object1 = new ToyClass2(), object2 = new ToyClass2(); object1.set("AAA",1); object2.set("BBB",2); System.out.println("Value of object2 before call:"); System.out.println(object2); object1.makeEqual(object2); System.out.println("Value of object2 after call:"); System.out.println(object2); }//End of main }//End of Class ------------------------------------------------------------------------------ -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 140.134.237.201

03/14 16:33, , 1F
虛線內為程式
03/14 16:33, 1F
文章代碼(AID): #19ks5OF7 (FCUProblems)