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.setEditablefalse;
display.setHorizontalAlignmentJTextFieldRIGHT;
JPanel panel new JPanel;
panel.setLayoutnew GridLayout;
String buttons
C
;
for String text : buttons
JButton button new JButtontext;
button.addActionListenerthis;
panel.addbutton;
setLayoutnew BorderLayout;
adddisplay BorderLayout.NORTH;
addpanel BorderLayout.CENTER;
setTitleCalculator;
setSize;
setDefaultCloseOperationJFrameEXITONCLOSE;
setVisibletrue;
@Override
public void actionPerformedActionEvent e
String command egetActionCommand;
if commandcharAtC
currentInput.setLength;
display.setText;
else if commandcharAt
try
double result evaluatecurrentInputtoString;
display.setTextDoubletoStringresult;
currentInput.setLength;
catch Exception ex
display.setTextError;
currentInput.setLength;
else
currentInput.appendcommand;
display.setTextcurrentInputtoString;
private double evaluateString expression
Simple evaluation logic not robust for complex expressions
return new ScriptEngineManagergetEngineByNameJavaScriptevalexpression;
public static void mainString args
new Calculator;
using this java code:
Calculate Halstead Metrics for the program and explain it means.
Calculate McCabe Cyclomatic Complexity and explain it means.
Calculate the HenryKafura metric and explain what it means.
Calculate the Card and Class metric and explain what it means.
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
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
