Java

JavaFx Money Counter Calculator App

In this tutorials will teach JavaFx Money Counter Calculator App step by step.if you enter the salary on the textfield it will be calculated how many coins ands notes.

you have to create two packages controller and view.

MoneyFormController
package controller;

import javafx.event.ActionEvent;
import javafx.scene.control.Alert;
import javafx.scene.control.TextField;

public class MoneyController {
    public TextField txtSalary;

    public void btnCal(ActionEvent actionEvent) {

        int salary = Integer.parseInt(txtSalary.getText());
        int notes,coins;

        notes = salary / 5000;
        salary = salary % 5000;
        System.out.println("5000 notes : " + notes);

        int fivethusand = notes;
        notes = salary / 1000;
        salary = salary % 1000;
        System.out.println("1000 notes : " + notes);

        int thusand = notes;

        notes = salary / 500;
        salary = salary % 500;
        System.out.println("500 notes : " + notes);

        int fivehundred = notes;

        notes = salary / 100;
        salary = salary % 100;
        System.out.println("100 notes : " + notes);
        int hundred = notes;


        notes = salary / 50;
        salary = salary % 50;
        System.out.println("50 notes : " + notes);
        int fifty = notes;

        notes = salary / 20;
        salary = salary % 20;
        System.out.println("20 notes : " + notes);
        int twenty = notes;

        coins = salary / 10;
        salary = salary % 10;
        System.out.println("10 coins : " + coins);
        int ten = coins;

        coins = salary / 5;
        salary = salary % 5;
        System.out.println("5 coins : " + coins);
        int five = coins;

        coins = salary / 2;
        salary = salary % 2;
        System.out.println("2 coins : " + coins);
        int two = coins;

        System.out.println("1 coins : " + salary);
        int one = salary;


        Alert alert = new Alert(Alert.AlertType.INFORMATION);
        alert.setTitle("Notes an Coin");
        alert.setHeaderText("Results:");
        alert.setContentText(
                "5000 notes " + fivethusand+ "\n" +
                        "1000 notes " + thusand+ "\n" +
                        "500 notes " + fivehundred+ "\n" +
                        "100 notes " + hundred+ "\n" +
                        "50 notes " + fifty+ "\n" +
                        "20 notes " + twenty+ "\n" +
                        "10 coins " + ten+ "\n" +
                        "5 coins " + five+ "\n" +
                        "2 coins " + two+ "\n" +
                        "1 coins " + one+ "\n"
        );

        alert.showAndWait();

    }
}

AppInilizer

import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;

import java.io.IOException;

public class AppIniliozer extends Application {

    public static void main(String[] args) {
        launch(args);
    }

    @Override
    public void start(Stage primaryStage) throws IOException {

        Parent parent = FXMLLoader.load(this.getClass().getResource("view/MoneyForm.fxml"));
        Scene scene = new Scene(parent);
        primaryStage.setScene(scene);
        primaryStage.setTitle("MoneyForm");
        primaryStage.centerOnScreen();
        primaryStage.show();

    }
}

MoneyForm.fxml

<?xml version="1.0" encoding="UTF-8"?>

<?import javafx.scene.control.Button?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.TextField?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.text.Font?>


<AnchorPane prefHeight="285.0" prefWidth="481.0" xmlns="http://javafx.com/javafx/19" xmlns:fx="http://javafx.com/fxml/1" fx:controller="controller.MoneyController">
   <children>
      <Label layoutX="62.0" layoutY="47.0" text="Notes &amp; Coins Calculator">
         <font>
            <Font name="System Bold" size="29.0" />
         </font>
      </Label>
      <Label layoutX="62.0" layoutY="137.0" text="Salary" textFill="#e10909">
         <font>
            <Font name="System Bold" size="21.0" />
         </font>
      </Label>
      <TextField fx:id="txtSalary" layoutX="158.0" layoutY="137.0" prefHeight="31.0" prefWidth="254.0" />
      <Button layoutX="298.0" layoutY="208.0" mnemonicParsing="false" onAction="#btnCal" prefHeight="34.0" prefWidth="113.0" text="Calculator" textFill="#ec0000">
         <font>
            <Font name="System Bold" size="17.0" />
         </font>
      </Button>
   </children>
</AnchorPane>

i have attached the video link below. which will do this tutorials step by step.

admin

Recent Posts

Touchable shop Pos system using Java

The Touchable Shop POS (Point of Sale) system is a sophisticated software solution developed using…

2 weeks ago

Build Your First Responsive Login Form Using HTML and CSS FlexBox

Creating a responsive login form is a crucial skill for any web developer. In this…

2 weeks ago

Build Crud API with Laravel 12

In this tutorial will teach  Laravel 12 CRUD API  by step. Laravel  10 CRUD Application …

3 weeks ago

laravel 12 image upload tutorial

In this lesson we talk about laravel 12 image uploading and display the image step…

3 weeks ago

Laravel 12 CRUD Application

In this tutorial will teach Laravel 12 CRUD Application step by step. Laravel  12 CRUD…

4 weeks ago

Conditional Statements in Python

Conditional statements in Python allow us to control the flow of execution based on conditions.…

2 months ago