Jump to content

Pesssoal preciso de um help!!!


Postagens Recomendadas

image.png

Taltal de Juros esta carregando R$0,00. Não estou conseguindo encontrar o erro...

 

package application;

import javax.swing.JFrame;

import calculation.view.CalculationForm;

public class Main {
    
    public static void main(String[] args) {
        CalculationForm form = new CalculationForm();
        form.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        form.setVisible(true);//*exibição do form*//
    }

}

 

package calculation.model;

 

import java.util.Objects;

 

public class Entity {

private Long id;

private TipoDeJuros tipoDeJuros;

private Double valorPrincipal;

private Double taxa;

private int meses;

private Double montante;

private Double totalJuros;

public Entity() {

this.tipoDeJuros = new TipoDeJuros();

this.taxa = 0.0;

this.totalJuros = 0.0;

}

 

public TipoDeJuros getDeJuros() {

return this.getDeJuros();

}

 

 

public Entity(Long id, float tipoDeJuros, Double valorPrincipal, Double taxa, int meses, Double montante,

Double totalJuros) {

super();

this.id = id;

this.valorPrincipal = valorPrincipal;

this.taxa = taxa;

this.meses = meses;

this.montante = montante;

this.totalJuros = totalJuros;

}

 

public Long getId() {

return id;

}

 

public void setId(Long id) {

this.id = id;

}

 

public TipoDeJuros getTipoDeJuros() {

return tipoDeJuros;

}

 

public void setTipoDeJuros(TipoDeJuros tipoDeJuros) {

this.tipoDeJuros = tipoDeJuros;

}

 

public Double getValorPrincipal() {

return valorPrincipal;

}

 

public void setValorPrincipal(Double valorPrincipal) {

this.valorPrincipal = valorPrincipal;

}

 

public Double getTaxa() {

return this.taxa;

}

 

public void setTaxa(Double taxa) {

this.taxa = taxa;

}

 

public int getMeses() {

return meses;

}

 

public void setMeses(int meses) {

this.meses = meses;

}

 

public Double getMontante() {

return montante;

}

 

public void setMontante(Double montante) {

this.montante = montante;

}

 

public Double getTotalJuros() {

return totalJuros;

}

 

public void setTotalJuros(Double totalJuros) {

this.totalJuros = totalJuros;

}

 

@Override

public int hashCode() {

return Objects.hash(id);

}

 

@Override

public boolean equals(Object obj) {

if (this == obj)

return true;

if (obj == null)

return false;

if (getClass() != obj.getClass())

return false;

Entity other = (Entity) obj;

return Objects.equals(id, other.id);

}

 

 

}

 

package calculation.model;

 

public class TipoDeJuros {

private float valor;

public float getValor() {

return valor;

}

public void setValor(float valor) {

this.valor = valor;

}

 

 

}

 

package calculation.model.dao;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;

public class GenericDao {
    
    
    
