当前位置: 代码迷 >> Java相关 >> [求助]请大家帮帮忙。。。
  详细解决方案

[求助]请大家帮帮忙。。。

热度:282   发布时间:2005-10-04 12:34:00.0
[求助]请大家帮帮忙。。。

//java 初学者 请大家帮帮忙。。。 public class Caculator {

private int number1,number2,number3,number4,factorialNumber; public int setNumber1(int number){return number1 = number;} public int setNumber2(int number){return number2 = number;} public int setNumber3(int number){return number3 = number;} public int setNumber4(int number){return number4 = number;} public int setFactorialNumber(int number){return factorialNumber = number;} public int getNumber1(){return number1 ;} public int getNumber2(){return number2 ;} public int getNumber3(){return number3 ;} public int getNumber4(){return number4 ;} public int getFactorialNumber(){ return factorialNumber ;} public int plus(){ return number1 + number2;} public int multiply(){ return number3 * number4;} public int factorial(){ int result1=1; for(int i=1;i <=factorialNumber ;i++) result1*=i; return result1; }

} import javax.swing.*;

public class Test301{ public static void main(String[] args){ String firstNumber; String secondNumber; String thirdNumber; String fourthNumber; String factorialNumber; int number1; int number2; int number3; int number4; int factorialNum; int result1; int result2; int result3; firstNumber = JOptionPane.showInputDialog("Enter first plus number:"); secondNumber = JOptionPane.showInputDialog("Enter second plus number:"); thirdNumber = JOptionPane.showInputDialog("Enter first multiply number:"); fourthNumber = JOptionPane.showInputDialog("Enter second multiply number:"); factorialNumber = JOptionPane.showInputDialog("Enter factorial number:");

number1 = Integer.parseInt(firstNumber); number2 = Integer.parseInt(secondNumber); number3 = Integer.parseInt(thirdNumber); number4 = Integer.parseInt(fourthNumber); factorialNum = Integer.parseInt(factorialNumber);

Caculator.setNumber1(number1); Caculator.setNumber2(number2); Caculator.setNumber3(number3); Caculator.setNumber4(number4); Caculator.setFactorialNumber(factorialNum); result1 = Caculator.plus(); result2 = Caculator.multiply(); result3 = Caculator.factorial();

JTextArea outputTextArea =new JTextArea(); outputTextArea.setText("功能\t result\n"); outputTextArea.append("plus\t" + result1 + "\n" +"multiply\t" + result2 + "\n"+ "factorial" + result3 );

JOptionPane.showMessageDialog(null,outputTextArea, "计算器" , JOptionPane.INFORMATION_MESSAGE); System.exit(0); } } //编译出错 /* non-static method setNumber1(int) cannot be referenced from a static context Caculator 类的函数都是这样提示错的 */

搜索更多相关的解决方案: class  java  private  public  number  

----------------解决方案--------------------------------------------------------
研究半天,搞不定啊
----------------解决方案--------------------------------------------------------
把你那些Caculator中的Method设成static
----------------解决方案--------------------------------------------------------
还是不行 ....
----------------解决方案--------------------------------------------------------
哪位行家 帮帮 忙 。。。。
----------------解决方案--------------------------------------------------------
import javax.swing.*;

class Caculator
{
  private int number1,number2,number3,number4,factorialNumber;
  public void setNumber1(int number)
  {
    number1 = number;
  }
  public void setNumber2(int number)
  {
    number2 = number;
  }
  public void setNumber3(int number)
  {
    number3 = number;
  }
  public void setNumber4(int number)
  {
    number4 = number;
  }
  public void setFactorialNumber(int number)
  {
    factorialNumber = number;
  }
  public int getNumber1()
  {
    return number1 ;
  }
  public int getNumber2()
  {
    return number2 ;
  }
  public int getNumber3()
  {
    return number3 ;
  }
  public int getNumber4()
  {
    return number4 ;
  }
  public int getFactorialNumber()
  {
    return factorialNumber ;
  }
  public int plus()
  {
    return number1 + number2;
  }
  public int multiply()
  {
    return number3 * number4;
  }
  public int factorial()
  {  
    int result1=1;
    for(int i=1; i&lt;=factorialNumber; i++)   
      result1 *= i;
    return result1;   
  }

}


public class Test301
{
  public static void main(String[] args)
  {
    Caculator c = new Caculator();  
    String firstNumber;
    String secondNumber;
    String thirdNumber;
    String fourthNumber;
    String factorialNumber;
   
    int number1;
    int number2;
    int number3;
    int number4;
    int factorialNum;
    int result1;
    int result2;
    int result3;
   
    firstNumber = JOptionPane.showInputDialog("Enter first plus number:");
    secondNumber = JOptionPane.showInputDialog("Enter second plus number:");
    thirdNumber = JOptionPane.showInputDialog("Enter first multiply number:");
    fourthNumber = JOptionPane.showInputDialog("Enter second multiply number:");
    factorialNumber = JOptionPane.showInputDialog("Enter factorial number:");

    number1 = Integer.parseInt(firstNumber);
    number2 = Integer.parseInt(secondNumber);
    number3 = Integer.parseInt(thirdNumber);
    number4 = Integer.parseInt(fourthNumber);
    factorialNum = Integer.parseInt(factorialNumber);

    c.setNumber1(number1);
    c.setNumber2(number2);
    c.setNumber3(number3);
    c.setNumber4(number4);
    c.setFactorialNumber(factorialNum);
    result1 = c.plus();
    result2 = c.multiply();
    result3 = c.factorial();

    JTextArea outputTextArea = new JTextArea();
   
    outputTextArea.setText("功能\t result\n");
    outputTextArea.append("plus\t " + result1 +
                         "\n" +"multiply\t " +
                         result2 + "\n"+ "factorial\t " +  result3 );

    JOptionPane.showMessageDialog(null,outputTextArea,"计算器",                              

   JOptionPane.INFORMATION_MESSAGE);
    System.exit(0);   
  }
}
----------------解决方案--------------------------------------------------------
不错    写的不短    呵呵
这样就对了吗       多发点实例  多好啊   我们共同学习呵呵
----------------解决方案--------------------------------------------------------
谢谢6楼楼主 。。。
----------------解决方案--------------------------------------------------------
楼主    你编的这个是个什么东西啊????
我执行出来了  但不知道是什么意思啊?????
----------------解决方案--------------------------------------------------------
是两个数相加,想乘,,还有一个是阶乘。。
----------------解决方案--------------------------------------------------------
  相关解决方案