




版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報或認(rèn)領(lǐng)
文檔簡介
1、精選優(yōu)質(zhì)文檔-傾情為你奉上實(shí)訓(xùn)報告書實(shí)訓(xùn)名稱: Java程序設(shè)計(jì)實(shí)訓(xùn) 系 (部): 信息工程系 專業(yè)班級: 計(jì)算機(jī)科學(xué)與技術(shù) 學(xué)生姓名: 學(xué) 號: 指導(dǎo)教師: 張民 完成日期: 2015.12.11 山東科技大學(xué)泰山科技學(xué)院專心-專注-專業(yè)實(shí)訓(xùn)課題簡易計(jì)算器實(shí)訓(xùn)人姓名 同組人員實(shí)訓(xùn)日期2015.12.07至2015.12.11實(shí)訓(xùn)成績指導(dǎo)教師評語指導(dǎo)教師簽名:_年 _ 月_日目錄簡易計(jì)算機(jī)的設(shè)計(jì)與實(shí)現(xiàn)1 實(shí)訓(xùn)目的通過本課程設(shè)計(jì)能夠較全面的掌握面向?qū)ο蟪绦蛟O(shè)計(jì)的有關(guān)概念和開發(fā)方法,以便能較全面地理解、掌握和綜合運(yùn)用所學(xué)的知識,提高自身的編程能力。利用Java Applet圖形界面首先開
2、始設(shè)計(jì)一個計(jì)算器的界面,定義計(jì)算器所需要的按鈕并賦給其按鈕名稱,使得使用計(jì)算器時簡單明了,清晰可見,操作輕松。 給各個按鈕進(jìn)行算法,利用鼠標(biāo)點(diǎn)擊事件,當(dāng)鼠標(biāo)點(diǎn)擊某個按鈕時就開始執(zhí)行那個按鈕所定義的算法,生成數(shù)據(jù)并顯示。 除數(shù)字的輸入為直接進(jìn)行輸入外,其他運(yùn)算例如+、-、*、/、開平方等算法要求計(jì)算時通過內(nèi)部較為復(fù)雜的運(yùn)算將結(jié)果顯示在顯示屏上。 至于其中的進(jìn)制轉(zhuǎn)換功能的實(shí)現(xiàn)則是直接調(diào)用Java中進(jìn)制轉(zhuǎn)換的函數(shù),例如要將十進(jìn)制轉(zhuǎn)換成二進(jìn)制則可直接調(diào)用函數(shù)Inte
3、ger.toBinaryString(int i)來實(shí)現(xiàn),充分顯示了Java語言的簡潔性和Java語言功能的強(qiáng)大性。 當(dāng)然了在輸入數(shù)據(jù)時還要進(jìn)行異常捕捉,防止越界的現(xiàn)象的發(fā)生,這也是Java語言健壯性的體現(xiàn)!2 簡易計(jì)算機(jī)的分析與設(shè)計(jì)二級標(biāo)題:宋體小四號字,段前段后間距為0,報告中最多到二級標(biāo)題2.1 系統(tǒng)功能描述此系統(tǒng)可以實(shí)現(xiàn)如下功能:1)可進(jìn)行“+”、“-”、“*”、“/”以及混合運(yùn)算。2)支持()改變運(yùn)算的優(yōu)先級3)可進(jìn)行二、十六和十進(jìn)制數(shù)的相互轉(zhuǎn)換4)支持復(fù)制和粘貼操作2.2 系統(tǒng)模塊設(shè)計(jì)(1)加法
4、0;兩個數(shù)據(jù)進(jìn)行加操作,可以為小數(shù)。 (2)減法 兩個數(shù)據(jù)進(jìn)行減操作,可以為負(fù)數(shù)相減。 (3)乘法 兩個數(shù)相乘操作。 (4)除法 兩個數(shù)相除操作。 (5)開平方 對任意一個數(shù)進(jìn)行開方運(yùn)算,可以是小數(shù)。 (6)求余 對任意一個數(shù)進(jìn)行求余運(yùn)算。 (7)倒數(shù) 對任意一個數(shù)進(jìn)行倒數(shù)運(yùn)算。 (8)轉(zhuǎn)換 將十進(jìn)制數(shù)轉(zhuǎn)換為二進(jìn)制以及將二進(jìn)制轉(zhuǎn)換為十進(jìn)制。加法運(yùn)算2.3 數(shù)據(jù)庫結(jié)構(gòu)設(shè)計(jì)倒數(shù)運(yùn)算 減法運(yùn)算 計(jì)算器開平方運(yùn)算乘法運(yùn)
5、算求余運(yùn)算二進(jìn)制與十進(jìn)制轉(zhuǎn)除法運(yùn)算圖1 計(jì)算機(jī)E-R圖圖2 流程圖3 主要代碼清單 這段代碼主要是對程序的主框架進(jìn)行相應(yīng)的設(shè)置 super("簡易計(jì)算器"); setSize(300,260); this.setLayout(new BorderLayout(); jPanel1=new JPanel(); jPanel1.set
6、Layout(new GridLayout(1,1); /一行一列的布局 jPanel2=new JPanel(); jPanel2.setLayout(new GridLayout(6,4); /六行四列的布局 resultField=new JTextField("0"); jPanel1.add(resultField);
7、60; this.add(jPanel1,BorderLayout.NORTH); this.add(jPanel2,BorderLayout.CENTER);設(shè)置數(shù)字按鈕1到9并添加監(jiān)控以及符號等的添加監(jiān)控 s1=new JButton(" 1 "); s1.addActionListener(this); s2=new JButton("
8、160;2 "); s2.addActionListener(this); s3=new JButton(" 3 "); s3.addActionListener(this); s4=new JButton(" 4 "); s4.addA
9、ctionListener(this);s5=new JButton(" 5 "); s5.addActionListener(this); s6=new JButton(" 6 "); s6.addActionListener(this); s7=new JButto
10、n(" 7 "); s7.addActionListener(this); s8=new JButton(" 8 "); s8.addActionListener(this); s9=new JButton(" 9
11、;"); s9.addActionListener(this); s0=new JButton(" 0 "); s0.addActionListener(this); b1=new JButton(" + "); b1.addActionListener(this);
12、160;b2=new JButton(" - "); b2.addActionListener(this); b3=new JButton(" * "); b3.addActionListener(this); b4=new JButton(" /&
13、#160; "); b4.addActionListener(this); b5=new JButton(" "); b5.addActionListener(this); b6=new JButton(" 開方 "); b6.addActionListener(this);
14、0; b7=new JButton(" % "); b7.addActionListener(this); b8=new JButton(" x! "); b8.addActionListener(this); b9=new JButton(" 1/x "); b9.a
15、ddActionListener(this); f1=new JButton(" . "); f1.addActionListener(this); f2=new JButton(" = "); f2.addActionListener(this); f3=new JBu
16、tton(" C "); f3.addActionListener(this); f4=new JButton(" 負(fù) "); f4.addActionListener(this); f5=new JButton(" 退格 "); f5.addActio
17、nListener(this); jPanel2.add(f3); jPanel2.add(b4); jPanel2.add(b3); jPanel2.add(f5); jPanel2.add(s7); jPanel2.add(s8);
18、160; jPanel2.add(s9); jPanel2.add(b1); jPanel2.add(s4); jPanel2.add(s5); jPanel2.add(s6); jPanel2.add(b2);
19、160; jPanel2.add(s1); jPanel2.add(s2); jPanel2.add(s3); jPanel2.add(b5); jPanel2.add(s0); jPanel2.add(f1);
20、160; jPanel2.add(f4); jPanel2.add(b6); jPanel2.add(b7); jPanel2.add(b8); jPanel2.add(b9); jPanel2.add(f2); (3)數(shù)據(jù)輸入用方法num(int i)設(shè)計(jì)如下: public void num(int i) &
21、#160; String s = null; s=String.valueOf(i); /返回整數(shù)i的字符串表示形式 if(end) /如果數(shù)字輸入結(jié)束,則將文本框置零,重新輸入 resultField.setText(&
22、quot;0"); end=false; if(resultField.getText().equals("0") /如果文本框的內(nèi)
23、容為零,則覆蓋文本框的內(nèi)容 resultField.setText(s); else /如果文本框的內(nèi)容不為零,則在內(nèi)容后面添加數(shù)字
24、60; str = resultField.getText() + s; resultField.setText(str); 以及用JFrame的方法actionPerformed(ActionEvent e)來獲取數(shù)據(jù) (4)符號運(yùn)算及清零、退格的設(shè)計(jì)如下:
25、;if(add) / 加法 num1=num1 +num2; else if(sub)
26、; /減法 num1=num1 - num2; else if(mul) /乘法
27、60; num1=num1 * num2; else if(div) /除法 if (num2=0) throw new ArithmeticException(&q
28、uot;除數(shù)不能為零"); elsenum1=num1 / num2; else if(chf) /乘方 if(num2=0) num1=1;
29、0; else num1=Math.pow(num1, num2); else if(evo) /開方
30、60; if(num2<0) throw new ArithmeticException("被開方數(shù)不能小于零"); else num1=Math.sqrt(num2); else if(rec)
31、; /倒數(shù) if(num2<0) throw new ArithmeticException("分母不能小于零"); else num1=1/num2; else if(per)
32、60; /百分 num1=num1/100.0; else if(pur) /階乘 if(num2<0) throw new Ari
33、thmeticException("負(fù)數(shù)不能求階乘"); else for(int i=1;i<num2;i+) num1=i*num1; resultField.setText(String.valueOf(num1);&
34、#160; end=true; else if(e.getSource()=f3) /實(shí)現(xiàn)清零 resultField.setText("0");
35、else if(e.getSource()=f4) /實(shí)現(xiàn)負(fù)號 if(resultField.getText()!="0") resultField.setText("-"+resultField.getText(); else if(e.getSource()=f5)
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 【正版授權(quán)】 ISO/IEC 14496-15:2024/Amd 1:2025 EN Information technology - Coding of audio-visual objects - Part 15: Carriage of network abstraction layer (NAL) unit structured video in t
- 2025年度新能源汽車充電樁安裝承包合同
- 2025年度生物制藥工藝保密協(xié)議
- 2025年血液灌流吸附器項(xiàng)目建議書
- 2025年度海上石油鉆井平臺運(yùn)輸與維護(hù)服務(wù)合同
- 品牌創(chuàng)新過程中的團(tuán)隊(duì)協(xié)作計(jì)劃
- 倉庫退貨管理的改進(jìn)方案計(jì)劃
- 主管工作總結(jié)的績效任務(wù)安排計(jì)劃
- 志愿者活動中的個人成長計(jì)劃
- 市場營銷活動的經(jīng)驗(yàn)與教訓(xùn)計(jì)劃
- 營養(yǎng)學(xué)緒論(精)
- 形位公差測量方法
- 車轍防治指導(dǎo)意見(確定稿)
- 最新ICD-9手術(shù)編碼
- 軟件項(xiàng)目報價方法參考模板
- 門診特殊病種審批表
- 國際形式發(fā)票模板
- 山西省會計(jì)師事務(wù)所服務(wù)收費(fèi)標(biāo)準(zhǔn)(匯編)
- 陜西延長石油(集團(tuán))有限責(zé)任公司企業(yè)年金方案
- 跟單人員績效考核表
- 常用偽裝方法組訓(xùn)方案
評論
0/150
提交評論