2009年5月25日 星期一

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 static 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 which test the method by CarParked.outOfOrder(yourCar).

Hint: You may study Display 5.14 to get some ideas.







2009年5月12日 星期二

Lab Finding the max of three numbers

Write a static method that computes the maximum of three float numbers.






點此打開==>
From =JAVA=

Lab Static Method

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





點此打開=>









點此打開=>

2009年5月11日 星期一

Lab Math methods

Compute the following mathematical functions.

Math.round(3.2)
Math.round(3.6)
Math.floor(3.2)
Math.floor(3.6)
Math.ceil(3.2)
Math.ceil(3.6)








點此打開=>

Homework 5-4-2009

Do Project 7 of Chapter 4

Write a Temperature class that has two instance variables: a temperature value (a floating-point number) and a character for the scale, either C for Celsius or F for Fahrenheit. The class should have four constructor methods: one for each instance variable (assume zero degress if no value is specified and Celsius if no scale is specified), one with two parameters for the two instance variables, and a no-argument constructor (set to zero degrees Celsius).


degreesC = 5 ( degreesF - 32 ) / 9
degreesF = ( 9 ( degreesC ) / 5 ) + 32








*結果:

=>最後跑完結果似乎有點出錯,C、F轉換的數據錯誤了。不知道哪裡出了問題,還要再仔細看看。

2009年5月5日 星期二

Lab Method Overloading

依據Class definition 3,修改程式使其接受三種setDate

date1.setDate(1,2,2008);
date2.setDate("February",2, 2008);
date3.setDate(2008);










2009年5月4日 星期一

Lab Java Constructor

Write constructors in the lab Fraction Addition.


(Fraction)


(FractionDemo)

    =>將原本的程式改寫用"Fraction f1 = new Fraction (1, 2)"的方式

     還要記得設定初始值!

Homework 4-27-2009

Do project 2 of Chapter 4.



題目:
Define a class called Fraction. This class is used to represent a ratio of two integers. Include mutator functions that allow the user to set the numerator and the denominator. Also include a member function that returns the value of numerator or denominator as a double. Include an additional member function that output the value of the fraction reduced to lowest terms (e.g., instead of outputting 20/60 the method should output 1/3). This will require finding the greatest common divisor for the numerator and denominator, then dividing both by that number. Embed your class in a test program










=> 利用最大公因數相除後,可得到分數之最簡化。大致上的方法都相同,都看幾次後就可顯的較容易上手了。