您的位置:首页 > 编程语言

原创学生成绩计算器代码

2009-02-23 14:54 141 查看
学校每学期开学都要算学生成绩的加权平均及绩点。以前都是用笔用计算器算的,耗时耗力。我就写了一个小东西出来,这是用eclipse编辑的安装了VE插件之后建的VisualClass,SWT的,传上来给大家看看,希望大家能帮忙优化优化,谢谢了。另外我是新手,欢迎各位看官提意见。
import java.awt.*;
import javax.swing.*;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Text;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Button;
public class calculater {
private Shell sShell = null;
private Label label1 = null;
private Label label2 = null;
private Label label3 = null;
private Label label4 = null;
private Text text10 = null;
private Text text11 = null;
private Text text12 = null;
private Text text13 = null;
private Text text14 = null;
private Text text15 = null;
private Text text16 = null;
private Text text17 = null;
private Text text18 = null;
private Text text19 = null;
private Text text20 = null;
private Text text21 = null;
private Text text22 = null;
private Text text23 = null;
private Text text24 = null;
private Text text25 = null;
private Text text26 = null;
private Text text27 = null;
private Text text28 = null;
private Text text29 = null;
private Text text30 = null;
private Text text31 = null;
private Button button = null;
private Button button1 = null;
private Button button2 = null;
private Label label5 = null;
private Text text32 = null;
public static void main(String[] args) {
Display display = Display.getDefault();
calculater thisClass = new calculater();
thisClass.createSShell();
thisClass.sShell.open();
while (!thisClass.sShell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
display.dispose();
}
private void createSShell() {
sShell = new Shell();
sShell.setText("加权平均分及绩点计算工具");
sShell.setSize(new Point(470, 184));
sShell.setLayout(null);
Dimension screen=Toolkit.getDefaultToolkit().getScreenSize();
sShell.setLocation((screen.width-470)/2,(screen.height-161)/2);
label1 = new Label(sShell, SWT.CENTER);
label1.setBounds(new Rectangle(16, 14, 65, 15));
label1.setToolTipText("在字符框中输入各科成绩");
label1.setText("各科成绩:");
label2 = new Label(sShell, SWT.CENTER);
label2.setBounds(new Rectangle(16, 47, 65, 15));
label2.setToolTipText("对应上一排各科成绩输入学分");
label2.setText("各科学分:");
label3 = new Label(sShell, SWT.CENTER);
label3.setBounds(new Rectangle(15, 84, 49, 15));
label3.setToolTipText("总学分");
label3.setText("总学分:");
label4 = new Label(sShell, SWT.CENTER);
label4.setBounds(new Rectangle(117, 84, 60, 15));
label4.setToolTipText("各科成绩的加权平均数");
label4.setText("加权平均:");
text10 = new Text(sShell, SWT.BORDER);
text10.setBounds(new Rectangle(90, 11, 27, 18));
text10.setText("");
text11 = new Text(sShell, SWT.BORDER);
text11.setBounds(new Rectangle(126, 11, 27, 18));
text11.setText("");
text12 = new Text(sShell, SWT.BORDER);
text12.setBounds(new Rectangle(162, 11, 27, 18));
text12.setText("");
text13 = new Text(sShell, SWT.BORDER);
text13.setBounds(new Rectangle(197, 11, 27, 18));
text13.setText("");
text14 = new Text(sShell, SWT.BORDER);
text14.setBounds(new Rectangle(234, 11, 27, 18));
text14.setText("");
text15 = new Text(sShell, SWT.BORDER);
text15.setBounds(new Rectangle(270, 11, 27, 18));
text15.setText("");
text16 = new Text(sShell, SWT.BORDER);
text16.setBounds(new Rectangle(306, 11, 27, 18));
text16.setText("");
text17 = new Text(sShell, SWT.BORDER);
text17.setBounds(new Rectangle(342, 11, 27, 18));
text17.setText("");
text18 = new Text(sShell, SWT.BORDER);
text18.setBounds(new Rectangle(378, 11, 27, 18));
text18.setText("");
text19 = new Text(sShell, SWT.BORDER);
text19.setBounds(new Rectangle(415, 11, 27, 18));
text19.setText("");
text20 = new Text(sShell, SWT.BORDER);
text20.setBounds(new Rectangle(90, 46, 27, 18));
text20.setText("");
text21 = new Text(sShell, SWT.BORDER);
text21.setBounds(new Rectangle(126, 47, 27, 18));
text21.setText("");
text22 = new Text(sShell, SWT.BORDER);
text22.setBounds(new Rectangle(163, 47, 27, 18));
text22.setText("");
text23 = new Text(sShell, SWT.BORDER);
text23.setBounds(new Rectangle(199, 47, 27, 18));
text23.setText("");
text24 = new Text(sShell, SWT.BORDER);
text24.setBounds(new Rectangle(235, 47, 27, 18));
text24.setText("");
text25 = new Text(sShell, SWT.BORDER);
text25.setBounds(new Rectangle(271, 47, 27, 18));
text25.setText("");
text26 = new Text(sShell, SWT.BORDER);
text26.setBounds(new Rectangle(307, 47, 27, 18));
text26.setText("");
text27 = new Text(sShell, SWT.BORDER);
text27.setBounds(new Rectangle(343, 47, 27, 18));
text27.setText("");
text28 = new Text(sShell, SWT.BORDER);
text28.setBounds(new Rectangle(379, 47, 27, 18));
text28.setText("");
text29 = new Text(sShell, SWT.BORDER);
text29.setBounds(new Rectangle(416, 47, 27, 18));
text29.setText("");
text30 = new Text(sShell, SWT.BORDER);
text30.setBounds(new Rectangle(67, 81, 41, 18));
text30.setToolTipText("总学分");
text30.setText("");
text31 = new Text(sShell, SWT.BORDER);
text31.setBounds(new Rectangle(182, 82, 97, 18));
text31.setToolTipText("各科成绩的加权平均数");
text31.setText("");
button = new Button(sShell, SWT.NONE);
button.setBounds(new Rectangle(303, 109, 73, 22));
button.setToolTipText("点击按钮进行计算");
button.setText("计算");
button1 = new Button(sShell, SWT.NONE);
button1.setBounds(new Rectangle(74, 110, 83, 22));
button1.setToolTipText("清除第一排成绩部分数据");
button1.setText("清除成绩部分");
button1.addSelectionListener(new org.eclipse.swt.events.SelectionAdapter() {
public void widgetSelected(org.eclipse.swt.events.SelectionEvent e) {
text10.setText("");
text11.setText("");
text12.setText("");
text13.setText("");
text14.setText("");
text15.setText("");
text16.setText("");
text17.setText("");
text18.setText("");
text19.setText("");
}
});
button2 = new Button(sShell, SWT.NONE);
button2.setBounds(new Rectangle(202, 110, 65, 22));
button2.setToolTipText("清除所有数据");
button2.setText("清除全部");
label5 = new Label(sShell, SWT.NONE);
label5.setBounds(new Rectangle(284, 84, 39, 17));
label5.setToolTipText("学分绩点");
label5.setText("绩点:");
text32 = new Text(sShell, SWT.BORDER);
text32.setBounds(new Rectangle(328, 82, 101, 18));
text32.setToolTipText("学分绩点");
button2.addSelectionListener(new org.eclipse.swt.events.SelectionAdapter() {
public void widgetSelected(org.eclipse.swt.events.SelectionEvent e) {
text10.setText("");
text11.setText("");
text12.setText("");
text13.setText("");
text14.setText("");
text15.setText("");
text16.setText("");
text17.setText("");
text18.setText("");
text19.setText("");
text20.setText("");
text21.setText("");
text22.setText("");
text23.setText("");
text24.setText("");
text25.setText("");
text26.setText("");
text27.setText("");
text28.setText("");
text29.setText("");
text30.setText("");
text31.setText("");
text32.setText("");
}
});
button.addSelectionListener(new org.eclipse.swt.events.SelectionAdapter() {
public void widgetSelected(org.eclipse.swt.events.SelectionEvent e) {
String a10=text10.getText();
String a11=text11.getText();
String a12=text12.getText();
String a13=text13.getText();
String a14=text14.getText();
String a15=text15.getText();
String a16=text16.getText();
String a17=text17.getText();
String a18=text18.getText();
String a19=text19.getText();
String b20=text20.getText();
String b21=text21.getText();
String b22=text22.getText();
String b23=text23.getText();
String b24=text24.getText();
String b25=text25.getText();
String b26=text26.getText();
String b27=text27.getText();
String b28=text28.getText();
String b29=text29.getText();
Float x10,x11,x12,x13,x14,x15,x16,x17,x18,x19;
if(a10==null||a10=="") x10=(float)0;
else x10=Float.parseFloat(a10);
if(a11==null||a11=="") x11=(float)0;
else x11=Float.parseFloat(a11);
if(a12==null||a12=="") x12=(float)0;
else x12=Float.parseFloat(a12);
if(a13==null||a13=="") x13=(float)0;
else x13=Float.parseFloat(a13);
if(a14==null||a14=="") x14=(float)0;
else x14=Float.parseFloat(a14);
if(a15==null||a15=="") x15=(float)0;
else x15=Float.parseFloat(a15);
if(a16==null||a16=="") x16=(float)0;
else x16=Float.parseFloat(a16);
if(a17==null||a17=="") x17=(float)0;
else x17=Float.parseFloat(a17);
if(a18==null||a18=="") x18=(float)0;
else x18=Float.parseFloat(a18);
if(a19==null||a19=="") x19=(float)0;
else x19=Float.parseFloat(a19);
Float y20,y21,y22,y23,y24,y25,y26,y27,y28,y29;
if(b20==null||b20=="") y20=(float)0;
else y20=Float.parseFloat(b20);
if(b21==null||b21=="") y21=(float)0;
else y21=Float.parseFloat(b21);
if(b22==null||b22=="") y22=(float)0;
else y22=Float.parseFloat(b22);
if(b23==null||b23=="") y23=(float)0;
else y23=Float.parseFloat(b23);
if(b24==null||b24=="") y24=(float)0;
else y24=Float.parseFloat(b24);
if(b25==null||b25=="") y25=(float)0;
else y25=Float.parseFloat(b25);
if(b26==null||b26=="") y26=(float)0;
else y26=Float.parseFloat(b26);
if(b27==null||b27=="") y27=(float)0;
else y27=Float.parseFloat(b27);
if(b28==null||b28=="") y28=(float)0;
else y28=Float.parseFloat(b28);
if(b29==null||b29=="") y29=(float)0;
else y29=Float.parseFloat(b29);
double result1 = 0;
double result2 = 0;
double w=0;
try{
w=y20+y21+y22+y23+y24+y25+y26+y27+y28+y29;
if(w!=0){
result1=(x10*y20+x11*y21+x12*y22+x13*y23+x14*y24+x15*y25+x16*y26+x17*y27+x18*y28+x19*y29)/w;
result2=(result1-50)/10;
text30.setText(Double.toString(w));
text31.setText(Double.toString(result1));
text32.setText(Double.toString(result2));
}
else JOptionPane.showMessageDialog(null,"各科成绩对应学分不能为空!");
}catch(Exception ee){
JOptionPane.showMessageDialog(null,"BUG EXIST"+ee);
}
}
});
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