Skip to content

Commit

Permalink
Refactored SecondOperator to SecondOperand
Browse files Browse the repository at this point in the history
  • Loading branch information
M4444 committed Nov 5, 2017
1 parent 32b2f9f commit 989d0c9
Showing 1 changed file with 14 additions and 14 deletions.
28 changes: 14 additions & 14 deletions src/c41c/Window.java
Original file line number Diff line number Diff line change
Expand Up @@ -1141,11 +1141,11 @@ private void BUTTON_AddDigitActionPerformed(java.awt.event.ActionEvent evt) {//G
Value = Value.add(new BigInteger(button.getName(), Base));
} else {
if (!SecondOperandEntered) {
SecondOperator = BigInteger.ZERO;
SecondOperand = BigInteger.ZERO;
SecondOperandEntered = true;
}
SecondOperator = SecondOperator.multiply(new BigInteger(Integer.toString(Base)));
SecondOperator = SecondOperator.add(new BigInteger(button.getName(), Base));
SecondOperand = SecondOperand.multiply(new BigInteger(Integer.toString(Base)));
SecondOperand = SecondOperand.add(new BigInteger(button.getName(), Base));
}

refreshTextArea();
Expand All @@ -1160,7 +1160,7 @@ private void BUTTON_RemoveDigitActionPerformed(java.awt.event.ActionEvent evt) {
if(!OperationUnderway)
Value = Value.divide(new BigInteger(Integer.toString(Base)));
else
SecondOperator = SecondOperator.divide(new BigInteger(Integer.toString(Base)));
SecondOperand = SecondOperand.divide(new BigInteger(Integer.toString(Base)));

refreshTextArea();
}//GEN-LAST:event_BUTTON_RemoveDigitActionPerformed
Expand All @@ -1169,7 +1169,7 @@ private void BUTTON_ClearCurrentActionPerformed(java.awt.event.ActionEvent evt)
if(!OperationUnderway)
Value = BigInteger.ZERO;
else
SecondOperator = BigInteger.ZERO;
SecondOperand = BigInteger.ZERO;
DivisionByZero = false;

refreshTextArea();
Expand All @@ -1182,7 +1182,7 @@ private void BUTTON_OperationActionPerformed(java.awt.event.ActionEvent evt) {//
performOperation();
JButton button = (JButton) evt.getSource();
Operation = button.getName();
SecondOperator = Value;
SecondOperand = Value;
OperationUnderway = true;

System.out.println(Operation);
Expand All @@ -1200,7 +1200,7 @@ private void bitSwitch(JLabel bitLabel) {
if(!OperationUnderway)
Value = Value.flipBit(bitPos);
else
SecondOperator = SecondOperator.flipBit(bitPos);
SecondOperand = SecondOperand.flipBit(bitPos);
bitLabel.setText(bit.equals("1") ? "0" : "1");

//setSize(new java.awt.Dimension(386, 396));
Expand Down Expand Up @@ -1344,22 +1344,22 @@ private void performOperation() {
OperationUnderway = false;
switch(Operation) {
case "+":
Value = Value.add(SecondOperator);
Value = Value.add(SecondOperand);
break;
case "-":
Value = Value.subtract(SecondOperator);
Value = Value.subtract(SecondOperand);
break;
case "*":
Value = Value.multiply(SecondOperator);
Value = Value.multiply(SecondOperand);
break;
case "/":
if(SecondOperator.equals(BigInteger.ZERO)) {
if(SecondOperand.equals(BigInteger.ZERO)) {
TextPane.setText("Division by zero is undefined.");
DivisionByZero = true;
Operation = "";
return;
}
Value = Value.divide(SecondOperator);
Value = Value.divide(SecondOperand);
break;
default:
return;
Expand All @@ -1370,7 +1370,7 @@ private void performOperation() {
private void refreshTextArea() {
String out = Value.toString(Base);
if (OperationUnderway)
out += '\n' + Operation + '\n' + SecondOperator.toString(Base);
out += '\n' + Operation + '\n' + SecondOperand.toString(Base);
TextPane.setText(out);
}

Expand Down Expand Up @@ -1493,7 +1493,7 @@ public void run() {
// End of variables declaration//GEN-END:variables
// My variables
private BigInteger Value = BigInteger.ZERO;
private BigInteger SecondOperator = BigInteger.ZERO;
private BigInteger SecondOperand = BigInteger.ZERO;
private int Base = 10;
private boolean SecondOperandEntered = false;
private boolean OperationUnderway = false;
Expand Down

0 comments on commit 989d0c9

Please sign in to comment.