Monday, July 12, 2021

Loan Interest Solver in Swing Using Java

 A simple loan interest solver in Swing using Java programming language that I wrote I hope you will find my work useful.

I am currently accepting programming work, IT projects, school and application development, programming projects, thesis and capstone projects, IT consulting work, computer tutorials, and web development work kindly contact me at the following email address for further details.  If you want to advertise on my website, kindly contact me also at my email address also. Thank you.

My email address is jakerpomperada@gmail.com and jakerpomperada@yahoo.com

My mobile number here in the Philippines is 09173084360.






Program Listing

Loan_Interest_Solver.java

/*

 * To change this license header, choose License Headers in Project Properties.

 * To change this template file, choose Tools | Templates

 * and open the template in the editor.

 */

package com.jakerpomperada.loan_interest_solver;


import javax.swing.*;  

import java.text.DecimalFormat;


/**

 *

 * @author Jacob Samuel

 */

public class Loan_Interest_Solver extends javax.swing.JFrame {


    /**

     * Creates new form Loan_Interest_Solver

     */

    public Loan_Interest_Solver() {

        initComponents();

    }


    /**

     * This method is called from within the constructor to initialize the form.

     * WARNING: Do NOT modify this code. The content of this method is always

     * regenerated by the Form Editor.

     */

    @SuppressWarnings("unchecked")

    // <editor-fold defaultstate="collapsed" desc="Generated Code">                          

    private void initComponents() {


        Jlabel1 = new javax.swing.JLabel();

        principal_amount = new javax.swing.JTextField();

        Jlabel2 = new javax.swing.JLabel();

        percentage_rate = new javax.swing.JTextField();

        Jlabel3 = new javax.swing.JLabel();

        no_of_years = new javax.swing.JTextField();

        Jlabel4 = new javax.swing.JLabel();

        interest_rate = new javax.swing.JTextField();

        solve = new javax.swing.JButton();

        quit = new javax.swing.JButton();

        clear = new javax.swing.JButton();


        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        setTitle("Loan Interest Solver Using Swing in Java");


        Jlabel1.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N

        Jlabel1.setText("Enter Principal Amount ");


        Jlabel2.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N

        Jlabel2.setText("Enter Number of Years");


        Jlabel3.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N

        Jlabel3.setText("Enter Percentage Rate");


        Jlabel4.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N

        Jlabel4.setText("The Interest Rate");


        solve.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N

        solve.setText("Solve");

        solve.setToolTipText("Click here to solve the interest rate.");

        solve.addActionListener(new java.awt.event.ActionListener() {

            public void actionPerformed(java.awt.event.ActionEvent evt) {

                solveActionPerformed(evt);

            }

        });


        quit.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N

        quit.setText("Quit");

        quit.setToolTipText("Click here to quit program.");

        quit.addActionListener(new java.awt.event.ActionListener() {

            public void actionPerformed(java.awt.event.ActionEvent evt) {

                quitActionPerformed(evt);

            }

        });


        clear.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N

        clear.setText("Clear");

        clear.setToolTipText("Click here to clear the textbox.");

        clear.addActionListener(new java.awt.event.ActionListener() {

            public void actionPerformed(java.awt.event.ActionEvent evt) {

                clearActionPerformed(evt);

            }

        });


        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());

        getContentPane().setLayout(layout);

