義守大學 工業工程與管理學系 計算機程式

星期二, 5月 31, 2005

授課投影片

程式設計觀念與流程

-第一章 授課投影片下載

-第二章 授課投影片下載

-第三章 授課投影片下載

-第四章 授課投影片下載 <-- 目前上課進度

-第五章 授課投影片下載

Powerpoint Format (*.ppt)

星期一, 5月 30, 2005

Java 第二次小考-工管 1 A

工管 1 A 小考題目
( 下載 word 檔案 )
第一題 請參考台鐵網路訂票系統
http://railway.hinet.net/

星期四, 5月 26, 2005

第三章習題程式-第六題

第六題:
設計一程式,用迴圈表示輸入 1-7 數字則顯示對應星期 (星期一、星期二......星期天),

若非 1-7 顯示輸入錯誤,直至輸入 0 則程式結束。

----------------------------------------------------------
參考程式
----------------------------------------------------------

import javax.swing.JOptionPane;

class demo2{
public static void main(String args [ ]) {

int input=1;
String a;

JOptionPane.showMessageDialog(null," 輸入整數1-7 判斷星期幾, 輸入0 程式結束. ", " 迴圈判斷程式",JOptionPane.PLAIN_MESSAGE);

while (input != 0) {

a = JOptionPane.showInputDialog(" 請輸入1 -7 之間的整數, 輸入0 程式結束");
input = Integer.parseInt(a);

if(input ==1 ) { JOptionPane.showMessageDialog(null,"判斷結果是星期一", " 迴圈判斷程式",JOptionPane.PLAIN_MESSAGE); }
else if (input ==2 ) { JOptionPane.showMessageDialog(null,"判斷結果是星期二", " 迴圈判斷程式",JOptionPane.PLAIN_MESSAGE); }
else if (input ==3 ) { JOptionPane.showMessageDialog(null,"判斷結果是星期三", " 迴圈判斷程式",JOptionPane.PLAIN_MESSAGE); }
else if (input ==4 ) { JOptionPane.showMessageDialog(null,"判斷結果是星期四", " 迴圈判斷程式",JOptionPane.PLAIN_MESSAGE); }
else if (input ==5 ) { JOptionPane.showMessageDialog(null,"判斷結果是星期五", " 迴圈判斷程式",JOptionPane.PLAIN_MESSAGE); }
else if (input ==6 ) { JOptionPane.showMessageDialog(null,"判斷結果是星期六", " 迴圈判斷程式",JOptionPane.PLAIN_MESSAGE); }
else if (input ==7 ) { JOptionPane.showMessageDialog(null,"判斷結果是星期天", " 迴圈判斷程式",JOptionPane.PLAIN_MESSAGE); }
else if (input !=0) { JOptionPane.showMessageDialog(null,"輸入錯誤", " 迴圈判斷程式",JOptionPane.PLAIN_MESSAGE); }
}

JOptionPane.showMessageDialog(null,"輸入0 程式結束", " 迴圈判斷程式",JOptionPane.PLAIN_MESSAGE);

System.exit(0);

}
}

第三章習題解答

設計一巢狀迴圈列印遞減的星號
如輸入數字 5 則依序列印出 5,4,3,2,1 倒三角形星號圖
*****
****
***
**
*

參考程式碼
---------------------------------------------------------------------

import javax.swing.JOptionPane;

class demo1{
public static void main(String args [ ]) {

int input;
String a;

a = JOptionPane.showInputDialog(" 請輸入 1 - 30 之間的整數");
input = Integer.parseInt(a);

for (int i=input; i>=1; i--) {

for (int j=i; j>=1; j--) {

System.out.print(" * "); //列印 *
} // 內圈 j

System.out.println(" "); //換行列印
} // 外圈 i

System.exit(0);

}
}

星期六, 5月 21, 2005

程式碼

JAVA 程式碼 java.htm

JAVA Applet 程式範例
http://www.myphysicslab.com/index.html
(相關物理現象模擬)

星期一, 5月 09, 2005

多重 if 判斷式練習

設計出一類別Tax,依照個人年收入來計算應繳所得稅.

程式輸入: 個人年收入.
程式輸出: 所得稅率, 應繳所得稅. (應繳所得稅 = 個人年收入 x 所得
稅率 )

1. 個人年收入在30萬以下, 所得稅稅率為5%.
2. 個人年收入在31萬至60萬之間, 所得稅稅率為15%.
3. 個人年收入在61萬至90萬之間, 所得稅稅率為25%.
4. 個人年收入在91萬以上, 所得稅稅率為35%.

運用 JOptionPane 類別中的 輸入方法 showInputDialog 輸入個人年收入.
運用 JOptionPane 類別中的 輸出方法 showMessageDialog 顯示應繳所得稅.