程式語言 (Principles of Programming Languages) 2010
教師: 江振瑞 (jrjiang_a_t_csie.ncu.edu.tw)
助教: 黃捷群 洪兆緯 林子浩 黃達育
繳交作業:Blackborad System: http://bb.ncu.edu.tw (程式語言A)
上課時間:Tuesday 15:00~17:50
上課地點:E6-A204
教科書下載:
軟體下載:
相關聯結:
授課大綱:
In this course, we will teach the
following materials:
- Java Language Fundamentals
- Java Networking Programming
- Java 3D Programming
- International Collegiate Programming
Contest
- Wonderland Programming (for 3D Virtual
Worlds)
- Google App Engine (for Cloud Computing)
2/23: Preclass Test and Course
Introduction
3/2:
3/9:
3/16:
- My book's chapters 6, 7 and 2 (Java06.ppt)
(Java07.ppt) (Java02.ppt)
- Homework 4: Write the following Java Applet:
Use JOptionPane.showInputDialog method to input an interger n less than 2147483648
and use JOptionPane.showMessageDialog method to show the largest prime no
larger than n. You must use the "continue"
statement with label; otherwise, the program is considered no good. Due:
before next TA's calss.
- Homework 5: Write the following Java
Applet:
Use JOptionPane.showInputDialog method
to input two intergers n and m, both less than 2147483648, calculate their
greatest common divisor (gcd) by the Euclidean algorithm, and use JOptionPane.showMessageDialog
method to show the gcd. Due: before next TA's class.
3/23:
- My book's chapter 8: Multimedia (pdf)(ppt)
- Homework 6: Write a Java applet to embed
an animation of a Web page showing arbitrary geometric shapes, such as circles,
lines, diamonds, triangles, squares, pentagons, and hexagons, with random
colors. (Due: before next TA's class)
- My book's chapter 9: GUIs (pdf) (ppt)
- My book's chapter 10: Events (pdf) (ppt)
- Homework 7: Write a Java Applet, a Frame
or a JFrame to simulate a calculator. (Due: before next TA's class)
3/30:
4/06:
- The first examination (Scope:
All materials in my book)
4
/13: (How to create network connections)
4/20: (How to create a web server)
舉例如下:
telnet www.csie.ncu.edu.tw 80
GET /~jrjiang/ HTTP/1.1
Host: www.csie.ncu.edu.tw (備註: http1.1一定要加Host header field,而http1.0不一定要加)
HTTP/1.1
200 OK
Date: Mon, 19 Apr 2010 23:52:59 GMT
Last-Modified: Thu, 10 Sep 2009 20:16:05
GMT
Accept-Ranges: bytes
Content-Length: 2086
Content-Type: text/html
- (Bonus) Homework 9b: 利用Java語 言,寫一個網路爬蟲(crawler)程
式,可以由某個網頁開始,將網頁下載後隨機拜訪網頁中的一個html超連結網頁,並印出該網頁網址,重複上述動作直到碰到無超連結的網頁或碰到重複的網頁 或已瀏覽超過某個數目(如10)的網頁為止。
REF:(GetPage.java) (Due: 4/26)
4/27: (How to send/receive mails)
5/4: Introduction to Python
- Tutorial
in Chinese (link)
- Tutorial download (pdf)
- Python Introduction (ppt)
- Homework 11:
Write a Python program to input an arbitrary number of strings by the raw_input("Please
enter a string (press enter to stop): ") function and a while statement.
The program should prints out the last string according to the dictionary
order by calling the max() function. For example, if you input "A," "zebra,"
"is," "over," "there," then the program will output "zebra."
Sample Code:
a=[]
s=raw_input("Please enter a string
(press enter to stop): ")
while s!="":
a.append(s)
s=raw_input("Please enter a string
(press enter to stop): ")
print "The last string according to
the dictionary order is", max(a)
5/11: ICPC-like Test (20%)
5/18:
- The flow control of Python (ppt)
- 30-min Quiz:
以Python語言定義一個函數sum (start, stop,
step, minus)使得
sum()會傳回0, 1, 2,…, 99之和
sum(step=2)會傳回0~99之偶數總和
sum(start=1, step=2)會傳回0~99之奇數總和
sum(step=2, minus=5)會傳回0~99中非5倍數之偶數總和
sum(start=100, stop=997, step=3,
minus=7)會傳回100, 103, 106,…,997中非7倍數之總和
sum(start=100, stop=997, step=3,
minus=0)會傳回100, 103, 106,…,997之總和
Sample Code:
def sum(start=0, stop=99, step=1, minus=0):
acc=0
for i in range(start, stop+1, step):
if minus==0 or i%minus!=0: acc+=i
return acc
5/18: ICPC-like Contest
5/25:
- Data Structures of Python (ppt)
- 30-min
Quiz: (Question Dowload)
- Sample Code 0A
for basic ID checking : (By 975002019_王建堯)
def checkID():
ID = raw_input().upper()
s = {'A': 10, 'C': 12, 'B': 11, 'E': 14, 'D': 13, 'G': 16, 'F': 15,
'I': 34,
'H': 17, 'K': 19, 'J': 18, 'M': 21, 'L': 20, 'O': 35, 'N': 22,
'Q': 24,
'P': 23, 'S': 26, 'R': 25, 'U': 28, 'T': 27, 'V': 29, 'Y': 31,
'X': 30,}
checksum = int(ID[9]) + s[ID[0]]%10*9 + s[ID[0]]/10
for i in range(1,9): checksum += (9-i)*int(ID[i])
return checksum%10 == 0
- Sample
Code 0B for advanced ID checking: (By 975002019_王建堯)
def checkID( ID = None ):
'''"checkID( String ID )" or "checkID(),
ID = raw_input()"'''
#input ID
if type(ID) is not str:
ID = raw_input()
#check length
if( len(ID) != 10 ): return False
#build map
s = {'A': 10, 'C': 12, 'B': 11,
'E': 14, 'D': 13, 'G': 16,
'F': 15, 'I': 34, 'H': 17,
'K': 19, 'J': 18, 'M': 21,
'L': 20, 'O': 35, 'N': 22,
'Q': 24, 'P': 23, 'S': 26,
'R': 25, 'U': 28, 'T': 27,
'V': 29, 'Y': 31, 'X': 30,
'1': 1, '2': 2, '3': 3, '4':
4, '5': 5,
'6': 6, '7': 7, '8': 8, '9':
9, '0': 0 }
#check range
if ID[0] not in s.keys() or s[ID[0]]
not in range(10,36): return False
for i in range(1,10):
if ID[i] not in s.keys() or
s[ID[i]] not in range(0,10): return False
#count checksum
checksum = s[ID[9]] + s[ID[0]]%10*9
+ s[ID[0]]/10
for i in range(1,9): checksum +=
(9-i)*s[ID[i]]
#return result
if checksum%10: return False
else: return True
- Sample
Code 1 : (By 莊豐誌975002203)
def check():
def add(x,y):return x+y
a=[]
tran={'A':10,'B':11,'C':12,'D':13,'E':14,'F':15,'G':16,'H':17
,'J':18,'K':19,'L':20,'M':21,'N':22,'P':23,'Q':24,'R':25
,'S':26,'T':27,'U':28,'V':29,'X':30,'Y':31,'I':34,'O':35}
idnum=raw_input()
idnum=idnum.upper() #轉大寫
b=int(tran[idnum[0]]) #先找出字母對應的數字,然後拆開並計算
a.append(b/10)
a.append(b%10*9)
for n in range(1,9): #處理中間8碼
a.append(int(idnum[n])*(9-n))
a.append(int(idnum[9])) #處理檢查碼
return reduce(add,a,0)%10==0
- Sample
Code 2 (By 邱昱翔975002009):
def judge(str1):
str1.lower()
temp = map(ord,str1)
if 65<=temp[0]<=72:
temp[0]=temp[0]-55
elif 74<=temp[0]<=78:
temp[0]=temp[0]-56
elif 80<=temp[0]<=86:
temp[0]=temp[0]-57
elif 88<=temp[0]<=89:
temp[0]=temp[0]-58
elif temp[0]==73:
temp[0]=34
elif temp[0]==79:
temp[0]=35
for counter in range(1,10):
temp[counter]=temp[counter]-48
temp.insert(0,temp[0]/10)
temp[1]=temp[1]%10
num = range(1,10)
num.insert(0,1)
num.reverse()
num.insert(0,1)
for i in range(0,11):
temp[i]=temp[i]*num[i]
def add(x,y): return x+y
temp=reduce(add, temp)
if temp%10 == 0 : print "Correct!!"
else: print "Wrong!!"
- Samploe
Code 3 (By 陳厚凱975002011)
idnum = raw_input()
ida = []
i = 0
while i<=9:
ida.append(idnum[i])
i = i+1
def translate(x):
if x == 'A':return 10
if x == 'B':return 11
if x == 'C':return 12
if x == 'D':return 13
if x == 'E':return 14
if x == 'F':return 15
if x == 'G':return 16
if x == 'H':return 17
if x == 'J':return 18
if x == 'K':return 19
if x == 'L':return 20
if x == 'M':return 21
if x == 'N':return 22
if x == 'P':return 23
if x == 'Q':return 24
if x == 'R':return 25
if x == 'S':return 26
if x == 'T':return 27
if x == 'U':return 28
if x == 'V':return 29
if x == 'X':return 30
if x == 'Y':return 31
if x == 'I':return 34
if x == 'O':return 35
if x == '0':return 0
if x == '1':return 1
if x == '2':return 2
if x == '3':return 3
if x == '4':return 4
if x == '5':return 5
if x == '6':return 6
if x == '7':return 7
if x == '8':return 8
if x == '9':return 9
idi = map(translate,ida)
counter = 1
counter2 = 8
while counter <= 8:
idi[counter] = idi[counter]*counter2
counter = counter+1
counter2 = counter2-1
check = (idi[0]/10)+(idi[0]%10*9)
i = 1
while i<=9:
check = check + idi[i]
i = i+1
if check%10==0:
print 'Correct!'
else:
print 'Wrong!'
6/1:
- Modules, Classes, Errors, and Exceptions
in Python (ppt)
6/8: Google App Engine (GAE) with Python
- Introduction (doc) (Adpated from Google
Code: http://code.google.com/)
- Steps to Build Google App Engine Applications Using Python and Django
(doc) (ppt)
- Homework:
1.申請使用Google App Engine,建立一個新的網站,應用程式名稱ID就是每個網站的域名,依照 ncu+學號+python 設定應用程式。
2.建置使用Django的GAE專案,使用者輸入一個數值n,可以傳回小於n但是大於等於2的質數總和,並且將結果顯示於網頁中。
6/15: Google App Engine (GAE) BigTable and
Python
- Introduction (doc)(files)(ExplanationOfFiles)
- Howework
1.建置使用Django的GAE專案,讓使用者輸入一個數值n,將每次使用者輸入的數值n、輸入者、輸入時間儲存於GAE之資料庫中,並且將資料顯示於畫面中(每次顯示十筆)
6/15: Wonderland Introduction
6/22: Final Exam. (Open book; 2 hours)
教科書及參考書:
- 中文Java程
式設計, 江振瑞 著, 儒林出版社
- 物件導向資料結構
— 使用Java語言, 江振瑞 著, 松崗圖書公司
- 網路應用程式開發 — 使用Google App Engine, 李威和 編著
- Y. Daniel Liang, "Introduction to Java Programming," 7th Edition, Pearson
Education International, 2009.
- H. Zhang and Y. Dniel Liang, "Computer Graphcis using Java 2D and 3D,"
Pearson Education International, 2007.
- Deitel and Deitel, "Java How to Program," 7/e, Pearson Education, 2008.
- Robert W. Sebesta, "Concepts of Programming Languages," 7/e, Pearson
Education International, 2005.
- Steven S. Skiena and Miguel Revilla, "Programming Challenges," Elsevier,
2003.
- Java2程式設計入門與應用, 吳權威、王曉慧 編著, 網奕資訊 出版
- 精彩Java2程式設計, 吳逸賢、吳目誠 編著, 網奕資訊 出版
- 精彩JavaScript程式設計, 吳逸賢、王曉慧 編著, 網奕資訊 出版
- Java網際網路程式設計, 黃嘉輝 著, 文魁出版社
- JSP動態網頁入門實務, 位元文化 編著, 文魁出版社
- Java網路程式設計, 顏春煌 編著, 旗標出版社
評分方式:
- First Exam: 20%
- Second Exam (ICPC-like Test): 20%
- Third Exam: 20%
- In-Class, Homeworks and Projects: 40%
相關鏈結: