ImageVerifierCode 换一换
格式:DOCX , 页数:18 ,大小:805.45KB ,
资源ID:23558100      下载积分:3 金币
快捷下载
登录下载
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。 如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

加入VIP,免费下载
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.bdocx.com/down/23558100.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录   QQ登录  

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文(JAVA程序课程设计计算器编辑.docx)为本站会员(b****7)主动上传,冰豆网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知冰豆网(发送邮件至service@bdocx.com或直接QQ联系客服),我们立即给予删除!

JAVA程序课程设计计算器编辑.docx

1、JAVA程序课程设计计算器编辑程序课程设计-JAVA实验报告 开课院系:经济管理学院 实 验:JAVA课程设计 班 级:信管111 学生姓名:杨平 学 号:209110631 南京工程学院1、实验内容与步骤 将下列程序,改造成算器,要求 1、 增加乘、除、减法运算 2、 改正现行的近似计算,即现在用7.6+7.8=15.39999999这个问题 3、(选作)进行乘方、开方、取模运算 4、(选作)进行统计功能开发,功能自定义。比如多个数的平均值求法等 5、(选作)实现二进制运算 二、系统分析 利用JAVA程序设计开发计算器,在老师的指导和程序代码的改编下,最终实现计算器的加、减、乘、除、开方、取

2、模、乘方等功能,除此之外,还将解决该计算器的近似计算问题。课程设计的计算器虽然功能不是很全面,但是也实现了一些简单的计算功能。三、系统总体设计或详细设计(简单写出即可)用JAVA编译计算器,系统面板包括了一组button控件,控件采用5X4的布局方式,再将界面大小控制在600x480大小,其中包括09数字、还有+、*、/、乘方、取模、开方等功能。(如图)一、计算加法12+13二、计算减法3626三、计算乘法5*12四、计算除法36/12五、计算乘方8的2次方六、计算开方49的开方七、计算取模,10除4八、解决近似计算,7.6+7.8四、程序代码import java.awt.*;import

3、java.awt.event.*;import javax.swing.*;import java.text.DecimalFormat;import java.lang.Math;public class Calculator extends JFrame implements ActionListenerDecimalFormat df=(DecimalFormat)DecimalFormat.getInstance(); private JPanel jPanel1,jPanel2; private JTextField resultField; private JButton s1,s

