星期六, 12月 29, 2007
星期五, 12月 28, 2007
Lab: Static Method II
星期五, 12月 21, 2007
Homework 12/21/2007
Hint: The inner product is not a vector. It is a number (scalar).
Sample answer
Lab Static Method
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
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
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
{
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
Format: written test, no computers
Homework 12-7-2007
2. Show comments on your blog.
lab Fraction equality test
Use the following as the tests.
- 1/2, 2/4
- 5/6, 6/7
Hints:
Fraction f1, f2;
f1.equals(f2);
lab Fraction Addition
2 fractions should be equal to a fraction.
Use 1/2+1/3 as the test.
Hints:
Fraction f1, f2;
f1.add(f2);
星期五, 11月 30, 2007
Homework 11-30-2007
2. Do Lab Counter.
Lab counter
counter.reset();
counter.inc();
counter.inc();
counter.dec();
counter.output();
Class Definition 3
Question
In Display 4.7, if the method setDate has the parameter as setDate(int month, int day, int year), what kind of changes should be made in its body of codes?
星期五, 11月 16, 2007
Homework 11/16/2007: lab class definition 2
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?
態度決定高度
只有上課時來抄襲旁人的作業,在此只好明說,這門課不是 All-Pass。
上學期有八人因為知道無法及格,於期末退掉這門課,
整學期的努力最後必須退掉並不值得鼓勵。
另外對於不少人非常認真想學好Java,尤其是過去沒有電腦程式基礎的同學,無論前兩次小考結果如何,老師都要給你們鼓勵,欣賞你們用心的態度。
祝大家期中考有好的表現,也隨時照顧好自己。
星期五, 11月 09, 2007
Makeup Work 11/9/2007
For those who didn't pass Quiz II (see the list), you are encouraged to write complete Java programs and run them on your JBuilder. Please present your source codes and the answers that your programs produce.
Your makeup work can be posted to the following comment area, as usual.
Partial Solutions to Quiz II
Problem 1:
double power=1, fact=1, sum=0;
int k=-1;
for(int i=1; i<10; i++)
{
power=power*x;
fact=fact*i;
if(i%2==1)
{ k=k*(-1);
sum+=k*power/fact;
}
}
Problem 2:
int evenSum=oddSum=0;
for(i=1; i<=25; i++)
{
if(i%2==0)
evenSum=evenSum+i;
else
oddSum+=i;
}
Perforamnce Alert (didn't pass either Quiz 1 or Quiz 2)
9326206
9326223
9326246
9326251
9326256
9326268
9326309
9326314
9426113
9426114
9426130
9426224
9426228
9426236
9426332
9426365
9441142
9441210
9442234
Quiz 11/9/2007: Result
9326125 (100/150)
9326227 (100/150)
9426106 (100/150)
9426147 (80/150)
9426202 (120/150)
9426212 (125/150)
9426214 (75/150)
9426352 (150/150)
9426364 (150/150)
No PASS:
9325121
9326206
9326222
9326223
9326246
9326251
9326256
9326268
9326309
9326314
9326315
9426113
9426114
9426130
9426208
9426219
9426224
9426228
9426236
9426324
9426332 (No show)
9426365
9441142
9441210
9442234
9444162
Quiz 11/9/2007
1. (50) Write a Java program to calculate the sin function as follows:
sin(x)=x - 3!/x 3 + 5!/x5 - 7!/x7 ...
2. (30)
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.
3. (70) Write a program to calculate average science scores by gender based on the following data, where F stands for female and M for male.M 82
M 65
F 88
M 63
F 75
F 90
F 90
M 70
You should be able to allow users to type in a whole line such as F 80 followed by next line M 70.
星期五, 10月 26, 2007
Lab Exponential Function
Hint: You don't have to use nested loops.
11-9-2007 Quiz 2
Format: Open book. Pencil & Paper.
Running time: 30 min.
預告: 11/23 期中考週不上課。
Average income by gender
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.
Without any change made to your program, your program should be able to process a new set of data, such as follows:
M 52,000
M 35,000
F 48,000
M 33,000
F 75,000
F 110,000
F 90,000
M 30,100
Lab 9*9
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
Lab Fibonacci numbers
List the first 100 numbers and the ratio of
a number to its previous number, such as 1/1 = 1, 2/1 = 2, 3/2 = 1·5, 5/3 = 1·666..., 8/5 = 1·6, 13/8 = 1·625, 21/13 = 1·61538....
Want to know more about Fibonacci number
星期五, 10月 12, 2007
Homework 10-12-2007: Finding the max and the min
For example, given 1,3,5, and9, the max is 9 and the min is 1.
Your program should be able to process a list of any length.
Lab Finding the max of three numbers
Bonus: Lab for-loop
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.
Quiz 10-12-2007
2. The identifier BufferedReader is normally abbreviated as BR in programming language C. However, Java programmers normally do not use abbreviations for identifiers. What are the advantages and disadvantages of not using abbreviations?
Lab: Tax Calculation
calculate the income tax of a person whose annual income is 1,000,000 or 2,000,000.
星期二, 10月 09, 2007
星期五, 10月 05, 2007
10-5-2007 點名未到
電子三乙 李文森
電子三丙 謝志揚
電子三丙 潘冠宇
電子三甲 鄭安舜
電子四乙 黃璽祐 (有請假單)
電子四乙 林士傑 (有請假單)
電子四甲 曾韋碩
醫工四甲 東峻平
Lab: Keyborad Input
You need to import the following packages in the first place.
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
Change
Scanner keyboard= new Scanner(System.in);
into
BufferedReader keyboard= new BufferedReader(new InputStreamReader(System.in));
String inputString = keyboard.readLine();
Note the Main method needs IOException handling as follows:
public static void main (String[] args) throws IOException
Lab: Adding Links on Your Blog
2. Enter "自訂"
3. Select "連結清單"
4. Write down "http://javaatcycu.blogspot.com/" and the title as "Java物件導向程式設計"
5. Also add your own favorite links.
Programming Styles
Make your code easy to read and easy to modify.
Spelling conventions
- name the variables as the names suggest
- Start the name of classes with uppercase letters (such as String, FirstProgram) and start the names of variables, objects, and methods with lowercase letters.
- Word boundaries are indicated by an uppercase letter, as in numberOfPods
- Java spells things out in full. Use BufferedReader instead of BufReader, BuffReader, BufferedR or BR. With abbreviations, we often cannot recall how the identifier is abbreviated.
- "Just enough" is enough.
- When something is important and not obvious, it merits a comment.
- Example of unnecessary comment
Self-documenting
- the structure of the program is clear from the choice of identifier names and indenting pattern.
- The general rule of indenting is easy. When one structure is nested inside another structure, the inside structure is indented one more level.
- We prefer to use four spaces for each level of indenting. Indenting only two or three spaces is fine so long as you are consistent. One space is not enough to be clearly visible.
Oct-12-2007 Quiz of Chap. 1
Running time: 30 min.
Scope: Chap. 1
星期五, 9月 28, 2007
星期四, 9月 27, 2007
Lab String Processing
Write a program that starts with a line of text and then outputs that line of text with the first occurrence of "hate" changed to "love". For example, a possible sample output might be
The line of text to be changed is:
I hate you.
I have rephrased that line to read:
I love you.
Hint: You may consider use the methods: indexOf(A_String) and substring(Start, End) in your program.
Lab 9-28-2007 Simple Calculation
Hint: There are 5280 feet in a mile.
星期五, 9月 21, 2007
Homework 9/21/2007
"tell me and I'll forget; show me and I may remember; involve me and I'll understand"
1. Explain bytecode, JVM
2. Explain class, object
3. Reading Assignments:
Read 1.1, 1.2, 1.3 of Textbook
4.1 Write a Java program as follows:
Let i=2;
Print i;
Print 2 * (i++);
Print i;
Ans: 2, 4, 3
4.2 Write a Java program as follows:
Let i=2;
Print i;
Print 2 * (++i);
Print i;
Ans: 2, 6, 3
4.3 Write a Java program as follows:
Let m=7, n=2;
Print (double) m/n;
Print m/ (double)n;
Ans: 3.5, 3.5
Lab 2
Do Project 4 on Page 56. (2nd Edition)
Do Project 1 on Page 54. (1st Edition)
artificial sweetener 人工代糖(過量可以致癌)
diet soda pop 減肥可樂
lose weight 減肥
星期一, 9月 17, 2007
星期五, 9月 14, 2007
Homework 9/14/2007
1. Watch The Inside Story (Video), write your words on the development and inventor of Java.
2. List at least 5 applications of Java. You must provide the references you used. We recommend Google Search engine.
ps.
Lab: Using Firefox
Outlines of Lab
1. download Firefox 2.0
2. control font size
3. tabbed browsing
4. subscribe to the course blog
5. Using bookmarks to test RSS feed
Help
Hands on
1. Easy control of font size (try ctrl+ & ctrl- as many times as you like)
2. tabbed browsing (try ctrlT)
3. RSS feed, and support of Blog. Use the RSS feed from http://iapblog.blogspot.com/
to subscribe to it. Also subscribe to your own blog.
Note:
If your Firefox didn't work, you should check settings about proxy. It should be set as proxy.cycu.edu.tw at port 3128.
Lab Blogging
2. 張貼你的部落格的第一篇文章。一小段歡迎詞,或是簡短自我介紹,或是你最喜歡的科目與最不喜歡的科目,都可以。
3. 日後請將你的隨堂練習與作業寫在你的 blog, 然後到
Homework 或 Lab 的Comment 登錄作業blog網址就可以了.
請勿將整個作業直接寫在老師部落格的Comment處。
4. 尊重智慧財產權,引用他人文章須註明出處。並且應該合乎學術常規,以合理的方式引用。
注意事項
a. blog需正確設定時區顯示時間 。
b. 請測試他人可否留言(comment)。以方便留下回應意見。
How to insert a link at the following comment, please use the following HTML code.
星期二, 9月 11, 2007
Syllabus
Syllabus: Object Oriented Programming in Java
Grading Policy: Participation (Presence, Challenging and Answers, Proactiveness, Quiz) 50%, Lab 30%, Homework 20%,
Instructor: Associate Professor Yao-Jen Chang
Email: yjchang at cycu dot edu dot tw (for general purpose communication)
Teaching Assistant:
Textbooks: Walter Savitch, Absolute Java , 3/e, Addison Wesley, 2008由於上課時上機的需要, 上課務必攜帶課本,可新購或使用舊版皆可。僅限使用原版教科書。
1.Introduction to Java
2.Java variables & assignments
3.Java control structures
4.Object oriented design concepts
5. Java abstract data type
6.Java recursion
Learning Packages:
IDE: JBuilder Foundation Edition, Free full version for free download, no registration required http://www.borland.com/products/downloads/download_jbuilder.html
Links:
History of Java
Java Tutorials by Sun
Java History: The Inside Story (Video)
James Gosling (on Wikipedia)
作業繳交方式
星期二, 6月 19, 2007
星期三, 6月 13, 2007
為什麼要學寫程式
電子系同學大多不重視寫程式,想不透是誰給他們寫程式不重要的錯誤概念,事實上寫程式對電子系同學的重要性絕對不亞於資工系,無論是通訊,數位,用 到程式的機會極高。現在的系統講究智慧,智慧從哪裡來? 當然是軟體。以手機為例,手機硬體大同小異,功能差異性主要來自軟體。所謂科技來自人性,軟體居功厥偉。
電子系不等於焊電路接麵包板而已,所以千萬不要輕視寫程式。寫程式的好處如下:
- 以後工作用得上。現在的世界是買硬體送軟體,以後是買軟體送硬體。
- 訓練清晰頭腦,培養邏輯思考能力。
- 快速試做一個概念,因為你在耗時耗費實做之前,即可先用軟體程式模擬。如果結果不錯,再去實做不遲。
星期一, 6月 11, 2007
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.
星期二, 6月 05, 2007
星期一, 6月 04, 2007
Quiz 結果
9427217林明駿
Quiz 未通過
電子三丙 9326329 戴志翰
電子四丙 9226362 黎玉全
電子四丙 9126338 何俊學
電子四丙 9226315 林彥光
電子三乙 9326265 梁躍叡
電子二甲 9426116 藍宇霆
應數碩二 9461006 陳志威
電子四乙 9126240 蔡明翰
電子四丙 9226330 張展魁
電子三乙 9326202 蔡勝勛
電子二乙 9426222 甘碩傑
電子二乙 9426258 李彥勳
電子二甲 9426139 劉宜鈞
電子四甲 9226151 林文翔
電子三甲 9326152 蕭名宏
電子四甲 9226148 張競升
9326138張銘仁
電子二甲 9426102 許志瑋
電子三甲 9326157 張格榮
電子二丙 9426304 徐衍翰
電子二丙 9426361 李習文
電子三甲 9326161 陳健勳
電子三甲 9326143 薛子源
電子四丙 9226332 陳鴻政(凌晨三點才上傳)
Quiz 6-4-2007 II
Quiz 6-4-2007
星期一, 5月 28, 2007
Homework 5-28-2007: Sorting
Lab Static Method II
(2nd ed.) Do Project 7 of Chap 5. Define a Complex class and write a program to compute (2+3i)+(4+5i) in Java.
Note:
Implement a static method and a nonstatic method using overloading. The results of these two methods should be the same.
星期三, 5月 23, 2007
星期一, 5月 21, 2007
Lab Static Method
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
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);
星期五, 5月 18, 2007
5-28-2007 第三次上機測驗
Java 物件導向程式設計,50%, 範圍課本 Chap. 1~Chap. 5, Open book
星期二, 5月 15, 2007
Homework 5-14-2007
星期一, 5月 14, 2007
星期一, 5月 07, 2007
Lab Counter
counter.reset();
counter.inc();
counter.inc();
counter.dec();
counter.output();
Homework 5-7-2007: Overloading in Java
Study Display 4.9 and use Display 4.10 to call 4.9 (1st ed.)
星期一, 4月 30, 2007
Lab Class Definition III
Requirements
1. The method setDate has the parameter as setDate(int month, int day, int year).
What kind of changes should be made in its body of codes?
星期日, 4月 22, 2007
星期一, 4月 16, 2007
Homework 4-16-2007: Class Definitions II
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?
星期一, 4月 09, 2007
Lab Exponential Funtion
Hint: You don't have to use nested loops.
Lab Fibonacci numbers
List the first 100 numbers and the ratio of
a number to its previous number.
Want to know more about Fibonacci number
星期二, 3月 27, 2007
成績分佈: Quiz 3-26-2007
9326161 10
9226332 25
9326143 20
9226362 5
9126240 25
2. 缺考2位
9426140
9126104
3. 成績分佈(應考39位)
80~89 1
70~79 0
60~69 2
50~59 2
40~49 4
30~39 5
20~29 11
10~19 8
0~9 6
星期一, 3月 26, 2007
Homework 3-26-2007: Finding the max and the min
For example, given 1,3,5, and9, the max is 9 and the min is 1.
Your program should be able to process a list of any length.
Lab: Tax Calculation
calculate the income tax of a person whose annual income is 1,000,000 or 2,000,000.
Quiz 3-26-2007
according to Java program styles. Check the following
(1) the naming of constants, if any,
(2) Java spelling conventions, and
(3) indenting.
2. Insert proper comments in your program for Simple Java Expression. Note that there are 2 ways to insert comments: line comments and block comments.
3. The identifier BufferedReader is normally abbreviated as BR in programming language C. However, Java programmers normally do not use abbreviations in identifiers. Can you give some good reasons for using long names in Java?
4. The Java Virtual Machine handles string objects in a way different from the one it handles variables of primitive types such as int, long, float, and double. What is the difference?
星期一, 3月 19, 2007
星期二, 3月 13, 2007
Lab: Scanner
You need to import the following packages in the first place.
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
Change
Scanner keyboard= new Scanner(System.in);
into
BufferedReader keyboard= new BufferedReader(new InputStreamReader(System.in));
String inputString = keyboard.readLine();
Lab: Window input dialog
String myString=JOptionPane.showInputDialog("Enter a number: ");
use the following command to convert a string to a number
int myNumber = Integer.parseInt(myString);
and finally use the following command to print the input number to the console
System.out.println("The number is "+ myNumber);
Don't forget the following import command
import javax.swing.JOptionPane;
so that Java can recognize JOptionPane library.
星期一, 3月 12, 2007
Homework 3-12-2007
2. Do Project 5 of Chap. 1
"tell me and I'll forget; show me and I may remember; involve me and I'll understand"
Memo:
- Lab 超過下課24小時未交, 不予記分.
- 未交 Lab, 不僅該 Lab 不記分, 且扣平時成績.
- Homework 超過繳交時間(下次上課前) , 不予記分
- Lab 與 Homework 的重要性參看課程大綱
3-12-2007 點名未到
9126104
9226147
9326114
9326161
9326265
9326305
9426140
late
9326143
9326138
9426116
9426126
9426127
務必帶課本上課
使用原版之教科書
由於(台灣國際圖書業交流協會書函), 叮嚀必須使用使用原版之教科書作為上課及教學之用, 所以本課程使用原版之教科書作為上課及教學, 任何課本影印本, 一律不准攜入教室.
Lab: Simple Java Expression
Do Project 1 on Page 54. (1st Edition)
星期一, 3月 05, 2007
Homework 3/5/2007
Homework Problems due 3/12 18:50
1. Explain bytecode, JVM
2. Explain class, object
3. Reading Assignments:
Read 1.1, 1.2, 1.3 of Textbook
4.1 Write a Java program as follows:
Let i=2;
Print i;
Print 2 * (i++);
Print i;
Ans: 2, 4, 3
4.2 Write a Java program as follows:
Let i=2;
Print i;
Print 2 * (++i);
Print i;
Ans: 2, 6, 3
4.3 Write a Java program as follows:
Let m=7, n=2;
Print (double) m/n;
Print m/ (double)n;
Ans: 3.5, 3.5
星期一, 2月 26, 2007
加選成功同學(依照抽籤順序)
9426318 886
9226362 875
9226225 775
9126240 664
9226131 664
9326132 653
9427217 653
9326245 542
9461006 437
Lab Blogging
2. 張貼你的部落格的第一篇文章。一小段歡迎詞,或是簡短自我介紹,或是你最喜歡的科目與最不喜歡的科目,都可以。
3. 日後請將你的隨堂練習與作業寫在你的 blog, 然後到
Homework 或 Lab 的Comment 登錄作業blog網址就可以了.
請勿將整個作業直接寫在老師部落格的Comment處。
Preparing for the class
Watching videos about James Gosling and the persons who worked with him is very inspiring and encouraging to me. Before I found those videos on the Internet, I read some stories about how Java was created. The stories were great but the videos were even better. Both the stories and the videos fuel the passions into me, the kind of passion I need after teaching Java in 6 consecutive semesters.
Tonight, I watched Carl Sagan's TV series Cosmos followed by the Hollywood movie "Contact," which was based on Carl's novel. I felt more passions before the day ended.
星期日, 2月 25, 2007
Useful Readings
Java Tutorials by Sun
Java History: The Inside Story (Video)
James Gosling (on Wikipedia)
星期三, 1月 24, 2007
星期五, 1月 19, 2007
Web 2.0 無線行動系統與程式設計成長冬令營
時間: 2007年1月30日,1月31日
地點: 中原大學社區服務中心芳鄰成長園(位置 )
主辦: 電子系網路實驗室 (連絡電話: 4630,報名網址 http://mobilesocialtech.blogspot.com)
費用: 免 (只接受1/26以前之網路報名)
詳細課程
星期一, 1月 08, 2007
Lab Hanoi Tower
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.
Lab Squared Array
The sqaures are computed in a separate method rather than in the main method.
星期五, 十月 26, 2007 1:10:00 下午
9326268 李致學
星期五, 十月 26, 2007 2:07:00 下午
電子三乙9426236林庭輝
星期五, 十月 26, 2007 2:08:00 下午