面向对象课程设计模拟科学计算器.docx

上传人:b****0 文档编号:9064802 上传时间:2023-05-16 格式:DOCX 页数:20 大小:68.22KB
下载 相关 举报
面向对象课程设计模拟科学计算器.docx_第1页
第1页 / 共20页
面向对象课程设计模拟科学计算器.docx_第2页
第2页 / 共20页
面向对象课程设计模拟科学计算器.docx_第3页
第3页 / 共20页
面向对象课程设计模拟科学计算器.docx_第4页
第4页 / 共20页
面向对象课程设计模拟科学计算器.docx_第5页
第5页 / 共20页
面向对象课程设计模拟科学计算器.docx_第6页
第6页 / 共20页
面向对象课程设计模拟科学计算器.docx_第7页
第7页 / 共20页
面向对象课程设计模拟科学计算器.docx_第8页
第8页 / 共20页
面向对象课程设计模拟科学计算器.docx_第9页
第9页 / 共20页
面向对象课程设计模拟科学计算器.docx_第10页
第10页 / 共20页
面向对象课程设计模拟科学计算器.docx_第11页
第11页 / 共20页
面向对象课程设计模拟科学计算器.docx_第12页
第12页 / 共20页
面向对象课程设计模拟科学计算器.docx_第13页
第13页 / 共20页
面向对象课程设计模拟科学计算器.docx_第14页
第14页 / 共20页
面向对象课程设计模拟科学计算器.docx_第15页
第15页 / 共20页
面向对象课程设计模拟科学计算器.docx_第16页
第16页 / 共20页
面向对象课程设计模拟科学计算器.docx_第17页
第17页 / 共20页
面向对象课程设计模拟科学计算器.docx_第18页
第18页 / 共20页
面向对象课程设计模拟科学计算器.docx_第19页
第19页 / 共20页
面向对象课程设计模拟科学计算器.docx_第20页
第20页 / 共20页
亲,该文档总共20页,全部预览完了,如果喜欢就下载吧!
下载资源
资源描述

面向对象课程设计模拟科学计算器.docx

《面向对象课程设计模拟科学计算器.docx》由会员分享,可在线阅读,更多相关《面向对象课程设计模拟科学计算器.docx(20页珍藏版)》请在冰点文库上搜索。

面向对象课程设计模拟科学计算器.docx

面向对象课程设计模拟科学计算器

软件学院

课程设计报告书

 

课程名称面向对象程序设计

设计题目模拟科学计算器

专业班级软件10-04班

学号1020010418

姓名王鑫

指导教师冯永安

 

2012年6月

 

目录

1设计时间3

2设计目的3

3设计任务3

4设计内容3

4.1需求分析3

4.1.1问题描述3

4.1.2基本要求3

4.2总体设计3

4.2.1包的描述3

4.2.2类的描述3

4.2.3类之间的关系3

4.3详细设计4

4.3.1类图4

4.3.2页面设计4

4.4测试与分析5

4.5程序代码5

5总结与展望17

参考文献18

课程设计成绩评定18

1设计时间

2011年6月13日-2011年6月19日

2设计目的

《面向对象程序设计》是一门实践性很强的计算机专业基础课程,课程设计是学习完该课程后进行的一次较全面的综合练习。

其目的在于通过实践加深学生对面向对象程序设计的理论、方法和基础知识的理解,掌握使用Java语言进行面向对象设计的基本方法,提高运用面向对象知识分析实际问题、解决实际问题的能力,提高学生的应用能力。

3设计任务

界面模拟Windows中的计算器程序。

实现基本数学运算、函数等功能:

加、减、乘、除、阶乘、正弦、余弦和指数运算。

实现要点:

添加相关组件并进行按钮事件处理。

4设计内容

4.1需求分析

4.1.1问题描述

应用Java相关知识(JavaGUI为主)设计一个程序完成加、减、乘、除、阶乘、正弦、余弦和指数运算。

4.1.2基本要求

给按钮添加事件,完成加、减、乘、除、阶乘、正弦、余弦和指数运算。

4.2总体设计

4.2.1包的描述

没涉及用包

4.2.2类的描述

只用了一个Calculator类里边包含程序入口main函数,Calculator()构造函数完成对各个组件的定义和初始化,myEvent()完成事件监听的各种功能。

4.2.3类之间的关系

Calculator类集中完成各项功能。

4.3详细设计

4.3.1类图

图1myeclpse自动生成类图

4.3.2页面设计

图2计算机完成界面

4.4测试与分析

图37*6=42.0

图45!

=120.0

图5sin90=1

图63^2=9

4.5程序代码

importjava.awt.*;

importjava.awt.event.*;

