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

看板FCUProblems作者 (默)時間15年前 (2010/11/04 00:53), 編輯推噓1(100)
留言1則, 1人參與, 最新討論串1/1
[開課學院]:資電學院 (ex:金融學院,商學院,理工學院,資電學院,建設學院,文學院...) [開課系所]:資訊系 (ex:中文系,外文系,電機系,財稅系..) [課程名稱]:物件導向設計 [老師名稱]:張貴忠 老師 [開課學期]:991 [類型]:99-1 期中考 ex:(第n次)小考/98-2期中考/98-2期末考 Totally 100 points 1. (Basic Concept - 10 pts) Just a brief explanation (a) Class and Object (b) Overloading 2. (Encapsulation - 20 pts) (a).Discuss the public and private modifiers in context of methods and instance variables. (b).Discuss the importance of accessor and mutator methods and how they apply to the abstraction concept. 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 3 Student object. 4. (Basic Flow Control - 20 pts) Write a complete Java program that uses a "while loop" to compute the sum of the even numbers and the sum of the odd numbers between 1 and 25(include 1 and 25). 5.(Programming Style - 10 pts)The following program will compile and run,but it uses porr programming style.Modify the program so that it uses the spelling conventions, constant naming conventions,and formatting style recommended in the book. ----------------------------------------------------------------------------- public class messy{ public static final double distance =8.21; public static void main(String[] args) { double TIME; double PACE; TIME = 45.5; PACE=TIME/distance; System.out.println("Your pace is"+PACE+"miles per hour."); } } ----------------------------------------------------------------------------- 6. (Advanced Class & Object Concept - 25 pts) (a) Find all errors in the following code, and give brief explanation. (b) Please write down the output of the program when you correct all errors. ------------------------------------------------------------------------------ public calss PClass { private String name; private int number; public PClass(int n) { name = ""; number = n; } public void set(String newName, int newNumber) { name = newName; number = newNumber; } public void set(String newName1, double newNumber1) { name = newName1; } public boolean set(String newName2, double newNumber2) { name = newName2; return true; } public String toString() { return (name + " " + number ); } public static int getNumber() { return number; } public void makeEqual(PClass anObject) { anObject.name = this.name; anObject.number = this.number; } }//End of class ------------------------------------------------------------------------------ ------------------------------------------------------------------------------ public class MidExam { public static void main(String[] args) { int objNumber; int objPrice; PClass object1 = new PClass(), PClass object2 = new PClass(); object1.set("AAA",1); object2.set("BBB",2); System.out.println("Value of object2 before call:"); System.out.println(object2); object1.makeEqual(object2); objNumber = object1.number; System.out.println("Value of object2 after call:"); System.out.println(object2); }//End of main }//End of Class ------------------------------------------------------------------------------ -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 118.170.2.251

11/04 01:39, , 1F
推好老師!!
11/04 01:39, 1F
文章代碼(AID): #1CqPEJuf (FCUProblems)