    public void save(String insertSQL, Object... parametros) {
        Connection con = null;
        try {
            String url = "jdbc:mysql://localhost:3306/calc";
            String usuario = "root";
            String senha = "161009";

            con = DriverManager.getConnection(url, usuario, senha);
            PreparedStatement ps = con.prepareStatement(insertSQL);

            for (int i = 0; i < parametros.length; i++) {
                ps.setObject(i + 1, parametros[i]);
            }

            ps.execute();
            ps.close();
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            try {
                if (con != null) {
                    con.close();
                }
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
    }
    
}

 

package calculation.model.service;

import calculation.model.Entity;
import calculation.model.dao.CalculationDao;

public class CalculationService {
         private CalculationDao dao;
         
         public CalculationService() {
             this.dao = new CalculationDao();
       }
         
         public Entity JurosSimples(Entity calculation) {
             double principal = calculation.getValorPrincipal();
             double taxa = calculation.getTaxa()/100;
             int meses = calculation.getMeses();
             double juros = principal * taxa * meses;
             double montante = principal * (1 + (taxa * meses));
             calculation.setTotalJuros(juros);
             calculation.setMontante(montante);
             salvar(calculation);
             return calculation;
             
         }
         
         public Entity jurosCompostos(Entity calculation) {
             double principal = calculation.getValorPrincipal();
             double taxa = calculation.getTaxa() / 100;
             int meses = calculation.getMeses();
             double montante = principal * Math.pow((1 + taxa), meses);
             double juros = montante - principal;
             calculation.setTotalJuros(juros);
             calculation.setMontante(montante);
             salvar(calculation);
             return calculation;
         }
         
         public void salvar(Entity calculation) {
             dao.salvar(calculation);
         }
         
         
    
    
    
}

 

package calculation.view;

import java.awt.GridLayout;

import javax.swing.*;

import calculation.controller.CalculationController;

public class CalculationForm extends JFrame {

    private static final long serialVersionUID = 1L;

    private JLabel lbValorPrincipal, lbTaxa, lbTipo, lbMeses, lbMontante, lbTotalJuros;
    private JTextField txtValorPrincipal, txtTaxa, txtMeses, txtMontante, txtTotJuros;
    private JRadioButton rdBtnSimples, rBtnComposto;
    private JButton btnCalcular;

    public CalculationForm() {
        setTitle("Calculadora de Juros");
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        JPanel panel = new JPanel(new GridLayout(4, 3, 3, 4)); // 4 linhas, 3 colunas, espaçamento horizontal e
                                                                    // vertical entre os componentes

        lbValorPrincipal = new JLabel("Valor Principal:");
        lbTaxa = new JLabel("Taxa (%):");
        lbTipo = new JLabel("Tipo:");
        lbMeses = new JLabel("Meses:");
        lbMontante = new JLabel("Montante:");
        lbTotalJuros = new JLabel("Total de Juros:");

        txtValorPrincipal = new JTextField(10);
        txtTaxa = new JTextField(10);
        txtMeses = new JTextField(10);
        txtMontante = new JTextField(10);
        txtTotJuros = new JTextField(10);

        rdBtnSimples = new JRadioButton("Simples");
        rBtnComposto = new JRadioButton("Composto");
        ButtonGroup btnGroup = new ButtonGroup();
        btnGroup.add(rdBtnSimples);
        btnGroup.add(rBtnComposto);

        btnCalcular = new JButton("Calcular");

        // Adiciona um ouvinte de ação ao botão "Calcular"
        btnCalcular.addActionListener(e -> {
            // Cria uma instância de CalculationController
            CalculationController controller = new CalculationController();
            // Chama o método executa() do controller, passando a instância atual de
            // CalculationForm como argumento
            controller.executa(CalculationForm.this);
        });

        panel.add(lbValorPrincipal);
        panel.add(txtValorPrincipal);
        panel.add(lbTaxa);
        panel.add(txtTaxa);
        panel.add(lbTipo);
        panel.add(rdBtnSimples);
        panel.add(new JLabel()); // Adiciona uma célula vazia para manter o layout consistente
        panel.add(rBtnComposto);
        panel.add(lbMeses);
        panel.add(txtMeses);
        panel.add(lbMontante);
        panel.add(txtMontante);
        panel.add(lbTotalJuros);
        panel.add(txtTotJuros);

        panel.add(new JLabel()); // Adiciona uma célula vazia para manter o layout consistente
        panel.add(btnCalcular);

        add(panel);
        pack(); // Redimensiona o JFrame para ajustar os componentes
        setLocationRelativeTo(null); // Centraliza o JFrame na tela
        setVisible(true);
    }

    public JTextField getTxtValorPrincipal() {
        return this.txtValorPrincipal;
    }
    
    public JTextField getTxtMontante() {
        return this.txtMontante;
    }
    
    public JTextField getTxtTotJuros() {
        return this.txtTotJuros;
    }
}

 

 

Link to comment
Compartilhe em outros sites

Crie uma conta ou entre para comentar 😀

Você precisa ser um membro para deixar um comentário.

Crie a sua conta

Participe da nossa comunidade, crie sua conta.
É bem rápido!

Criar minha conta agora

Entrar

Você já tem uma conta?
Faça o login agora.

Entrar agora
  • Quem está online   0 Membros, 0 Anônimos, 26 Visitantes (Ver lista completa)

    • There are no registered users currently online


×
×
  • Create New...