importjavax.swing.*;

importjava.math.*;

classCalculator

{

GridLayoutl1;

GridLayoutl2;

BorderLayoutl3;

Framef;

Panelp1,p2;

JTextFieldt1;

TextFieldt2;

JButtonb1,b2,b3,b4,b5,b6,b7,b8,b9,b10,b11,b12,b13,b14,b15,b16,b17,b18,b19,b20;

StringBufferstr;

doublex,y;

intz;

staticdoublem;

publicCalculator()

{

f=newFrame("计算器");

f.setBounds(300,100,600,500);

l1=newGridLayout(1,5,5,5);

l2=newGridLayout(4,5,5,5);

l3=newBorderLayout();

p1=newPanel();

p2=newPanel();

t1=newJTextField(27);

t1.setHorizontalAlignment(JTextField.RIGHT);

t1.setEnabled(true);

t1.setText("0");

t2=newTextField();

t2.setEnabled(false);

b1=newJButton("7");

b1.setForeground(Color.black);

b2=newJButton("8");

b2.setForeground(Color.black);

b3=newJButton("9");

b3.setForeground(Color.black);

b4=newJButton("/");

b4.setForeground(Color.blue);

b5=newJButton("x!

");

b5.setForeground(Color.blue);

b6=newJButton("4");

b6.setForeground(Color.black);

b7=newJButton("5");

b7.setForeground(Color.black);

b8=newJButton("6");

b8.setForeground(Color.black);

b9=newJButton("*");

b9.setForeground(Color.blue);

b10=newJButton("x^y");

b10.setForeground(Color.blue);

b11=newJButton("1");

b11.setForeground(Color.black);

b12=newJButton("2");

b12.setForeground(Color.black);

b13=newJButton("3");

b13.setForeground(Color.black);

b14=newJButton("-");

b14.setForeground(Color.blue);

b15=newJButton("C");

b15.setForeground(Color.red);

b16=newJButton("0");

b16.setForeground(Color.black);

b17=newJButton("sin");

b17.setForeground(Color.pink);

b18=newJButton("cos");

b18.setForeground(Color.pink);

b19=newJButton("+");

b19.setForeground(Color.blue);

b20=newJButton("=");

b20.setForeground(Color.green);

str=newStringBuffer();

p1.add(t1);

p1.setBounds(10,25,300,45);

p1.setLayout(l1);

p2.setLayout(l2);

p2.add(b1);

p2.add(b2);

p2.add(b3);

p2.add(b4);

p2.add(b5);

p2.add(b6);

p2.add(b7);

p2.add(b8);

p2.add(b9);

p2.add(b10);

p2.add(b11);

p2.add(b12);

p2.add(b13);

p2.add(b14);

p2.add(b15);

p2.add(b16);

p2.add(b17);

p2.add(b18);

p2.add(b19);

p2.add(b20);

p2.setBounds(10,65,300,30);

f.setTitle("计算器");

f.setResizable(false);

f.setBackground(newColor(200,200,100));

f.setBounds(100,100,420,250);

f.setLayout(l3);

f.add(BorderLayout.NORTH,p1);

f.add(BorderLayout.CENTER,p2);

myEvent();

f.setVisible(true);

}

privatevoidmyEvent()

{

f.addWindowListener(newWindowAdapter(){

publicvoidwindowClosing(WindowEvente0){

System.exit(0);

}});

try{

b1.addMouseListener(newMouseAdapter()

{

publicvoidmouseClicked(MouseEvente1)

{

t1.setText(str.append(7).toString());

y=Double.parseDouble(t1.getText().trim());

}

});

b2.addMouseListener(newMouseAdapter()

{

publicvoidmouseClicked(MouseEvente2)

{

t1.setText(str.append(8).toString());

y=Double.parseDouble(t1.getText().trim());

}

});

b3.addMouseListener(newMouseAdapter()

{

publicvoidmouseClicked(MouseEvente3)

{

t1.setText(str.append(9).toString());

y=Double.parseDouble(t1.getText().trim());

}

});

b6.addMouseListener(newMouseAdapter()

{

publicvoidmouseClicked(MouseEvente6)

{

t1.setText(str.append(4).toString());

y=Double.parseDouble(t1.getText().trim());

}

});

b7.addMouseListener(newMouseAdapter()

{

publicvoidmouseClicked(MouseEvente7)

{

t1.setText(str.append(5).toString());

y=Double.parseDouble(t1.getText().trim());

}

});

b8.addMouseListener(newMouseAdapter()

{

publicvoidmouseClicked(MouseEvente8)

{

t1.setText(str.append(6).toString());

y=Double.parseDouble(t1.getText().trim());

}

});

b11.addMouseListener(newMouseAdapter()

{

publicvoidmouseClicked(MouseEvente11)

{

t1.setText(str.append

(1).toString());

y=Double.parseDouble(t1.getText().trim());

}

});

b12.addMouseListener(newMouseAdapter()

{

publicvoidmouseClicked(MouseEvente12)

{

t1.setText(str.append

(2).toString());

y=Double.parseDouble(t1.getText().trim());

}

});

b13.addMouseListener(newMouseAdapter()

{

publicvoidmouseClicked(MouseEvente13)

{

t1.setText(str.append(3).toString());

y=Double.parseDouble(t1.getText().trim());

}

});

b16.addMouseListener(newMouseAdapter()

{

publicvoidmouseClicked(MouseEvente16)

{

t1.setText(str.append(0).toString());

y=Double.parseDouble(t1.getText().trim());

}

});

b15.addMouseListener(newMouseAdapter()

{

publicvoidmouseClicked(MouseEvente15)

{

t1.setText("0");

str.setLength(0);

}

});

b19.addMouseListener(newMouseAdapter()

{

publicvoidmouseClicked(MouseEvente19)

{

x=Double.parseDouble(t1.getText().trim());

str.setLength(0);

y=0d;

z=0;

}

});

b14.addMouseListener(newMouseAdapter()

{

publicvoidmouseClicked(MouseEvente14)

{

x=Double.parseDouble(t1.getText().trim());

str.setLength(0);

y=0d;

z=1;

}

});

b9.addMouseListener(newMouseAdapter()

{

publicvoidmouseClicked(MouseEvente9)

{

x=Double.parseDouble(t1.getText().trim());

str.setLength(0);

y=0d;

z=2;

}

});

b4.addMouseListener(newMouseAdapter()

{

publicvoidmouseClicked(MouseEvente4)

{

x=Double.parseDouble(t1.getText().trim());

str.setLength(0);

y=0d;

z=3;

}

});

b5.addMouseListener(newMouseAdapter()

{

publicvoidmouseClicked(MouseEvente5)

{

x=Integer.parseInt(t1.getText());

intsum=1;

for(inti=1;i<=x;i++)

{

sum*=i;

}

x=sum;

y=0d;

z=0;

}

});

b10.addMouseListener(newMouseAdapter()

{

publicvoidmouseClicked(MouseEvente10)

{

x=Integer.parseInt(t1.getText());

str.setLength(0);t1.setText("");

y=0d;

z=4;

}

});

b17.addMouseListener(newMouseAdapter()

{

publicvoidmouseClicked(MouseEvente17)

{

x=Integer.parseInt(t1.getText());

x=Math.round(Math.sin(x));

y=0d;

z=0;

}

});

b18.addMouseListener(newMouseAdapter()

{

publicvoidmouseClicked(MouseEvente18)

{

x=Integer.parseInt(t1.getText());

x=Math.round(Math.cos(x));

y=0d;

z=0;

}

});

b20.addMouseListener(newMouseAdapter()

{

publicvoidmouseClicked(MouseEvente20)

{

str.setLength(0);

switch(z)

{

case0:

t1.setText(""+(x+y));break;

case1:

t1.setText(""+(x-y));break;

case2:

t1.setText(""+(x*y));break;

case3:

t1.setText(""+(x/y));break;

case4:

{

intsum=1;

for(inti=1;i<=y;i++)

{

sum*=x;

}

t1.setText(""+sum);break;

}

}

}

});}

catch(NumberFormatExceptione){

t1.setText("数字格式异常");

}

catch(StringIndexOutOfBoundsExceptione){

t1.setText("字符串索引越界");

}

}

publicstaticvoidmain(Stringargs[])

{

newCalculator();

}

}

5总结与展望

在这次课程设计过程中,我深刻的感受到自己所学的应用能力很弱,以后要多多练习,加强实战能力。

在完成过程中,初始界面的完成还比较顺利,但是后期的加入事件监听的过程费很大的劲儿,在下载网上的视频,看笔记,看老师上课的实例之后才基本完成,依旧有很多的错误,后期很多的更改之后,最终完成各项功能。

然而,对于异常的处理还不够,因此还需改进。

 

参考文献

[1]刘万军等编著Java6程序设计实践教程第一版

[2]

课程设计成绩评定

出勤

情况

缺勤次数:

课程

设计

评估

设计成绩

教师签字

展开阅读全文
相关资源
猜你喜欢
相关搜索
资源标签

当前位置:首页 > IT计算机 > 电脑基础知识

copyright@ 2008-2023 冰点文库 网站版权所有

经营许可证编号:鄂ICP备19020893号-2