User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the Java section within the Software Development category of DaniWeb, a massive community of 397,766 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,532 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Java advertiser: Lunarpages Java Web Hosting
Jun 15th, 2007
Views: 3,487
A program that compounds interest continuously to a specified premium, rate, and number of years. Displays the total work up in the GUI panel in a tree form.
java Syntax | 5 stars
  1. // Arman Majumder
  2. // Investhor GUI
  3.  
  4. import javax.swing.*;
  5. import java.awt.*;
  6. import java.awt.event.*;
  7. import java.util.*;
  8. import java.io.*;
  9.  
  10. public class InvesthorWindow extends JFrame
  11. {
  12. private JLabel yearLabel = new JLabel("Year");
  13. private JLabel principal1Label = new JLabel("Initial Principal");
  14. private JLabel interestLabel = new JLabel("Interest");
  15. private JLabel principal2Label = new JLabel("Final Principal");
  16.  
  17. public InvesthorWindow(String name, double principal, double rate, int year)
  18. {
  19. JPanel investment = new JPanel(new GridLayout(1, 2, 4, 8));
  20. investment.add(yearLabel);
  21. investment.add(principal1Label);
  22. investment.add(interestLabel);
  23. investment.add(principal2Label);
  24.  
  25. Container container = getContentPane();
  26. container.add(investment, BorderLayout.CENTER);
  27. JPanel compound = new JPanel(new GridLayout((year), 1, 1, 1));
  28.  
  29. double inter = 0;
  30. for(int count = 1; count<= year; count++)
  31. {
  32. JLabel time = new JLabel("Year " + count);
  33. JLabel initial = new JLabel(String.format("$%,.2f", principal));
  34. inter -= principal;
  35. principal = principal * Math.pow((1 + (rate/400)),(4*count));
  36. inter += principal;
  37. JLabel interest = new JLabel(String.format("$%,.2f", inter));
  38. JLabel fnlAmt = new JLabel(String.format("$%,.2f", principal));
  39.  
  40. compound.add(time);
  41. compound.add(initial);
  42. compound.add(interest);
  43. compound.add(fnlAmt);
  44. }
  45. container.add(compound, BorderLayout.SOUTH);
  46. }
  47.  
  48. public static void main (String[] args)
  49. {
  50. String name = JOptionPane.showInputDialog(null,
  51. "Enter your full name", "Input", JOptionPane.QUESTION_MESSAGE);
  52.  
  53. String money = JOptionPane.showInputDialog(null,
  54. "Enter your initial principal", "Input", JOptionPane.QUESTION_MESSAGE);
  55. try
  56. {
  57. double principal = Double.parseDouble(money);
  58. }
  59. catch(Exception e)
  60. {
  61. JOptionPane.showMessageDialog(null, "ERROR: principal input syntax");
  62. }
  63. double principal = Double.parseDouble(money);
  64.  
  65. String intRate = JOptionPane.showInputDialog(null,
  66. "Enter your interest rate", "Input", JOptionPane.QUESTION_MESSAGE);
  67. try
  68. {
  69. double rate = Double.parseDouble(intRate);
  70. }
  71. catch(Exception e)
  72. {
  73. JOptionPane.showMessageDialog(null, "ERROR: rate input syntax");
  74. }
  75. double rate = Double.parseDouble(intRate);
  76.  
  77. String time = JOptionPane.showInputDialog(null,
  78. "Enter your year", "Input", JOptionPane.QUESTION_MESSAGE);
  79. try
  80. {
  81. int year = Integer.parseInt(time);
  82. }
  83. catch(Exception e)
  84. {
  85. JOptionPane.showMessageDialog(null, "ERROR: year input syntax");
  86. }
  87. int year = Integer.parseInt(time);
  88.  
  89. InvesthorWindow investhor = new InvesthorWindow(name, principal, rate, year);
  90. investhor.setTitle("Investhor");
  91. investhor.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  92. investhor.pack();
  93. investhor.setVisible(true);
  94. }
  95. }
Post Comment

Only community members can submit or comment on code snippets. You must register or log in to contribute.

DaniWeb Marketplace (Sponsored Links)
All times are GMT -4. The time now is 4:08 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC