關於我自己

我的相片
Welcome to discuss about : Chinese Traditional Medicine and Acupuncture Please send me the email: tccnchsu@gmail.com Chih-Yu Hsu

最新消息

總網頁瀏覽量

2010年2月25日 星期四

Java

Java2011

C程式語言2010


佛-零晨04:30

2010 International Conference on Advanced Information Technologies

2010/04/23-24 Conference period

Eclipse IDE for Java Developers (92 MB)

丙級術科

物件實作與類別繼承與覆寫(over write)

public class Test {



/**

* @param args

*/

public static void main(String[] args) {

// TODO 自動產生方法 Stub

Myprint1 myprint=new Myprint1();

myprint.mytest();

}



}

class Myprint

{

Myprint()

{



}

void mytest()

{

System.out.println("Hello");

}

}

class Myprint1 extends Myprint

{





}


Java 的 類別壓縮檔 src.zip





【試題編號】11900-940305


【題目】矩陣相加

【說明】請利用『指定』迴圈控制指令,由外部資料檔讀入兩組2 乘2 矩陣數值後,將

此兩矩陣數值相加後,列印出此矩陣。

【輸入資料檔案及資料格式】940305.SM, 940305.T01, 940305.T02, 940305.T03

1. 檔案型態:循序檔。

2. 檔案資料欄位如下:(各欄位間以逗號分隔)

欄位 1 欄位2

第一筆記錄A(1,1) A(1,2)

第二筆記錄 A(2,1) A(2,2)

第三筆記錄 B(1,1) B(1,2)

第四筆記錄 B(2,1) B(2,2)

欄位 1 A(1,1) , A(2,1), B(1,1), B(2,1) 整數型態

欄位2 A(1,2) , A(2,2), B(1,2), B(2,2) 整數型態

【範例檔案】940305.SM

第一筆記錄 1, 2

第二筆記錄3, 4

第三筆記錄5, 6

第四筆記錄7, 8

【報表輸出】

第五題結果:

[6 8]

[10 12]




public class MytestMatrix {

/**
* @param args
*/
public static void main(String[] args) {
// TODO 自動產生方法 Stub
int[][] a =new int[2][2];
int[][] b =new int[2][2];
int[][] c =new int[2][2];
a[0][0]=1;
a[0][1]=2;
a[1][0]=3;
a[1][1]=4;
b[0][0]=5;
b[0][1]=6;
b[1][0]=7;
b[1][1]=8;
c[0][0]=a[0][0]+b[0][0];
c[1][0]=a[1][0]+b[1][0];
c[0][1]=a[0][1]+b[0][1];
c[1][1]=a[1][1]+b[1][1];
System.out.println("["+c[0][0]+" "+c[0][1]+"]");
System.out.println("["+c[1][0]+" "+c[1][1]+"]");


}

}







第十四週 2010/05/28

11900-940304 BMI 值計 算

【試題編號】11900-940304
【題目】體質指數BMI
【說明】體質指數 BMI(Body Mass Index)是常用在評估人體肥胖程度的一種指標,其
計算公式為體重除以身高的平方:
BMI = 體重(公斤)/(身高× 身高)(公尺2)
一般而言,正常的體重其BMI 範圍=20~25。請設計一個程式,輸入3 組身高與體重後,
將BMI 值最小者印出並判斷是否在正常範圍內(BMI 之計算身高以公尺,體重以公斤計
算,計算至個位數,小數點後第一位數以四捨五入計算)。
【輸入資料檔案及資料格式】940304.SM, 940304.T01, 940304.T02, 940304.T03
1. 檔案型態:循序檔。
2. 檔案資料欄位如下:(各欄位間以逗號分隔)
欄位 1 欄位2
第一筆記錄身高(公分) 體重(公斤)
第二筆記錄身高(公分) 體重(公斤)
第三筆記錄身高(公分) 體重(公斤)
欄位1 身高(公分) 整數型態
欄位 2 體重(公斤) 整數型態


【範例檔案】 940304.SM
第一筆記錄 176, 45
第二筆記錄 165, 50
第三筆記錄 170, 55
【報表輸出】
第四題結果:最小 BMI 值=15,不正常





import java.io.*;
import java.util.*;


public class Myjava1 {


/**
* @param args
*/
public static void main(String[] args) {
// TODO 自動產生方法 Stub
String inputs="";


try{
FileReader myinpufile=new FileReader("940304.SM");
BufferedReader isr=new BufferedReader(myinpufile);

//System.out.println(isr.readLine());
FileWriter myoutfile=new FileWriter("940304w.SM");
BufferedWriter isrw=new BufferedWriter(myoutfile);

for (int i=1;i<=3;i++)

{
 inputs=isr.readLine();
isrw.write(inputs);
System.out.println(inputs);
StringTokenizer mytoken=new StringTokenizer(inputs,",");
System.out.println(mytoken.nextToken());
System.out.println(mytoken.nextToken());
}
 isrw.flush();
myoutfile.close(); }
catch(Exception e)
{ }
 }
 public static boolean judg(String inputs)
{
int sl=inputs.length();
boolean myresult=true;
String outputs="";
System.out.println(sl);
//System.out.println(inputs.charAt(4));
 for (int i=sl-1;i>=0;i--)
{
System.out.println(inputs.charAt(i));
outputs=outputs+inputs.charAt(i);
}
System.out.println(outputs.equals(inputs));
if(outputs.equals(inputs))
myresult=true;
else
myresult=false;

return myresult;

}

}




電腦軟體設計丙級技術士技能檢定術科測試

第一站試題 BASIC 語言基本指令操作
11900-940301 迴文 判 斷
11900-940302






import java.io.*;


public class Myjava1 {


/**
* @param args
*/
public static void main(String[] args) {
// TODO 自動產生方法 Stub
String inputs="";


try{
FileReader myinpufile=new FileReader("940301.SM");
BufferedReader isr=new BufferedReader(myinpufile);
inputs=isr.readLine();
//System.out.println(isr.readLine());
FileWriter myoutfile=new FileWriter("940301w.SM");
BufferedWriter isrw=new BufferedWriter(myoutfile);
if(judg(inputs))
{
isrw.write("is a palindrome");
System.out.println("is a palindrome");
}
else
{
isrw.write("is not a palindrome");
System.out.println("is not a palindrome");
}
isrw.flush();
myoutfile.close();
}
catch(Exception e)
{

}



}

public static boolean judg(String inputs)
{
int sl=inputs.length();
boolean myresult=true;

String outputs="";
System.out.println(sl);
//System.out.println(inputs.charAt(4));
for (int i=sl-1;i>=0;i--)
{
System.out.println(inputs.charAt(i));
outputs=outputs+inputs.charAt(i);
}
System.out.println(outputs.equals(inputs));
if(outputs.equals(inputs))
myresult=true;
else
myresult=false;

return myresult;

}

}







第十三週 2010/05/21

【試題編號】11900-940301
【題目】迴文判斷
【說明】請利用『指定』迴圈控制指令,由外部資料檔讀入一個欲判斷的數字,若此數
字為迴文(Palindrome,左右讀起均同,例如12321),則印出此數字及“is a
palindrome.",若不是則印出此數字及“is not a palindrome."
【輸入資料檔案及資料格式】940301.SM, 940301.T01, 940301.T02, 940301.T03
1. 檔案型態:循序檔。
2. 檔案資料欄位如下:(各欄位間以逗號分隔)
欄位 1
第一筆記錄數字
欄位 1 數字長整數型別 (3~9 位數的正整數)
【範例檔案】940301.SM
第一筆記錄 12321
【報表輸出】
第一題結果: 12321 is a palindrome.

JAVA 迴文

eclipse download

Palindromes on visual basic 5.0

電腦軟體設計丙級技術士 術科 矩陣相加

電腦軟體設計技術士 電子書

098 年度11900 電腦軟體設計丙級技術士技能檢定學科測試試題本試卷有
第十二週 2010/05/14

電腦軟體設計乙級技術士技能檢定
第十一週 2010/05/07





import java.io.*;
import java.lang.Byte;
import java.util.StringTokenizer;
class TestFile
{
public static void main(String args[])
{
String InFileName;
String OutFileName;
String strLine;
//Byte b=new Byte("34");
try
{
InFileName=args[0];
System.out.println(InFileName);

FileReader rdFile = new FileReader(InFileName);

BufferedReader brdFile = new BufferedReader(rdFile);


strLine = brdFile.readLine();
System.out.println(strLine);
strLine = brdFile.readLine();
System.out.println(strLine);



StringTokenizer tokens = new StringTokenizer( InFileName, ".");
OutFileName=tokens.nextToken()+ ".w" + tokens.nextToken();
System.out.println(OutFileName);
File myfile=new File(OutFileName);
//myfile.createNewFile();
FileWriter fos= new FileWriter(OutFileName);
BufferedWriter bfos=new BufferedWriter(fos);
bfos.write("1");
bfos.flush();
bfos.close();
}
catch (Exception e)
{
System.out.println("exception");

}

}
}


