Advertisement
Kotelettklopfer

Zinsrechner

May 9th, 2021
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5.48 KB | None | 0 0
  1. import java.awt.Color;
  2. import java.awt.Container;
  3. import java.awt.Dimension;
  4. import java.awt.Insets;
  5. import java.awt.Toolkit;
  6. import java.awt.event.ActionEvent;
  7. import java.awt.event.ActionListener;
  8. import java.math.BigDecimal;
  9. import java.text.NumberFormat;
  10. import java.util.Locale;
  11.  
  12. import javax.swing.JButton;
  13. import javax.swing.JFrame;
  14. import javax.swing.JLabel;
  15. import javax.swing.JTextField;
  16. import javax.swing.SwingConstants;
  17. import javax.swing.WindowConstants;
  18.  
  19. /**
  20.  *
  21.  * Beschreibung
  22.  *
  23.  * @version 1.0 (Alpha) vom 08.05.2021
  24.  * @author DPU
  25.  *
  26.  */
  27.  
  28. public class ZinsrechnerDPU extends JFrame {
  29.  
  30.   private JLabel lZinsrechnerDPU = new JLabel();
  31.   private JLabel labelCapital = new JLabel();
  32.   private JTextField fieldCapital = new JTextField();
  33.   private JLabel labelRunTime = new JLabel();
  34.   private JTextField fieldRunTime = new JTextField();
  35.   private JLabel labelInterestRate = new JLabel();
  36.   private JTextField fieldInterestRate = new JTextField();
  37.   private JButton bBerechnung = new JButton();
  38.   private JLabel labelTotalCaptital = new JLabel();
  39.   private JTextField fieldTotalCapital = new JTextField();
  40.   private JLabel labelTotalInterestRate = new JLabel();
  41.   private JTextField fieldTotalInterestRate = new JTextField();
  42.  
  43.  
  44.   public ZinsrechnerDPU() {
  45.    
  46.     super();
  47.     setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
  48.     int frameWidth = 756;
  49.     int frameHeight = 480;
  50.     setSize(frameWidth, frameHeight);
  51.     Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
  52.     int x = (d.width - getSize().width) / 2;
  53.     int y = (d.height - getSize().height) / 2;
  54.     setLocation(x, y);
  55.     setTitle("Zinsrechner DPU");
  56.     setResizable(false);
  57.     Container cp = getContentPane();
  58.     cp.setLayout(null);
  59.    
  60.    
  61.     cp.setBackground(Color.GRAY);
  62.     lZinsrechnerDPU.setBounds(10, 8, 700, 20);
  63.     lZinsrechnerDPU.setText("Zinsrechner -DPU-");
  64.     lZinsrechnerDPU.setHorizontalAlignment(SwingConstants.CENTER);
  65.     cp.add(lZinsrechnerDPU);
  66.     labelCapital.setBounds(40, 60, 110, 20);
  67.     labelCapital.setText("Kapital");
  68.     labelCapital.setToolTipText("Trennzeichen .");
  69.     labelCapital.setHorizontalAlignment(SwingConstants.CENTER);
  70.     labelCapital.setVerticalAlignment(SwingConstants.CENTER);
  71.     cp.add(labelCapital);
  72.     fieldCapital.setBounds(40, 85, 150, 20);
  73.     fieldCapital.setSelectionEnd(0);
  74.     fieldCapital.setHorizontalAlignment(SwingConstants.CENTER);
  75.     cp.add(fieldCapital);
  76.     labelRunTime.setBounds(40, 125, 110, 20);
  77.     labelRunTime.setText("Laufzeit");
  78.     labelRunTime.setHorizontalAlignment(SwingConstants.CENTER);
  79.     cp.add(labelRunTime);
  80.     fieldRunTime.setBounds(40, 150, 150, 20);
  81.     fieldRunTime.setHorizontalAlignment(SwingConstants.CENTER);
  82.     cp.add(fieldRunTime);
  83.     labelInterestRate.setBounds(40, 190, 110, 20);
  84.     labelInterestRate.setText("Zinssatz");
  85.     labelInterestRate.setHorizontalAlignment(SwingConstants.CENTER);
  86.     cp.add(labelInterestRate);
  87.     fieldInterestRate.setBounds(40, 215, 150, 20);
  88.     fieldInterestRate.setHorizontalAlignment(SwingConstants.CENTER);
  89.     cp.add(fieldInterestRate);
  90.     bBerechnung.setBounds(70, 290, 100, 25);
  91.     bBerechnung.setText("Berechnung");
  92.     bBerechnung.setMargin(new Insets(2, 2, 2, 2));
  93.     bBerechnung.addActionListener(new ActionListener() {
  94.       public void actionPerformed(ActionEvent e) {
  95.             NumberFormat cf = NumberFormat.getCurrencyInstance(Locale.GERMANY);
  96.            
  97.             BigDecimal capital = new BigDecimal(fieldCapital.getText());
  98.             System.out.println(capital);
  99.             BigDecimal runTime = new BigDecimal(fieldRunTime.getText());
  100.             System.out.println(runTime);
  101.             BigDecimal interestRate = new BigDecimal(fieldInterestRate.getText());
  102.             System.out.println(interestRate);
  103.            
  104.             BigDecimal totalInterrestRate =
  105.                     capital.multiply(interestRate)
  106.                     .multiply(runTime)
  107.                     .divide(BigDecimal.valueOf(12*100));
  108.            
  109.             System.out.println(cf.format(totalInterrestRate));
  110.            
  111.             BigDecimal totalCapital =
  112.                     capital.multiply(interestRate)
  113.                     .multiply(runTime)
  114.                     .divide(BigDecimal.valueOf(12*100))
  115.                     .add(capital);
  116.            
  117.             System.out.println(cf.format(totalCapital));
  118.            
  119.             String totalCapitalString = String.valueOf(cf.format(totalCapital));
  120.            
  121.             fieldTotalCapital.setText(totalCapitalString);
  122.            
  123.             String totalInterestRateString = String.valueOf(cf.format(totalInterrestRate));
  124.            
  125.             fieldTotalInterestRate.setText(totalInterestRateString);
  126.            
  127.       }
  128.     });
  129.     cp.add(bBerechnung);
  130.     labelTotalCaptital.setBounds(300, 85, 195, 20);
  131.     labelTotalCaptital.setText("Kapital inkl. Zinsen über X Monate");
  132.     labelTotalCaptital.setHorizontalAlignment(SwingConstants.CENTER);
  133.     cp.add(labelTotalCaptital);
  134.     fieldTotalCapital.setBounds(500, 85, 150, 20);
  135.     fieldTotalCapital.setHorizontalAlignment(SwingConstants.CENTER);
  136.     fieldTotalCapital.setEditable(false);
  137.     cp.add(fieldTotalCapital);
  138.     labelTotalInterestRate.setBounds(300, 150, 178, 20);
  139.     labelTotalInterestRate.setText("Zinsen über X Monate Laufzeit ");
  140.     labelTotalInterestRate.setHorizontalAlignment(SwingConstants.CENTER);
  141.     cp.add(labelTotalInterestRate);
  142.     fieldTotalInterestRate.setBounds(500, 150, 150, 20);
  143.     fieldTotalInterestRate.setHorizontalAlignment(SwingConstants.CENTER);
  144.     fieldTotalInterestRate.setEditable(false);
  145.     cp.add(fieldTotalInterestRate);
  146.        
  147.     setVisible(true);
  148.   }
  149.  
  150.  
  151.  
  152.   public static void main(String[] args) {
  153.     new ZinsrechnerDPU();
  154.   }
  155.    
  156. }
  157.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement