星期六, 12月 29, 2007

勤練程式

國外公司如微軟,Google應徵新人會考程式,國內手機, NB, GPS大廠其實也類似,最近我們的學生找Firmware Engineer工作,臨時被考程式能力。今年中央大學網路學習所的甄試在複試時也是當場測驗程式。

期末報告題目

到圖書館挑選三本Java課本,寫下這些書名與作者出版社與出版日期,每本書各挑選一個習題進行個人研究,說明以下

  • 你為什麼挑選這個習題(只有題目,沒有範例或解答),
  • 這個習題讓你學到什麼概念,
  • 請你製作一個講義說明這個習題。


Due: 1/11/2008 at 18:00

星期五, 12月 28, 2007

Lab: Static Method II

Define a Complex class with a static method for computing complex addition. Use (2+3i)+(4+5i) in your test.

星期五, 12月 21, 2007

觀摩學習

這位同學為了鼓勵讀者留言,寫了"你的回應 我的動力"在回應區上,很不錯的點子。

Homework 12/21/2007

Design a method that can compute the vector inner product. You must define Vector class in the first place. Write a demo program to verify your program works. You should use constructors to initialize the two vectors.

Hint: The inner product is not a vector. It is a number (scalar).

Sample answer

Lab Static Method

Study Display 5.2.
Using static variables and static methods to implement the class Fibonacci such that
the first call to Fibonacci.next()
returns 2, the second returns 3, and then 5, and so on.

Lab Java Constructor

Use Display 4.14 to call 4.13 (2nd ed.) or
Display 4.12 to call 4.11 (1st ed.).

After you finish the above, try the following

Date birthday = new Date("Jan",1,2000);
birthday.Date("Feb",1,2000);
birthday.setDate("Feb",1,2000);
birthday=new Date("Mar",1,2000);

星期六, 12月 08, 2007

Quiz on Chap. 4

1. Explain API and ADT.
2. How are the object variables managed by Java compilers? Are they managed in the same way as variables of primitive types?
3. In the following statement,

Date myDate= new Date();

What is the use of "new"?

4. Design a method that can compute the vector inner product. You must define Vector class in the first place. Write a demo program to verify your program works.

5. Define a class called Counter whose objects count things. An object of this class records a count that is a nonnegative integer. Include methods to set the counter to 0, to increase the count by 1, and to decrease the count by 1. Include an accessor method that returns the current count value and a method that outputs the count to the screen. Write a program to test

星期五, 12月 07, 2007

Solution to Faction addition

public class Fraction
{
private int Numer,Denom;

public Fraction ()
{
}

public Fraction (int Numer, int Denom)
{
this.Numer = Numer;
this.Denom = Denom;
}

public void setNumber(int Numer, int Denom)
{
this.Numer = Numer;
this.Denom = Denom;
}

public String toString()
{
return (Numer + " /" + Denom);
}

public static void add(Fraction c1,Fraction c2)
{
Fraction number = new Fraction();

number.Numer= (c1.Numer*c2.Denom) + (c2.Numer*c1.Denom);
number.Denom = c1.Denom * c2.Denom;

return number;
}

public void writeOutput()
{
System.out.println(Numer + " / " + Denom);
}
}

Quiz 3: 12-14-2007

Java 基本知識,問答題 50%, 範圍課本 Chap. 4.1~4.2, Open book
Java 物件導向程式設計,50%, 範圍課本 Chap. 4.1~4.2, Open book

Format: written test, no computers

Homework 12-7-2007

1. Define a Complex class and write an object oriented program to compute (2+3i)+(4+5i) in Java.

2. Show comments on your blog.

Show comments on your blog

以一段程式自動擷取部落格的回應留言,讓你的部落格產生最新回應,沒有時差。

lab Fraction equality test

Write a program to implement a method that can check whether 2 fractions are equal. You will implement a class called Fraction consisting of a numerator and a denominator. The equality test of 2 fractions should return a boolean value.

Use the following as the tests.
  • 1/2, 2/4
  • 5/6, 6/7

Hints:
Fraction f1, f2;
f1.equals(f2);

lab Fraction Addition

Write a program to implement a method that can do additions of 2 fractions. You will implement a class called Fraction consisting of a numerator and a denominator. The additions of
2 fractions should be equal to a fraction.
Use 1/2+1/3 as the test.

Hints:
Fraction f1, f2;
f1.add(f2);