posted 12 years ago

GUI, Recursion and Exception Handling

Problem Statement

A simple calculator has function keys for adding, subtracting, multiplying and dividing two numbers. It also has a function key for calculating the factorial of an integer.

Requirements: (10 marks)

Using the Keypad class, write a program to simulate a simple calculator.

(1)Add 6 more buttons for add, subtract, multiply, divide, equal and factorial functionalities to the keypad GUI.

(2)Implement the factorial function. The factorial must be applied to an integer.

(3)Throw an exception if the number entered has the wrong format. For example, the number 25.5.3 has the wrong format.

The GUI of your program should look like this:

Bonus: (5 marks)

(1) Implement the calculator functions for adding, subtracting, multiplying and dividing.

(2) Throw an exception if the user attempts to divide a number by zero.

Problem Statement

A simple calculator has function keys for adding, subtracting, multiplying and dividing two numbers. It also has a function key for calculating the factorial of an integer.

Requirements: (10 marks)

Using the Keypad class, write a program to simulate a simple calculator.

(1)Add 6 more buttons for add, subtract, multiply, divide, equal and factorial functionalities to the keypad GUI.

(2)Implement the factorial function. The factorial must be applied to an integer.

(3)Throw an exception if the number entered has the wrong format. For example, the number 25.5.3 has the wrong format.

The GUI of your program should look like this:

Bonus: (5 marks)

(1) Implement the calculator functions for adding, subtracting, multiplying and dividing.

(2) Throw an exception if the user attempts to divide a number by zero.