        layout.setHorizontalGroup(

            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

            .addGroup(layout.createSequentialGroup()

                .addGap(21, 21, 21)

                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

                    .addGroup(layout.createSequentialGroup()

                        .addComponent(solve, javax.swing.GroupLayout.PREFERRED_SIZE, 109, javax.swing.GroupLayout.PREFERRED_SIZE)

                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 38, Short.MAX_VALUE)

                        .addComponent(clear, javax.swing.GroupLayout.PREFERRED_SIZE, 109, javax.swing.GroupLayout.PREFERRED_SIZE)

                        .addGap(32, 32, 32)

                        .addComponent(quit, javax.swing.GroupLayout.PREFERRED_SIZE, 109, javax.swing.GroupLayout.PREFERRED_SIZE))

                    .addGroup(layout.createSequentialGroup()

                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

                            .addComponent(Jlabel1)

                            .addComponent(Jlabel2)

                            .addComponent(Jlabel3)

                            .addComponent(Jlabel4))

                        .addGap(18, 18, 18)

                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

                            .addComponent(interest_rate, javax.swing.GroupLayout.PREFERRED_SIZE, 126, javax.swing.GroupLayout.PREFERRED_SIZE)

                            .addComponent(percentage_rate, javax.swing.GroupLayout.PREFERRED_SIZE, 126, javax.swing.GroupLayout.PREFERRED_SIZE)

                            .addComponent(no_of_years, javax.swing.GroupLayout.PREFERRED_SIZE, 126, javax.swing.GroupLayout.PREFERRED_SIZE)

                            .addComponent(principal_amount, javax.swing.GroupLayout.PREFERRED_SIZE, 126, javax.swing.GroupLayout.PREFERRED_SIZE))))

                .addContainerGap())

        );

        layout.setVerticalGroup(

            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

            .addGroup(layout.createSequentialGroup()

                .addGap(31, 31, 31)

                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)

                    .addComponent(Jlabel1)

                    .addComponent(principal_amount, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))

                .addGap(18, 18, 18)

                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)

                    .addComponent(Jlabel2)

                    .addComponent(no_of_years, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))

                .addGap(18, 18, 18)

                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)

                    .addComponent(Jlabel3)

                    .addComponent(percentage_rate, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))

                .addGap(28, 28, 28)

                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)

                    .addComponent(Jlabel4)

                    .addComponent(interest_rate, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))

                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 32, Short.MAX_VALUE)

                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)

                    .addComponent(solve, javax.swing.GroupLayout.PREFERRED_SIZE, 42, javax.swing.GroupLayout.PREFERRED_SIZE)

                    .addComponent(quit, javax.swing.GroupLayout.PREFERRED_SIZE, 42, javax.swing.GroupLayout.PREFERRED_SIZE)

                    .addComponent(clear, javax.swing.GroupLayout.PREFERRED_SIZE, 42, javax.swing.GroupLayout.PREFERRED_SIZE))

                .addGap(21, 21, 21))

        );


        pack();

    }// </editor-fold>                        


    private void solveActionPerformed(java.awt.event.ActionEvent evt) {                                      

        // TODO add your handling code here:

         DecimalFormat f = new DecimalFormat("##.00");

        

         if (evt.getSource().equals(solve)) {


           double principal_amt =  Double.parseDouble(principal_amount.getText());

        

           double no_of_yrs =  Double.parseDouble(no_of_years.getText());

           

           double percentage_rate_given = Double.parseDouble(percentage_rate.getText());

           

           double solve_interest = (principal_amt * no_of_yrs * percentage_rate_given) / 100;

          

           interest_rate.setText(String.valueOf(" PHP " + f.format(solve_interest)));

           interest_rate.setEditable(false); 

           

    }             

    }                                     


    private void clearActionPerformed(java.awt.event.ActionEvent evt) {                                      

        // TODO add your handling code here:

         if (evt.getSource().equals(clear)) {

        principal_amount.setText("");

        no_of_years.setText("");

        percentage_rate.setText("");

        interest_rate.setText("");

        principal_amount.requestFocus();

        }

    }                                     


    private void quitActionPerformed(java.awt.event.ActionEvent evt) {                                     

        // TODO add your handling code here:

        if (evt.getSource().equals(quit)) {

                             

   int confirmed = JOptionPane.showConfirmDialog(null, "Exit Program?","Quit Program",JOptionPane.YES_NO_OPTION);

    if(confirmed == JOptionPane.YES_OPTION)

    {

        dispose();

    }

} else {

            

     setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);

       }     

    }                                    


    /**

     * @param args the command line arguments

     */

    public static void main(String args[]) {

        /* Set the Nimbus look and feel */

        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">

        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.

         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 

         */

        try {

            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {

                if ("Nimbus".equals(info.getName())) {

                    javax.swing.UIManager.setLookAndFeel(info.getClassName());

                    break;

                }

            }

        } catch (ClassNotFoundException ex) {

            java.util.logging.Logger.getLogger(Loan_Interest_Solver.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);

        } catch (InstantiationException ex) {

            java.util.logging.Logger.getLogger(Loan_Interest_Solver.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);

        } catch (IllegalAccessException ex) {

            java.util.logging.Logger.getLogger(Loan_Interest_Solver.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);

        } catch (javax.swing.UnsupportedLookAndFeelException ex) {

            java.util.logging.Logger.getLogger(Loan_Interest_Solver.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);

        }

        //</editor-fold>


        /* Create and display the form */

        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {

                new Loan_Interest_Solver().setVisible(true);

            }

        });

    }


    // Variables declaration - do not modify                     

    private javax.swing.JLabel Jlabel1;

    private javax.swing.JLabel Jlabel2;

    private javax.swing.JLabel Jlabel3;

    private javax.swing.JLabel Jlabel4;

    private javax.swing.JButton clear;

    private javax.swing.JTextField interest_rate;

    private javax.swing.JTextField no_of_years;

    private javax.swing.JTextField percentage_rate;

    private javax.swing.JTextField principal_amount;

    private javax.swing.JButton quit;

    private javax.swing.JButton solve;

    // End of variables declaration                   

}



No comments:

Post a Comment