Results 1 to 3 of 3
  1. #1
    Froz3n777 is offline Member
    Join Date
    Feb 2008
    Posts
    1
    Rep Power
    0

    Default Simple Method Question

    I have the following code, and I want to make the return statement loop but i'm not sure exactly what i'm doing wrong or if it is even possible.

    Java Code:
    import javax.swing.JOptionPane;
     
    public class investment {
     
    	public static void main(String[] args) {
    		
    		String dataString = JOptionPane.showInputDialog(
    		"Enter the investment amount: ");
    		double amount = Integer.parseInt(dataString);
    				
    		String dataString1 = JOptionPane.showInputDialog(
    		"Enter the interest rate: ");
    		double interest = Integer.parseInt(dataString1);
    		
    		String dataString2 = JOptionPane.showInputDialog(
    		"Enter the amount of years: ");
    		int years = Integer.parseInt(dataString2);
    		
    		System.out.println("Years" + "      " + "Yearly Amount");
    		System.out.println("______" + "      " + "____________");
    		
    	
    		System.out.println(investment(amount,interest,years));
     
     
    	}
    	
    	public static double investment(double investmentAmount, double monthlyInterestRate, int years){
    			
     
    			double realrate = monthlyInterestRate / 100;
    			double monthlyPayment = investmentAmount * realrate / (1 - 1 / Math.pow(1 + realrate, years * 12));
    			total = monthlyPayment + investmentAmount;
    			
     
    			for (i = 1; i <= years; i++)
    				double realtotal = total + monthlyPayment
    				System.out.println(i);
    				return realtotal;
    			}
    	}
    I want the output to look something like:
    Year 1 - 1093
    Year 2 - 1186
    Year 3 - 1279
    and so forth looping through the amount of years

  2. #2
    Leprechaun is offline Member
    Join Date
    Dec 2007
    Posts
    30
    Rep Power
    0

    Default

    Once a return statement is executed the method is exited and the code returns to where the method was called.

    I would suggest using an array to return your values.

  3. #3
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

Similar Threads

  1. Question about CAS (compare and swap) method
    By illidian in forum Advanced Java
    Replies: 1
    Last Post: 04-04-2008, 08:49 PM
  2. Return question in a method.
    By MetalGear in forum New To Java
    Replies: 1
    Last Post: 01-13-2008, 04:45 AM
  3. Simple append question
    By Rageagainst20 in forum New To Java
    Replies: 0
    Last Post: 12-20-2007, 11:40 PM
  4. Probably a really simple question...
    By ibanez270dx in forum New To Java
    Replies: 0
    Last Post: 11-16-2007, 01:27 AM
  5. Simple question of JTable
    By carl in forum AWT / Swing
    Replies: 1
    Last Post: 08-07-2007, 07:07 AM

Posting Permissions

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