求助编写计算器的问题
请问下各位大虾们,我现在在编一个计算器的作业交上去,
请问下,* - + = 这些符号怎么实现他的功能,
需要用到哪些类,接口
------解决方案-------------------- 直接用好了
int a,b,c;
c=a+b;
c=a-b;
c=a*b;
c=a/b;
是不是被概念忽悠了...张口就类和接口...
这些基本的...系统默认类里面都带上了
------解决方案--------------------我先昏一下~
------解决方案--------------------多写几个方法就可以了啊!每个方法就相当于一个计算就可以了
------解决方案--------------------估计以前lz是搞汇编是的吧,呵呵
------解决方案--------------------import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class MyCalculater extends JFrame implements ActionListener{
JTextField tf=new JTextField();
String num= " ";
Double number;
int pointCount=0;
char operation;
JButton b1=new JButton( "1 ");
JButton b2=new JButton( "2 ");
JButton b3=new JButton( "3 ");
JButton b4=new JButton( "4 ");
JButton b5=new JButton( "5 ");
JButton b6=new JButton( "6 ");
JButton b7=new JButton( "7 ");
JButton b8=new JButton( "8 ");
JButton b9=new JButton( "9 ");
JButton b0=new JButton( "0 ");
JButton b10=new JButton( "+ ");
JButton b11=new JButton( "- ");
JButton b12=new JButton( "* ");
JButton b13=new JButton( "/ ");
JButton b14=new JButton( "= ");
JButton b15=new JButton( ". ");
JButton b16=new JButton( " <- ");
JButton b17=new JButton( "S ");
JButton b18=new JButton( "C ");
JButton b19=new JButton( "+/- ");
void buildConstraints(GridBagConstraints gbc,int gx,int gy,
int gw,int gh,int wx,int wy){
gbc.gridx=gx;
gbc.gridy=gy;
gbc.gridwidth=gw;
gbc.gridheight=gh;
gbc.weightx=wx;
gbc.weighty=wy;
}
public MyCalculater(){
super( "MyCaculater ");
setBounds(200,200,280,215);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setResizable(false);
GridBagLayout exlayout=new GridBagLayout();
GridBagConstraints constraints=new GridBagConstraints();
JPanel expane=new JPanel();
expane.setLayout(exlayout);
b0.addActionListener(this);
b1.addActionListener(this);
b2.addActionListener(this);
b3.addActionListener(this);
b4.addActionListener(this);
b5.addActionListener(this);
b6.addActionListener(this);
b7.addActionListener(this);
b8.addActionListener(this);
b9.addActionListener(this);
b10.addActionListener(this);
b11.addActionListener(this);
b12.addActionListener(this);
b13.addActionListener(this);
b14.addActionListener(this);
b15.addActionListener(this);
b16.addActionListener(this);
b17.addActionListener(this);
b18.addActionListener(this);
b19.addActionListener(this);
GridLayout inlayout=new GridLayout(4,5,5,5);
JPanel inpane2=new JPanel();
inpane2.setLayout(inlayout);
inpane2.add(b1);
inpane2.add(b2);
inpane2.add(b3);
inpane2.add(b10);
inpane2.add(b18);
inpane2.add(b4);
inpane2.add(b5);
inpane2.add(b6);
inpane2.add(b11);
inpane2.add(b16);