Results 1 to 5 of 5
  1. #1
    kingfisher is offline Member
    Join Date
    Oct 2015
    Posts
    7
    Rep Power
    0

    Default Help me find error in very basic java code

    Hello,

    Am trying to find simple calculation using code. This is about calculating Loan amounts. To a given loan amount. monthly interest rate and number of years, I want to calculate monthly payment and total payment. So this is the code I gave but facing error that couldn't resolve. Help me find the error and please explain it.
    Java Code:
    import java.util.*;
    public class computeLoan {
    	public static void main(String[] args){
    	// Creating required objects
    	Scanner input = new Scanner(System.in); //object to accept inputs is created
    	System.out.println("Enter the Loan Amount, Monthly Interest Rate and Number of years for payment, respectively");
    	//Taking input from the console.
    	double loanAmount = input.newDouble();
    	double monthlyInterestRate = input.newDouble();
    	int numberOfYears = input.newInt();
    	int G = numberOfYears*12;
    	double monthlyPayment = (loanAmount*monthlyInterestRate)/(1-1/Math.pow((1+monthlyInterestRate),G));
    	double totalPayment = monthlyPayment*G;
    	System.out.println("The Monthly Payment is "+monthlyPayment+"and The total payment is "+ totalPayment);
    			  }
    			  }
    The error am getting is:
    Java Code:
    computeLoan.java:8: error: cannot find symbol
            double loanAmount = input.newDouble();
                                               ^
      symbol:   method newDouble()
      location: variable input of type Scanner
    computeLoan.java:9: error: cannot find symbol
            double monthlyInterestRate = input.newDouble();
                                                           ^
      symbol:   method newDouble()
      location: variable input of type Scanner
    computeLoan.java:10: error: cannot find symbol
            int numberOfYears = input.newInt();
                                              ^
      symbol:   method newInt()
      location: variable input of type Scanner
    3 errors
    Thanks in Advance.
    Last edited by JosAH; 10-06-2015 at 01:25 PM. Reason: added [code] ... [/code] tags

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    14,422
    Blog Entries
    7
    Rep Power
    28

    Default Re: Help me find error in very basic java code

    Does your scanner have newDouble() and newInt() methods? Mine hasn't ...

    kind regards,

    Jos
    Build a wall around Donald Trump; I'll pay for it.

  3. #3
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    6,226
    Rep Power
    14

    Default Re: Help me find error in very basic java code

    Add the following link to your browser. Use it often.

    Java Platform SE 8

    Regards,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

  4. #4
    kingfisher is offline Member
    Join Date
    Oct 2015
    Posts
    7
    Rep Power
    0

    Default Re: Help me find error in very basic java code

    Hello josAH,

    Ahh.. Didn't see that it wasn't nextDouble(). Thank you for pointing it out.

  5. #5
    kingfisher is offline Member
    Join Date
    Oct 2015
    Posts
    7
    Rep Power
    0

    Default Re: Help me find error in very basic java code

    Hello jim,

    That's really helpful. Thank you for the info.

Similar Threads

  1. Replies: 1
    Last Post: 06-27-2013, 09:08 PM
  2. Really basic error: cannot find symbol
    By gjwcarsaig in forum New To Java
    Replies: 10
    Last Post: 07-31-2011, 09:50 AM
  3. Replies: 8
    Last Post: 06-15-2011, 05:26 AM
  4. Find the Error in Class Code
    By Humphrey Bogart in forum New To Java
    Replies: 3
    Last Post: 03-30-2011, 04:43 PM
  5. help with basic java code
    By elizabeth in forum New To Java
    Replies: 1
    Last Post: 08-07-2007, 06:47 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
  •