2009年6月16日 星期二
JAVA!! 我有話要說
這學期,
突破性的選擇了有關程式語言的一門課-JAVA
對於上學期才轉進電子系的我而言,
這是個全新的陌生領域!
完全沒接觸過這方面的資訊,可以說是一竅不通
真的好擔心會學不好...
一開始
看著JAVA卻什麼也不懂
內容看似就是那樣簡單的英文單字拼拼湊湊
卻始終不太能了解那些指令的功能
起初
面對一個題目總是要想很久或根本不知該從何著手寫起
而作業、上機都要翻課本或參考別人的寫法才能約略完成
那時真的覺得寫程式是一件好累又無趣的事情
但 經過每堂課每堂課 老師認真清晰的講解
而同時自己又去多買了一本JAVA的書來看看
題目一次又一次的慢慢練習
漸漸的對JAVA越來越有感覺了
雖然現在面對題目時還是無法很快的有構想
但越來越發覺原來寫程式也是件有趣的事呢!!
好多好多運算都可以用JAVA輕輕鬆鬆的做出來
而學寫程式的優點多多
就像老師曾說的,不僅在未來很有用途,
更可以訓練腦力及細心度!!
就像剛開始時我常因為程式裡多一個";"或是少一個而導致程式錯誤
久而久之慢慢的想成了仔細的檢查
沒想到學個JAVA還真是好處多多耶!!
感謝老師的認真教學,帶給我滿滿的知識
感謝老師~讓我慢慢的喜歡上JAVA的一切!!
2009年6月15日 星期一
Lab Hanoi Tower
The pseudocode for Hanoi Tower is as follows:
solve(N, Src, Aux, Dst)
if N is 0 return
solve(N-1, Src, Dst, Aux)
Move N from Src to Dst
solve(N-1, Aux, Src, Dst)
Write the Java program based on the pseudocode in the above.
solve(N, Src, Aux, Dst)
if N is 0 return
solve(N-1, Src, Dst, Aux)
Move N from Src to Dst
solve(N-1, Aux, Src, Dst)
Write the Java program based on the pseudocode in the above.
From =JAVA= |
Lab Factorial
Write a Java program that computes N! where N is a positive integer.
Hint:
public static long factorial(int n)
Hint:
public static long factorial(int n)
From =JAVA= |
Lab Recursive method
Write a recursive method to compute Fibonacci series.
Hint:
1.
fib(n)=fib(n-1)+fib(n-2)
2.
public static long fib(int n)
Hint:
1.
fib(n)=fib(n-1)+fib(n-2)
2.
public static long fib(int n)
From =JAVA= |
2009年6月8日 星期一
Homework 6-1-2009 Modular Sorting
Write a sort method which takes a double array as parameter
and returns the sorted array. Call this method in a main program.
Hint: The lab is a rewriting of Lab Sorting
to make the sorting procedure a reusable method.
and returns the sorted array. Call this method in a main program.
Hint: The lab is a rewriting of Lab Sorting
to make the sorting procedure a reusable method.
2009年6月2日 星期二
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.
Hint: You may study Display 5.14 to get some ideas.
2009年5月12日 星期二
Lab Static Method
2009年5月11日 星期一
Lab Math methods
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轉換的數據錯誤了。不知道哪裡出了問題,還要再仔細看看。
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);
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)
(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
題目:
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
=> 利用最大公因數相除後,可得到分數之最簡化。大致上的方法都相同,都看幾次後就可顯的較容易上手了。
2009年4月27日 星期一
Class definition 3
Lab ADT
Homework 4-13-2009 Fraction Multiplication
Write a program to implement a method that can multiply 2 fractions. You will implement a class called Fraction consisting of a numerator and a denominator. The multiplication of2 fractions should be equal to a fraction.
Use 1/2 * 1/3 as the test.
Hints:
Fraction f1, f2;
f1.multiply(f2);
Use 1/2 * 1/3 as the test.
Hints:
Fraction f1, f2;
f1.multiply(f2);
2009年3月31日 星期二
lab class definition 2
Study Display 4.4 (2nd ed. and 3rd ed.) or Display 4.2 & Display 4.3 (1st ed.) and then
1. Comment out date.setDate(6, 17, year); by // date.setDate(6, 17, year);
2. At the next line below, add date.readInput();
3. Run the program again. Fix any problems you may encouter along the way.
4. At the last line of your program, add System.out.println(date.month);
and see what happens. Why?
*month被定義為只有自己可以呼叫自己,所以再另一個程式裡無法呼叫
1. Comment out date.setDate(6, 17, year); by // date.setDate(6, 17, year);
2. At the next line below, add date.readInput();
3. Run the program again. Fix any problems you may encouter along the way.
4. At the last line of your program, add System.out.println(date.month);
and see what happens. Why?
*month被定義為只有自己可以呼叫自己,所以再另一個程式裡無法呼叫
Homework 3-30-2009: counter
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
counter.reset();
counter.inc();
counter.inc();
counter.dec();
counter.output();
counter.reset();
counter.inc();
counter.inc();
counter.dec();
counter.output();
2009年3月30日 星期一
Homework: 3/23/2009
Write a program to calculate average income by gender based on the following data, where F stands for female and M for male.
F 62,000
M 25,000
F 38,000
F 43,000
M 65,000
M 120,000
F 80,000
M 30,100
You should be able to allow users to type in a whole line such as F 80,000 followed by next line M 30,100.
F 62,000
M 25,000
F 38,000
F 43,000
M 65,000
M 120,000
F 80,000
M 30,100
You should be able to allow users to type in a whole line such as F 80,000 followed by next line M 30,100.
2009年3月23日 星期一
Lab Cosine
Write a Java program to calculate the triangular function as follows:
Cos(x)=1 - x 2 /2!+ x 4/4!- x 6/ 6!...
Cos(x)=1 - x 2 /2!+ x 4/4!- x 6/ 6!...
Lab Fibonacci
Write a program to generate the series 1, 1, 2, 3, 5, 8, 13, ...
The series has a property that the third number is the sum of the first and second numbers. For example, 2=1+1, 3=1+2, and 5=2+3.
The series has a property that the third number is the sum of the first and second numbers. For example, 2=1+1, 3=1+2, and 5=2+3.
*結論:差距越來越小逐漸趨近於0
2009年3月18日 星期三
Homework 3-16-2009
1. Project 7 of Chap. 3
2. Write a program to generate the following table of arithmetic expressions
1*1=1 1*2=2 1*3=3 ... 1*9=9
2*1=2 2*2=4 2*3=6 ... 2*9=19
...
9*1=9 9*2=18 9*3=27 ... 9*9=81
n=1
n=10
n=50
n=100
2. Write a program to generate the following table of arithmetic expressions
1*1=1 1*2=2 1*3=3 ... 1*9=9
2*1=2 2*2=4 2*3=6 ... 2*9=19
...
9*1=9 9*2=18 9*3=27 ... 9*9=81
訂閱:
文章 (Atom)