4、2,s3,s4,s5,s6,s7,s8,s9,s0,b1,b2,b3,b4,b5,b6,b7,f1,f2,f3; private boolean end,add,sub,mul,div,pow,sqr,mod; private String str; private double num1,num2; public Calculator() super(Calculate); setSize(600,480); Container con=getContentPane(); con.setLayout(new BorderLayout(); jPanel1=new JPanel(); jPan

5、el1.setLayout(new GridLayout(1,1); jPanel2=new JPanel(); jPanel2.setLayout(new GridLayout(4,5); resultField=new JTextField(0); jPanel1.add(resultField); con.add(jPanel1,BorderLayout.NORTH); s1=new JButton( 1 ); s1.addActionListener(this); s2=new JButton( 2 ); s2.addActionListener(this); s3=new JButt

6、on( 3 ); s3.addActionListener(this); s4=new JButton( 4 ); s4.addActionListener(this); s5=new JButton( 5 ); s5.addActionListener(this); s6=new JButton( 6 ); s6.addActionListener(this); s7=new JButton( 7 ); s7.addActionListener(this); s8=new JButton( 8 ); s8.addActionListener(this); s9=new JButton( 9

7、); s9.addActionListener(this); s0=new JButton( 0 ); s0.addActionListener(this); b1=new JButton( + ); b1.addActionListener(this); b2=new JButton( - ); b2.addActionListener(this); b3=new JButton( * ); b3.addActionListener(this); b4=new JButton( / ); b4.addActionListener(this); b5=new JButton( ); b5.ad

8、dActionListener(this); b6=new JButton( sqr ); b6.addActionListener(this); b7=new JButton( % ); b7.addActionListener(this); f1=new JButton( . ); f1.addActionListener(this); f2=new JButton( = ); f2.addActionListener(this); f3=new JButton( OFF ); f3.addActionListener(this); jPanel2.add(s1); jPanel2.add

9、(s2); jPanel2.add(s3); jPanel2.add(b1); jPanel2.add(b5); jPanel2.add(s4); jPanel2.add(s5); jPanel2.add(s6); jPanel2.add(b2); jPanel2.add(b6); jPanel2.add(s7); jPanel2.add(s8); jPanel2.add(s9); jPanel2.add(b3); jPanel2.add(b7); jPanel2.add(f1); jPanel2.add(s0); jPanel2.add(f2); jPanel2.add(b4); jPane

10、l2.add(f3); con.add(jPanel2,BorderLayout.CENTER); public void num(int i) String s = null; s=String.valueOf(i); if(end) resultField.setText(0); end=false; if(resultField.getText().equals(0) resultField.setText(s); else str = resultField.getText() + s; resultField.setText(str); public void actionPerfo

11、rmed(ActionEvent e) if(e.getSource()=s1) num(1); else if(e.getSource()=s2) num(2); else if(e.getSource()=s3) num(3); else if(e.getSource()=s4) num(4); else if(e.getSource()=s5) num(5); else if(e.getSource()=s6) num(6); else if(e.getSource()=s7) num(7); else if(e.getSource()=s8) num(8); else if(e.get

12、Source()=s9) num(9); else if(e.getSource()=s0) num(0); else if(e.getSource()=b1) sign(1); else if(e.getSource()=b2) sign(2); else if(e.getSource()=b3) sign(3); else if(e.getSource()=b4) sign(4); else if(e.getSource()=b5) sign(5); else if(e.getSource()=b6) sign(6); else if(e.getSource()=b7) sign(7);

13、else if(e.getSource()=f1) str=resultField.getText(); if(str.indexOf(.)=1) str+=.; resultField.setText(str); else if(e.getSource()=f2) num2=Double.parseDouble(resultField.getText(); if(add) num1=num1 + num2; else if(sub) num1=num1 - num2; else if(mul) num1=num1 * num2; else if(div) num1=num1 / num2;

14、else if(pow) num1=Math.pow(num1,num2); else if(sqr) num1=Math.sqrt(num1); else if(mod) num1=num1 % num2; df.setMaximumFractionDigits(2); String x=df.format(num1); resultField.setText(x); end=true; if(e.getSource()=f3) System.exit(0); public void sign(int s) if(s=1) add=true; sub=false; mul=false; di

15、v=false; pow=false; sqr=false; mod=false; else if(s=2) add=false; sub=true; mul=false; div=false; pow=false; sqr=false; mod=false; else if(s=3) add=false; sub=false; mul=true; div=false; pow=false; sqr=false; mod=false; else if(s=4) add=false; sub=false; mul=false; div=true; pow=false; sqr=false; mo

16、d=false; else if(s=5) add=false; sub=false; mul=false; div=false; pow=true; sqr=false; mod=false; else if(s=6) add=false; sub=false; mul=false; div=false; pow=false; sqr=true; mod=false; else if(s=7) add=false; sub=false; mul=false; div=false; pow=false; sqr=false; mod=true; num1=Double.parseDouble(

17、resultField.getText(); end=true; public static void main(String args) Calculator th1=new Calculator(); th1.show(); 五、收获体会 通过这次课程设计实践,我深深地体会到java程序设计的内涵,我不但进一步理解到老师上课所传授的知识,而且在自我程序设计上也有了一个完美的突破。通过老师的指导和自己查阅资料,最终把计算器给编译出来了。这次设计的计算器,刚开始觉得很难,但是后来觉得很有趣,通过自己慢慢的摸索和请教老师,我一步一个脚印,将老师所给的代码,进一步解读,慢慢的自己也就会了,其实大体上都是差不多的,只要按照老师所给的加法和减法程序,那么乘法和除法以及乘方、取模等计算功能都可以将其模仿出来。经过了一天的自习研究,该计算器最终被我做出来了,最终实现计算器的加、减、乘、除、开方、取模、乘方等功能,除此之外,还将解决该计算器的近似计算问题。课程设计的计算器虽然功能不是很全面,但是也实现了一些简单的计算功能。 所以这次课程设计虽然比较困难,但是只要态度认真,最终就可以将计算器攻克,将理论与实践相结合,那么就会收获到你想要的结果。

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1