•
•
•
•
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
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.
// Arman Majumder // Investhor GUI import javax.swing.*; import java.awt.*; import java.awt.event.*; import java.util.*; import java.io.*; public class InvesthorWindow extends JFrame { private JLabel yearLabel = new JLabel("Year"); private JLabel principal1Label = new JLabel("Initial Principal"); private JLabel interestLabel = new JLabel("Interest"); private JLabel principal2Label = new JLabel("Final Principal"); public InvesthorWindow(String name, double principal, double rate, int year) { JPanel investment = new JPanel(new GridLayout(1, 2, 4, 8)); investment.add(yearLabel); investment.add(principal1Label); investment.add(interestLabel); investment.add(principal2Label); Container container = getContentPane(); container.add(investment, BorderLayout.CENTER); JPanel compound = new JPanel(new GridLayout((year), 1, 1, 1)); double inter = 0; for(int count = 1; count<= year; count++) { JLabel time = new JLabel("Year " + count); JLabel initial = new JLabel(String.format("$%,.2f", principal)); inter -= principal; principal = principal * Math.pow((1 + (rate/400)),(4*count)); inter += principal; JLabel interest = new JLabel(String.format("$%,.2f", inter)); JLabel fnlAmt = new JLabel(String.format("$%,.2f", principal)); compound.add(time); compound.add(initial); compound.add(interest); compound.add(fnlAmt); } container.add(compound, BorderLayout.SOUTH); } public static void main (String[] args) { String name = JOptionPane.showInputDialog(null, "Enter your full name", "Input", JOptionPane.QUESTION_MESSAGE); String money = JOptionPane.showInputDialog(null, "Enter your initial principal", "Input", JOptionPane.QUESTION_MESSAGE); try { double principal = Double.parseDouble(money); } catch(Exception e) { JOptionPane.showMessageDialog(null, "ERROR: principal input syntax"); } double principal = Double.parseDouble(money); String intRate = JOptionPane.showInputDialog(null, "Enter your interest rate", "Input", JOptionPane.QUESTION_MESSAGE); try { double rate = Double.parseDouble(intRate); } catch(Exception e) { JOptionPane.showMessageDialog(null, "ERROR: rate input syntax"); } double rate = Double.parseDouble(intRate); String time = JOptionPane.showInputDialog(null, "Enter your year", "Input", JOptionPane.QUESTION_MESSAGE); try { int year = Integer.parseInt(time); } catch(Exception e) { JOptionPane.showMessageDialog(null, "ERROR: year input syntax"); } int year = Integer.parseInt(time); InvesthorWindow investhor = new InvesthorWindow(name, principal, rate, year); investhor.setTitle("Investhor"); investhor.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); investhor.pack(); investhor.setVisible(true); } }
Post Comment
•
•
•
•
DaniWeb Marketplace (Sponsored Links)