Question: This is my Java Code for the arithmetic calculator : import javax.swing. * ; import java.awt. * ; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; public class Calculator

This is my Java Code for the arithmetic calculator :
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class Calculator extends JFrame implements ActionListener {
private JTextField display;
private StringBuilder currentInput;
public Calculator(){
currentInput = new StringBuilder();
display = new JTextField();
display.setEditable(false);
display.setHorizontalAlignment(JTextField.RIGHT);
JPanel panel = new JPanel();
panel.setLayout(new GridLayout(4,4));
String[] buttons ={
"7","8","9","/",
"4","5","6","*",
"1","2","3","-",
"0","C","=","+"
};
for (String text : buttons){
JButton button = new JButton(text);
button.addActionListener(this);
panel.add(button);
}
setLayout(new BorderLayout());
add(display, BorderLayout.NORTH);
add(panel, BorderLayout.CENTER);
setTitle("Calculator");
setSize(300,400);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setVisible(true);
}
@Override
public void actionPerformed(ActionEvent e){
String command = e.getActionCommand();
if (command.charAt(0)=='C'){
currentInput.setLength(0);
display.setText("");
} else if (command.charAt(0)=='='){
try {
double result = evaluate(currentInput.toString());
display.setText(Double.toString(result));
currentInput.setLength(0);
} catch (Exception ex){
display.setText("Error");
currentInput.setLength(0);
}
} else {
currentInput.append(command);
display.setText(currentInput.toString());
}
}
private double evaluate(String expression){
// Simple evaluation logic (not robust for complex expressions)
return new ScriptEngineManager().getEngineByName("JavaScript").eval(expression);
}
public static void main(String[] args){
new Calculator();
}
}
----->using this java code:
1.Calculate Halstead Metrics for the program and explain it means.
2.Calculate McCabe Cyclomatic Complexity and explain it means.
3.Calculate the Henry-Kafura metric and explain what it means.
4.Calculate the Card and Class metric and explain what it means.
5.Calculate the Chidamber and Kemerer metric and explain what it means

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!