========================================













































































第十週 2010/04/30
作業: 輸入 arg[0]和arg[1] 相加的結果寫入檔案





import java.io.*;
import java.lang.Byte;
class TestFile
{
public static void main(String agrs[])
{
//Byte b=new Byte("34");
try
{
File myfile=new File("mytext.txt");
myfile.createNewFile();
FileOutputStream fos= new FileOutputStream(myfile);
PrintStream ps=new PrintStream(fos);
ps.print("1");

}
catch (Exception e)
{
System.out.println("exception");

}

}
}























期中考



1. 執行 class TriangleMethod (TriangleMethod.java)

2. 修改後以 args[0] 和 args[1]  輸入邊長後結果如下:








import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class TriangleMethod extends JFrame
implements ActionListener {

private JButton button;
private JPanel panel;

public static void main(String[] args) {
TriangleMethod frame = new TriangleMethod();
frame.setSize(350, 300);
frame.createGUI();
frame.setVisible(true);
}

private void createGUI() {
setDefaultCloseOperation(EXIT_ON_CLOSE);
Container window = getContentPane();
window.setLayout(new FlowLayout() );

panel = new JPanel();
panel.setPreferredSize(new Dimension(300, 200));
panel.setBackground(Color.white);
window.add(panel);

button = new JButton("Press me");
window.add(button);
button.addActionListener(this);
}

public void actionPerformed(ActionEvent event) {
Graphics paper = panel.getGraphics();
drawLogo(paper, 10, 20);
drawLogo(paper, 100, 100);
drawTriangle(paper, 100, 10, 40, 40);
drawTriangle(paper, 10, 100, 20, 60);
}

private void drawLogo(Graphics drawingArea,
int xPos, int yPos) {
drawingArea.drawRect(xPos, yPos, 60, 60);
drawingArea.drawRect(xPos, yPos, 40, 40);
drawingArea.drawRect(xPos, yPos, 20, 20);
}

private void drawTriangle(Graphics drawingArea,
int xPlace,
int yPlace,
int width,
int height) {
drawingArea.drawLine(xPlace, yPlace,
xPlace, yPlace + height);
drawingArea.drawLine(xPlace, yPlace + height,
xPlace + width, yPlace + height);
drawingArea.drawLine(xPlace, yPlace,
xPlace + width, yPlace + height);
}
}





演算法筆記

遞迴( recursion)

Introduction to Computer Science - Java Recursion

merge sort java

第七週 2010/04/09



class Mytestjava (Mytestjava.java)






class Myjava

{

public static void main(String[] args)
{
int w,u;
String s1,s2;
int a,b;
a=3;
b=4;

Addop jerry=new Addop();


u=jerry.add(a,b);
s1=args[0];
s2=args[1];
w=jerry.add(s1,s2);
System.out.println(s1);
System.out.println(s2);
System.out.println(u);
System.out.println(w);
}



}


class Addop
{

Addop()
{

System.out.println("hsu chih-yu");
}


static int add(String s1,String s2)
{
int x,y,z;
x=Integer.parseInt(s1);
y=Integer.parseInt(s2);
z=x+y;
//System.out.println(z);
return z ;
}

static int add(int s1, int s2)
{
int x,y,z;
x=s1;
y=s2;
z=x+y;
//System.out.println(z);
return z ;
}

}







執行結果:







D:\myjava>javac Myjava.java

D:\myjava>java Myjava 1 2
hsu chih-yu
1
2
7
3

D:\myjava>





輸出檔案 930201.ws01 內容:






1
2
3
4
5
6
8.4
9.3
0.2
7.9
3.4





第六週 2010/04/02

// 目標 Method Overload
class Myjava

{

public static void main(String[] args)
{
int w,u;
String s1,s2;
int a,b;
a=3;
b=4;
u=add(a,b);
s1=args[0];
s2=args[1];
w=add(s1,s2);
System.out.println(s1);
System.out.println(s2);
System.out.println(u);
System.out.println(w);
}

static int add(String s1,String s2)
{
int x,y,z;
x=Integer.parseInt(s1);
y=Integer.parseInt(s2);
z=x+y;
//System.out.println(z);
return z ;
}

static int add(int s1,int s2)
{
int x,y,z;
x=s1;
y=s2;
z=x+y;
//System.out.println(z);
return z ;
}


}

