2008年1月4日 星期五

Lab Magic Parking Tower

A parking tower is out of order someday. If you park a Benz, you will end up with a Torben. Write a program to simulate this scenario. First create a class called CarParked which has a method called outOfOrder. Name an object called yourCar, which happens to be a Benz. Your program should contain a class called CarParked and a test program called CarParkedDemo.

1.

















(附) toString 用為將最後的輸出型態轉為 String。
故,brand 已為 String 型態,所以再用 toString 做轉換輸出,不好。

2.

















(改進版)
1.

















2.

2007年12月28日 星期五

Lab: Static Method II

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

Main.















Complex Class.















Math Class and addition static method.

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.

示意圖:

variable number1, number2 are static.(記憶體位置固定)
variable Ans are not static.(記憶體位置非固定)


















class

















main