作者Courake (courake)
看板FCUProblems
標題[考古] 物件導向設計/張貴忠/972-期中考
時間Tue May 19 06:02:52 2009
[開課學院]: 資電學院
[開課系所]: 資訊系
[課程名稱]: 物件導向設計
[老師名稱]: 張貴忠 老師
[開課學期]: 97-2
[類型]: 97-2 期中考
------------------------------------------------------------
1. (Basic OOD Concept - 15pts ) Just a brief explanation
(a) Class Constructor
(b) Encapsulation
(c) Overloading
2. (Class Concept -10pts ) Define the terms class and object. What's the
difference between class and object?
3. (Class Concept -10pts ) 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)?
4. (Defining Class -20pts ) Write a Java class that represents a People with
String-type instance variables name, id. Include at least 2 constructors
, 3 accessors and 3 mutators. Write a simple main program to create one
People object.
5. (Flow Control -15pts ) Write a complete Java progrm that uses a "for loop"
to compute the product of the even numbers and the sum of the odd numbers
between 1 and 25.
6. (Advanced Class & Object Concept -30pts) Find all compiler-time only in the
MidExamClass, and give brief explanation. When you correct all errors, what
is the output of the code?
public class MidExamClass
{
private String mName;
private int mNumber;
private static int mCount;
public static final int GRADE = 60;
public void set(String newName, int newNumber)
{
mName = newName;
mNumber = newNumber;
mCount++;
}
public void set(String newName, double newNumber)
{
mName = newName;
}
public boolean set(String oldName, double oldNumber)
{
mName = oldName;
}
public MidExamClass(int number)
{
this.mNumber = number;
}
public String toString()
{
return (mName + " " + mNumber + " " + mCount++);
}
public void makeEqual(MidExamClass anObject)
{
anObject.mName = this.mName;
anObject.mNumber = this.mNumber;
}
public static void tryToMakeEqual(int aNumber)
{
toString();
aNumber = this.mNumber;
}
public boolean equals(MidExamClass otherObject)
{
int grade = otherObject.GRADE;
return ((mName.equals(otherObjec.mName))
&& (mNumber == otherObject.mNumber) );
}
}//end of class definition
public class ParametersDemo
{
public static void main(String[] args)
{
MidExamClass object1 = new MidExamClass();
MidExamClass object2 = new MidExamClass();
MidExamClass object3 = new MidExamClass();
object1.set("AAA",1);
object2.set("BBB",2);
object3.set("CCC",3);
System.out.println("Valus of object2 before call:");
System.out.println(object2);
object1 = object3;
object1.makeEqual(object2);
System.out.println("Value of object2 after call:");
System.out.println(object2);
}//end of main method
}//end of class
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 140.134.213.201