Results 1 to 2 of 2
  1. #1
    Smirre is offline Member
    Join Date
    Nov 2008
    Posts
    16
    Rep Power
    0

    Question Help with compound interest program pleaze

    Hi guys,

    I please need your help with this compound interest program please.

    What I need to do is:

    "Create an application which calculates compound interest on a deposit over a certain period of time -

    1. Display the amount of money over the years on a graph. The x-axis should show the number of years, and the y-axis should show the amount of money.

    2. Using a thread, display each year and the amount as a point on the graph with a label. Display point about 200 milliseconds apart. The program should loop infinitely.

    3. The number of years and the amount must be entered by the user as command arguments. The number of years must range from 1 - 25 and the deposit from 20 - 200.

    4. Interest will be 5% per annum
    5. Provide error checking for the input boxes.
    "

    The code that Iv'e done so far is:

    Java Code:
    public class CompoundInterestProgram extends JFrame implements ActionListener, Runnable {
    	
    	double amount, prevAmount;
    	int years;
    	double interest = 0.5;
    	Thread runner;
    	
    	JLabel lbl1 = new JLabel("Please enter the initial deposit amount:");
    	JTextField text1 = new JTextField("", 5);
    	JLabel lbl2 = new JLabel("Please enter the numbers of years:");
    	JTextField text2 = new JTextField("", 5);
    	
    	public CompoundInterestProgram() {
    		super("Compound Interest Program");
    		setSize(500, 500);
    		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    		JPanel panel = new JPanel();
    		panel.add(lbl1);
    		lbl1.setToolTipText("Range of deposit must be 20 - 200!");
    		panel.add(text1);
    		panel.add(lbl2);
    		lbl2.setToolTipText("Range of years must be 1 - 25!");
    		panel.add(text2);
    		add(panel);
    		
    		if (runner == null) {
    			runner = new Thread(this);
    			runner.start();
    		}
    		
    		setVisible(true);
    	}
    	
    	public static void main(String[] args) {
    		CompoundInterestProgram cip = new CompoundInterestProgram();
    	}
    	
    	@Override
    	public void actionPerformed(ActionEvent ae) {
    		Object source = ae.getSource();
    		if (text1.equals(source)) {
    			String a = text1.getText(); 
    			int x = Integer.parseInt(a);
    			if (x < 20 || x > 200) {
    				JOptionPane.showMessageDialog(null, "The range of the initial deposit is 20 - 200!");
    			} else {
    				amount = x;
    			}
    		}
    		
    		if (text2.equals(source)) {
    			String b = text1.getText(); 
    			int y = Integer.parseInt(b);
    			if (y < 1 || y > 25) {
    				JOptionPane.showMessageDialog(null, "The range of years is 1 - 25!");
    			} else {
    				years = y;
    			}
    		}	
    	}
    
    	@Override
    	public void run() {
    		
    		
    		
    		try {
    			Thread.sleep(200);
    		} catch (InterruptedException ie) {
    		}
    		repaint();
    		
    	}
    
    }
    I know that the formula for this is:
    amount = prevAmount + (prevAmount*interest)

    but that's about it. I'm not sure what to do further or even if my code is correct this far.

    Please help me out with this.
    Thank you

  2. #2
    angryboy's Avatar
    angryboy is offline Senior Member
    Join Date
    Jan 2009
    Posts
    742
    Rep Power
    6

    Default

    You want to use an approach like top-down or bottom-up. I would write out paintComponent and the calculation methods first before going into threads and user inputs.
    USE CODE TAGS--> [CODE]...[/CODE]
    Get NotePad++ (free)

Similar Threads

  1. HELP FAST!!----Interest Calculator
    By Coop33 in forum New To Java
    Replies: 8
    Last Post: 10-15-2008, 01:44 PM
  2. calculating Bank interest rate.
    By dotnet007 in forum New To Java
    Replies: 10
    Last Post: 05-13-2008, 09:30 AM
  3. Replies: 0
    Last Post: 04-04-2008, 02:40 PM
  4. How to use compound property names in Spring
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 03-30-2008, 10:08 AM
  5. How to use compound property names in Spring
    By JavaBean in forum Java Tip
    Replies: 0
    Last Post: 09-26-2007, 08:39 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •