2014-11-16 1 views
1

Я начинаю здесь, в JAVA, и я пытаюсь запрограммировать калькулятор Gratuity с использованием как класса интерфейса, так и класса объекта, но он продолжает компилировать с ошибками, говоря «не может найти символ» .I попытался все исправить, но он просто продолжает указывать символ. Пожалуйста помоги.Класс интерфейса и класс объектов компилируют ошибки символов

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; 
} 

}

+0

Где находится 'firstNumber'? –

ответ

0

Некоторые ошибки ...

Добавить firstNumber классовым CalculateDoubles:

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

    /* object class variables */ 
    double billAmount; 
    double gratuityAmount; 
    double firstNumber; 
    ... 

Определение GRATUITY_RATE:

double GRATUITY_RATE = 0.15; 

Я вижу некоторые другие ошибки, кажется y ou не разместил все содержимое класса.

+0

Спасибо. Я внес изменения, которые вы предложили, но он все же указал те же ошибки. Кажется, он не находит символ для вычисления. – user4059399

+0

Вы можете отредактировать вопрос и поместить весь код. Это будет работать для лучшего понимания. – jordiburgos

+0

Я редактировал вопрос и вставлял весь код. Надеюсь, кто-то может решить проблему. Он показывает шесть ошибок - все из которых «не могут найти символ» Спасибо! – user4059399

Смежные вопросы