# ⌛ JavaFX calculator¶

Place the main class of your implementation into the file Round12/calc/src/main/java/fi/tuni/prog3/calc/Calculator.java. As implied by the directory structure, the implementation must belong to the package fi.tuni.prog3.calc.

This task concerns implementing a simple calculator with the JavaFX GUI library. The calculator must have the following parts:

• Input fields for the first and second operand.

• The input fields must be JavaFX TextField elements that have id’s “fieldOp1” and “fieldOp2”. Set the id’s by using the JavaFX element member function setId.

• The input fields must be preceded by the label texts “First operand:” and “Second operand:”. These must be implemented either as JavaFX Text or Label elements and have id’s “labelOp1” and “labelOp2”.

• Buttons for the four basic arithmetic operations: addition, subtraction, multiplication and division.

• These must be JavaFX Button elements and have id’s “btnAdd”, “btnSub”, “btnMul” and “btnDiv”.

• The buttons must have texts “Add”, “Subtract”, “Multiply” and “Divide”.

• A result field.

• The result field must be a JavaFX Label element that has the id “fieldRes” and whose background is white (see e.g. the documentation of the member function setBackground; you may use the color Color.WHITE). The result field is initially empty (contains “”).

• The result field must be preceded by the label text “Result:” implemented either as JavaFX Text or Label element whose id is “labelRes”.

You have to specify the above-mentioned element id’s in order to allow the grader to use simple unit tests in testing your GUI implementation.

Below is an example image of a calculator GUI. Note that this is an example: you do not have to implement an identical GUI. Just make sure that your GUI contains the required parts in some form and layout.

If a user sets values into the operator input fields and presses one of the buttons, the result of applying the the corresponding operation to the two operands should appear in the result field. The operation will not affect the contents of the input fields; they will hold their existing values until the user explicitly modifies them. The program must use double variables for handling the input values and the result. Below are examples of all four operations:

The main class of your implementation must be fi.tuni.prog3.calc.Calculator (that is, the class Calculator belonging to the package fi.tuni.prog3.calc). By a “main class” we mean the class that contains your implementation of the function start that initializes the JavaFX GUI. Your implementation can contain also other source files as long as also they are located in the directory src/main/java/fi/tuni/prog3/calc.