[SOLVED] CSC20 Lab 9

30.00 $

Category:
Click Category Button to View Your Next Assignment | Homework

You will receive the following solution file(s) instantly after successful payment:

zip file icon lab09-6ig8a8.zip (327.7 KB)
Assignment Instructions Updated Recently? Submit Below and we will provide new Solution!
Submit New Instructions
🔒 Securely Powered by:
Secure Checkout
5/5 - (2 votes)

The programming assignment:

In this assignment you are to add functionality to the calculator created in lab 08. You don’t have to make the calculator a full function calculator. You only need to make buttons 0 ~ 9, +, -, *, / and = work.

Some programming hints:

1. Implement an action listener.

public void actionPerformed(ActionEvent e) { for (int i=0; i<=9; ++i) {

if (e.getSource() == digitButton[i]) { if (newNumber) {

display digit in tf;

newNUmber = false; } else append digit in tf;

return; }

}
if (e.getSource() == addButton ){

opnd1 = Double.parseDouble(tf.getText()); newNumber = true;
operator = ‘+’; return;

}
if (e.getSource() == eqButton) {

} }

opnd2 = Double.parseDouble(tf.getText()); switch (operator) {

case ‘/’: res = opnd1 / opnd2; break; case ‘*’: res = opnd1 * opnd2; break; case ‘-‘: res = opnd1 – opnd2; break; case ‘+’: res = opnd1 + opnd2; break;

}
display(“”+res); newNumber = true; return;

2. Register the action listener with all buttons.

  • lab09-6ig8a8.zip