Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

can anyone help me fix my java programming errors? package math; import java.awt

ID: 3647242 • Letter: C

Question

can anyone help me fix my java programming errors?

package math;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JOptionPane;
import java.awt.*;
import javax.swing.JFrame;

/**
*
* @author Owner
*/
public class Math {

/**
* @param args the command line arguments
*/
public static void main(String[] args) {
private JButton buttons[];
private String operation[] = {"Addition [+]","Subtraction [-]","Multiplication [x]","Division [/]"};


public Math() {


super("Math using JOptionPane");


setSize(320,120);


setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);


buttons = new JButton[4];


Container pane = getContentPane();
setContentPane(pane);


GridLayout grid = new GridLayout(2,2);
pane.setLayout(grid);


for(int count=0; count<buttons.length; count++) {
buttons[count] = new JButton(operation[count]);
pane.add(buttons[count]);
}


buttons[0].addActionListener(
new ActionListener() {


public void actionPerformed(ActionEvent event) {
try {


String input1, input2;
int num1, num2, result;


input1 = JOptionPane.showInputDialog("Please Input First Number: ");
input2 = JOptionPane.showInputDialog("Please Input Second Number: ");

num1 = Integer.parseInt(input1);
num2 = Integer.parseInt(input2);


result = num1 + num2;


JOptionPane.showMessageDialog(null,result,"Result:",JOptionPane.INFORMATION_MESSAGE);
} catch (NumberFormatException e){
JOptionPane.showMessageDialog(null, "Please Input a Integer","Error",JOptionPane.ERROR_MESSAGE);
}
}
}
);


buttons[1].addActionListener(
new ActionListener() {


public void actionPerformed(ActionEvent event) {
try {
String input1, input2;
int num1, num2, result;

input1 = JOptionPane.showInputDialog("Please Input First Number: ");
input2 = JOptionPane.showInputDialog("Please Input Second Number: ");

num1 = Integer.parseInt(input1);
num2 = Integer.parseInt(input2);

result = num1 - num2;

JOptionPane.showMessageDialog(null,result,"Result:",JOptionPane.INFORMATION_MESSAGE);
} catch (NumberFormatException e){
JOptionPane.showMessageDialog(null, "Please Input a Integer","Error",JOptionPane.ERROR_MESSAGE);

}
}
}
);

//Implemeting Even-Listener on JButton button[2] which is multiplication
buttons[2].addActionListener(
new ActionListener() {

//Handle JButton event if it is clicked
public void actionPerformed(ActionEvent event) {
try {
String input1, input2;
int num1, num2, result;

input1 = JOptionPane.showInputDialog("Please Input First Number: ");
input2 = JOptionPane.showInputDialog("Please Input Second Number: ");

num1 = Integer.parseInt(input1);
num2 = Integer.parseInt(input2);

result = num1 * num2;

JOptionPane.showMessageDialog(null,result,"Result:",JOptionPane.INFORMATION_MESSAGE);
} catch (NumberFormatException e){
JOptionPane.showMessageDialog(null, "Please Input a Integer","Error",JOptionPane.ERROR_MESSAGE);

}
}
}
);

//Implemeting Even-Listener on JButton button[3] which is division
buttons[3].addActionListener(
new ActionListener() {

//Handle JButton event if it is clicked
public void actionPerformed(ActionEvent event) {
try {
String input1, input2;
int num1, num2, result;

input1 = JOptionPane.showInputDialog("Please Input First Number: ");
input2 = JOptionPane.showInputDialog("Please Input Second Number: ");

num1 = Integer.parseInt(input1);
num2 = Integer.parseInt(input2);

result = num1 / num2;

JOptionPane.showMessageDialog(null,result,"Result:",JOptionPane.INFORMATION_MESSAGE);
} catch (NumberFormatException e){
JOptionPane.showMessageDialog(null, "Please Input a Integer","Error",JOptionPane.ERROR_MESSAGE);

}
}
}
);

buttons[0].setMnemonic('A');
buttons[1].setMnemonic('S');
buttons[2].setMnemonic('M');
buttons[3].setMnemonic('D');

/**Set all the Components Visible.
* If it is set to "false", the components in the container will not be visible.
*/
setVisible(true);
setResizable(false); //Fix window height and width
}


public static void main (String[] args) {
Math pjtf = new Math();
}
}

Explanation / Answer

Please post the error that you are found in this program so we will b able to solv it

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Chat Now And Get Quote