| | |
Investhor GUI
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); } }
Similar Threads
- Help with GUI I/O (Java)
- GUI help (C++)
- GUI Help? (Java)
- Help with GUI (Python)
- need help with the GUI (Java)
| Thread Tools | Search this Thread |
3d 6 @param affinetransform android api applet application arc array arrays automation binary bluetooth bold byte c++ chat class client code color compare component coordinates database detection doctype eclipse educational error file fractal froglogic game givemetehcodez graphics gui guitesting helpwithhomework html ide ideas image ingres input integer internet intersect j2me java java.xls javaexcel javaprojects jni jpanel jtextarea julia keytool keyword linux list loop map method methods mobile netbeans newbie nextline object pong print problem producer program programming project projectideas read recursion recursive replaysolutions rim scanner sell server set size sms sort sql string swing terminal threads tree web websites windows



