Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 5 of 5

Thread: Need help with my code for calculating monthly payment on a loan

  1. #1
    Junior Member
    Join Date
    Feb 2012
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Need help with my code for calculating monthly payment on a loan

    I can get it to enter amount and also enter rate and enter amount of years but can't get it to tell me the monthly payment for some reason. I know I am missing something.

    import java.util.Scanner;
     
    public class project5{
     
    	/**
    	 * @param args
    	 */
    	public static void main(String[] args) {
     
    		  //Print out the welcome screen
    		  System.out.println ("Welcome to the Loan Calculator");
    		  System.out.println();
     
    		  double loanAmount;
    		  double interestRate;
    		  double months = 0;
     
    		  String choice = ("y");
     
    		  double numberYears;
     
    		  while (choice.equalsIgnoreCase("y"))
    		{
    			   //read loan amount
    			  Scanner sc = new Scanner (System.in);
    			  System.out.print("enter amount");
    			  loanAmount = sc.nextDouble();
     
    			  //read interest rate
    			  System.out.print("enter interest rate");
    			  interestRate = sc.nextDouble();
     
    			  //read number of years
    			  System.out.print("enter number of years");
    			  numberYears = sc.nextDouble();
     
    			  //calculate the monthly payment
    			  double monthlyPayment = loanAmount * interestRate / (1 - 1/Math.pow(1 + interestRate, months));
     
    			  //display the monthly payment
    			  System.out.println ("The monthly payment is:");
     
     
    			  //see if the user wants to continue
    			  System.out.print("continue? (y/n): ");
    			  choice = sc.next();
    			  System.out.println();
     
     
     
     
    		}
     
     
    	}
     
    }


  2. #2
    Member snowguy13's Avatar
    Join Date
    Nov 2011
    Location
    In Hyrule enjoying a chat with Demise and Ganondorf
    Posts
    339
    My Mood
    Happy
    Thanks
    31
    Thanked 48 Times in 42 Posts

    Default Re: Need help with my code for calculating monthly payment on a loan

    //display the monthly payment
    System.out.println ("The monthly payment is:");
    You never tell the program to display monthlyPayment's value. That may be why it's not showing.
    Last edited by snowguy13; February 24th, 2012 at 09:31 PM. Reason: Forgot smiley
    Use highlight tags to help others help you!

    [highlight=Java]Your prettily formatted code goes here[/highlight]

    Using these tags makes your code formatted, and helps everyone answer your questions more easily!




    Wanna hear something funny?

    Me too.

  3. #3
    Junior Member
    Join Date
    Feb 2012
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Need help with my code for calculating monthly payment on a loan

    Okay I am not sure how to tell it to do that. Can you give me a tip on how to do it please?

  4. #4
    Junior Member
    Join Date
    Feb 2012
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Need help with my code for calculating monthly payment on a loan

    Does anyone have an idea???

  5. #5
    Member snowguy13's Avatar
    Join Date
    Nov 2011
    Location
    In Hyrule enjoying a chat with Demise and Ganondorf
    Posts
    339
    My Mood
    Happy
    Thanks
    31
    Thanked 48 Times in 42 Posts

    Default Re: Need help with my code for calculating monthly payment on a loan

    To display a variable's value, you simply put it into the println statement.

    For example:

    int number = 2;
    System.out.println("The number is " + number);

    The result of this would be:

    The number is 2
    Use highlight tags to help others help you!

    [highlight=Java]Your prettily formatted code goes here[/highlight]

    Using these tags makes your code formatted, and helps everyone answer your questions more easily!




    Wanna hear something funny?

    Me too.

Similar Threads

  1. Need help correcting my code for calculating sexy prime pairs
    By BinaryPenguin14 in forum What's Wrong With My Code?
    Replies: 5
    Last Post: November 23rd, 2011, 04:05 AM
  2. Monthly Mortage Payment Calculator
    By lockdown in forum What's Wrong With My Code?
    Replies: 1
    Last Post: July 17th, 2011, 11:54 PM
  3. Basic program which gets cost, adds tax, gets payment then calculates change.
    By bibboorton in forum What's Wrong With My Code?
    Replies: 6
    Last Post: August 25th, 2010, 10:31 AM