[Solved] CSc20: Programming Concepts And Methodology II Lab 09

$25

File Name: CSc20:_Programming_Concepts_And_Methodology_II_Lab_09.zip
File Size: 499.26 KB

SKU: [Solved] CSc20: Programming Concepts And Methodology II Lab 09 Category: Tag:
5/5 - (1 vote)

Objective: This assignment will give you practice with action event handling.

The programming assignment:

In this assignment you are to add functionality to the calculator created in lab 08. You dont 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;

}

}

  1. Register the action listener with all buttons.

Reviews

There are no reviews yet.

Only logged in customers who have purchased this product may leave a review.

Shopping Cart
[Solved] CSc20: Programming Concepts And Methodology II Lab 09
$25