講義書

第五週 2010/03/26

class Myjava

{

public static void main(String[] args)
{
int x,y,z;
String s1,s2;
s1="1";
s2="2";
x=Integer.parseInt(s1);
y=Integer.parseInt(s2);
z=x+y;

System.out.println(args[0]);
System.out.println(args[1]);
System.out.println(z);

}

}

第四週 2010/03/19

工欲善其事必先利其器,學習Java必須先有工具。

Google

java下載

eclipse

Chapter1 建立第一個Java 程式
 網路資源下載並安裝Java的軟體開發環境。
 設定環境變數。
 熟悉命令提示字元視窗程式
 編輯與執行java第一個程式。
 了解設計Java程式的步驟。
 在獲得的錯誤訊息中,提供修改程式的提示。
 了解Java程式的一個最簡單的形式。

作業
以google 查java pi
列印
cos(0);
cos(pi/4);
cos(pi/2);
cos(3pi/3);
cos(2pi);
sin(0);
sin(pi/4);
sin(pi/2);
sin(3pi/3);
sin(2pi);


Chapter2 類別的設計與物件的使用

物件導向的觀念是從類別實作物件,再利用其方法與屬性。

 除了只有一個class 可以有 main()方法外,其他的類別只能有一個和類別名稱一樣的方法,此方法稱之為建構子。
 要電腦聽命作事的步驟要放在建構子中。
 請記住名言『作事需要方法』。
 利用上↑下↓鍵可以重複使用在命令提示字元已經打入的指令。

隨機亂數


第三週 2010/03/12

從嘗試錯誤中學習Java程式寫作
Learning Java from Error Messages
許志宇

『從嘗試錯誤中學習Java程式寫作』這一本教材是一種全新的Java教學法,克服同學懼怕學習程式時,面對錯誤產生時的茫然無知與手足無措,直接從嘗試錯誤中學習Java程式寫作。一般的Java書的寫法有條理與結構,但是學生無法自習而學會Java程式設計,因為在錯誤產生的時候,一般書本並沒有告訴您該如何解決,因此初學者在茫然無知手足無措的情況下,只好放棄學習Java程式設計。
『從錯誤中學習、從失敗裡成功、從跌倒處站立』是一種人生觀也可當成學習的法則,學習任何學問都要不怕失敗越挫越勇,終究會有爐火純青而登峰造極的境地。

 網路資源下載並安裝Java的軟體開發環境。
 設定環境變數。
 熟悉命令提示字元視窗程式
 編輯與執行java第一個程式。
 了解設計Java程式的步驟。
 在獲得的錯誤訊息中,提供修改程式的提示。
 了解Java程式的一個最簡單的形式。

 除了只有一個class 可以有 main()方法外,其他的類別只能有一個和類別名稱一樣的方法,此方法稱之為建構子。
 要電腦聽命作事的步驟要放在建構子中。
 請記住名言『作事需要方法』。
 利用上↑下↓鍵可以重複使用在命令提示字元已經打入的指令。


作業
1. 在main()方法中以System.out.printline 畫一棵聖誕樹。
2. 寫一個顯示字串的類別程式並含有建構子,在main()方法中實作物件,畫一棵聖誕樹。

第二週 2010/03/05
放假停課

第一週 2010/02/26
製作自己的學習部落格blog
回答下列問題
1.為何why要選修這門課?(動機)

2.希忘從這門課獲得那些知識?(目標)

3.我要如何修習這一門課?(態度與方法)

who, when, where t1 202

"Hello World!" for Microsoft Windows

修課同學

施宜亨
石孟昌
謝介文
楊維帆
張豫武
陳俊友
陳弘男
余孟儒
林郁銘
徐祥得
陳子洧
王智永
王偉亦
吳沛晃
廖敏芳
陳立棠
吳煒銘
劉佳馨
許庭碩
陳閔信
莊偉志
陳昭尹
陳建宏
林鈞平
許晉晏
林修麒
陳柏宇
宋嘉軒
王繹涵
苗予青
李云楷
湯筌凱
徐邦承
林宜欣
周亞君
闕聖翰
許祖逖
彭博瑜

沒有留言: