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

Please help with what I have.Code and outcome picture below. ///////////////////

ID: 3818123 • Letter: P

Question

Please help with what I have.Code and outcome picture below.

//////////////////////////////////////////////////////////////////////////////////////////////////

Write a binary calculator with a GUI interface similar to that shown in the attached screen shot. Use BoxLayout or GridBagLayout. All values are displayed in binary. See Integer.parseInt() and Integer.toString().

The calculator has four registers: X, Y, S, and T. It also has nine control buttons that behave as follows:

Clear - the contents of the X register is replaced with the single character "0", and the firstEntry flag is set

1 - if firstEntry, a "1" replaces the X register contents and the flag is cleared, else the X register contents with a right-appended "1" replaces the X register contents

0 -  if firstEntry, a "0" replaces the X register contents and the flag is cleared, else the X register contents with a right-appended "0" replaces the X register contents

Enter - the registers roll-up, and the firstEntry flag is set

x+y - the sum of the X and Y registers replaces the X register and the registers roll-down; the firstEntry flag is set

x-y - the Y register is subtracted from the X register, the result replaces the X register, and the registers roll-down; the firstEntry flag is set

x*y - the product of the X and Y registers replaces the X register and the registers roll-down; the firstEntry flag is set

x/y - the Y register is divided into the X register, the integer result replaces the X register, and the registers roll-down; the firstEntry flag is set

Swap - the contents of the X and Y registers are exchanged

Register Roll-up

the T register goes off-screen, the S register replaces the T register, the Y register replaces the S register, the X register replaces the Y register; the X register is unchanged

Register Roll-down

the S register replaces the Y register, the T register replaces the S register, the T register is set from off-screen

Off-screen

An array list of Strings is used the save values that go off-screen from the T register. Values are added to the end and removed from the end of the array list.

Clear Calculator 1 o T Swap 0 S x y 0 Y 0 X Enter

Explanation / Answer

import javax.swing.*; import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.util.LinkedList; import java.util.Stack; class AssignCalcBoxLayout implements Runnable { static final int width = 340; static final int height = 200; static final String title = "Calculator"; static final String[] buttonLbls = {"Swap", "x / y", "x * y", "x - y", "x + y", "Enter"}; // Setting button titles static final String[] buttonDigits = {"Clear", "1", "0"}; // Setting Button titles static final String[] regLabels = {"T", "S", "Y", "X"}; // Specifying the label names JFrame application; JTextField[] regs = new JTextField[4]; /* Stack that will hold the off screen strings. It is used to support Last in First Out Support */ Stack offScreen = new Stack(); // Flag to know if it is first entry or not boolean firstEntry = true; /* Created Button type utils to make code clean and easily readable */ enum ButtonType{ Swap, Add, Sub, Mul, Div, Clear, One, Zero, Enter } JPanel ops() { JPanel panel = new JPanel(); int ix; panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS)); for (ix = 0; ix