Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/399.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 接口类和对象类正在编译符号错误_Java_Object_Interface - Fatal编程技术网

Java 接口类和对象类正在编译符号错误

Java 接口类和对象类正在编译符号错误,java,object,interface,Java,Object,Interface,我是JAVA的初学者,我正在尝试使用接口类和对象类编写一个免费计算器,但它不断编译,错误是“找不到符号”。我尝试了所有方法来修复它,但它只是不断声明符号。请帮忙 public class GratuityCalculator extends JFrame { /* declarations */ // color objects Color black = new Color(0, 0, 0); Color white = new Color(255, 255, 255);

我是JAVA的初学者,我正在尝试使用接口类和对象类编写一个免费计算器,但它不断编译,错误是“找不到符号”。我尝试了所有方法来修复它,但它只是不断声明符号。请帮忙

  public class GratuityCalculator extends JFrame
{
 /* declarations */

// color objects
   Color black = new Color(0, 0, 0);
   Color white = new Color(255, 255, 255);
   Color light_gray = new Color(192, 192, 192);

 // components
   JLabel billAmountJLabel;
   JTextField billAmountJTextField;

   JLabel gratuityAmountJLabel;
   JTextField gratuityAmountJTextField;

   JButton enterJButton;
   JButton clearJButton;
   JButton closeJButton;

  // variables
  double billAmount;
  double gratuityAmount;
  double firstNumber;
  final double GRATUITY_RATE = .15;


// objects
  CalculateDoubles calculateDoubles; // object class declaration

  public GratuityCalculator()
  {
        createUserInterface();
  }

  public void createUserInterface()
  {
    Container contentPane = getContentPane();
    contentPane.setBackground(Color.white);
    contentPane.setLayout(null);

    /* initialize components */

    billAmountJLabel = new JLabel();
    billAmountJLabel.setBounds(50, 50, 120, 20);
    billAmountJLabel.setFont(new Font("Default", Font.PLAIN, 12));
    billAmountJLabel.setText("Enter First Number:");
    billAmountJLabel.setForeground(black);
    billAmountJLabel.setHorizontalAlignment(JLabel.LEFT);
    contentPane.add(billAmountJLabel);

    billAmountJTextField = new JTextField();
    billAmountJTextField.setBounds(225, 50, 50, 20);
    billAmountJTextField.setFont(new Font("Default", Font.PLAIN, 12));
    billAmountJTextField.setHorizontalAlignment(JTextField.CENTER);
    billAmountJTextField.setForeground(black);
    billAmountJTextField.setBackground(white);
    billAmountJTextField.setEditable(true);
    contentPane.add(billAmountJTextField);

    gratuityAmountJLabel = new JLabel();
    gratuityAmountJLabel.setBounds(50, 80, 150, 20);
    gratuityAmountJLabel.setFont(new Font("Default", Font.PLAIN, 12));
    gratuityAmountJLabel.setText("Enter Second Number:");
    gratuityAmountJLabel.setForeground(black);
    gratuityAmountJLabel.setHorizontalAlignment(JLabel.LEFT);
    contentPane.add(gratuityAmountJLabel);

    gratuityAmountJTextField = new JTextField();
    gratuityAmountJTextField.setBounds(225, 80, 50, 20);
    gratuityAmountJTextField.setFont(new Font("Default", Font.PLAIN, 12));
    gratuityAmountJTextField.setHorizontalAlignment(JTextField.CENTER);
    gratuityAmountJTextField.setForeground(black);
    gratuityAmountJTextField.setBackground(white);
    gratuityAmountJTextField.setEditable(false);
    contentPane.add(gratuityAmountJTextField);

    enterJButton = new JButton();
    enterJButton.setBounds(20, 300, 100, 20);
    enterJButton.setFont(new Font("Default", Font.PLAIN, 12));
    enterJButton.setText("Enter");
    enterJButton.setForeground(black);
    enterJButton.setBackground(white);
    contentPane.add(enterJButton);
    enterJButton.addActionListener(

        new ActionListener()
        {
            public void actionPerformed(ActionEvent event)
            {
                enterJButtonActionPerformed(event);
            }
        }
    );

    clearJButton = new JButton();
    clearJButton.setBounds(130, 300, 100, 20);
    clearJButton.setFont(new Font("Default", Font.PLAIN, 12));
    clearJButton.setText("Clear");
    clearJButton.setForeground(black);
    clearJButton.setBackground(white);
    contentPane.add(clearJButton);
    clearJButton.addActionListener(

        new ActionListener()
        {
            public void actionPerformed(ActionEvent event)
            {
                clearJButtonActionPerformed(event);
            }
        }
    );

    closeJButton = new JButton();
    closeJButton.setBounds(240, 300, 100, 20);
    closeJButton.setFont(new Font("Default", Font.PLAIN, 12));
    closeJButton.setText("Close");
    closeJButton.setForeground(black);
    closeJButton.setBackground(white);
    contentPane.add(closeJButton);
    closeJButton.addActionListener(

        new ActionListener()
        {
            public void actionPerformed(ActionEvent event)
            {
                closeJButtonActionPerformed(event);
            }
        }
    );

    setTitle("Gratuity Calculator");
    setSize(400, 400);
    setVisible(true);
}

// main method
public static void main(String[] args)
{
        GratuityCalculator application = new GratuityCalculator();
        application.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}

public void enterJButtonActionPerformed(ActionEvent event)
{
    getDoubleOne();
}

public void getDoubleOne()
{
    try
    {
        billAmount = Double.parseDouble(billAmountJTextField.getText());
        getGratuityAmount();
    }
    catch(NumberFormatException exception)
    {
            JOptionPane.showMessageDialog(this,
            "Please enter bill amount!",
            "Number Format Error", JOptionPane.ERROR_MESSAGE );
            billAmountJTextField.setText("");
            billAmountJTextField.requestFocusInWindow();
    }
}

public void getGratuityAmount()
{
    /* initalize the object class */
    calculateDouble = new calculateDouble();
    calculateDoubles.setFirstValue(billAmount);
    displayGratuityAmount();

}

public void displayGratuityAmount()
{
    /* call object class method */
    gratuityAmountNumber = calculateDouble.getGratuityAmountNumber();

    gratuityAmountJTextField.setText("" + gratuityAmountNumber);
}

public void clearJButtonActionPerformed(ActionEvent event)
{
    billAmountJTextField.setText("");
    billAmountJTextField.requestFocusInWindow();
    gratuityAmountTextField.setText("");

}

public void closeJButtonActionPerformed(ActionEvent event)
{
    GratuityCalculator.this.dispose();
}

} 

class CalculateDoubles
{
/* object class variables */
double billAmount;
double gratuityAmount;
double firstNumber;
final double GRATUITY_RATE = .15;


/* first value is received by object class */
public CalculateDoubles(double billAmount)
{
    firstNumber = billAmount;
}

/* return method sends sum of values to interface class */
public double getGratuityAmount()
{
    return firstNumber * GRATUITY_RATE;
}
}有些错误

将firstNumber添加到类CalculatedDubles:

class CalculateDoubles  {/* object class non-constructor */

    /* object class variables */
    double billAmount;
    double gratuityAmount;
    double firstNumber;
    ...
定义酬金率:

double GRATUITY_RATE = 0.15;

我看到一些其他错误,似乎你没有发布所有的课程内容。

第一个编号的定义在哪里?谢谢。我做了你建议的更改,但它仍然指出了相同的错误。似乎找不到用于计算的符号。您可以编辑问题并放置所有代码。这将有助于更好的理解。我已经编辑了这个问题,并将整个代码都放进去了。我希望有人能解决这个问题。它显示了六个错误-都是“找不到符号”谢谢!