作者MOTG (秦缺)
看板FCUProblems
标题[考古] 物件导向设计/张贵忠/971-期中考
时间Sat Mar 14 15:48:33 2009
[开课学院]:资电学院
(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
1F:→ MOTG :虚线内为程式 03/14 16:33