//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 类的函数都是这样提示错的 */