Results 1 to 6 of 6
  1. #1
    Blondedude092 is offline Member
    Join Date
    Sep 2012
    Posts
    16
    Rep Power
    0

    Default I'm not sure where there is a problem with the code...

    import java.io.*;
    import java.io.InputStreamReader;

    public class Bert
    {
    public static void main(String[] args)throws IOException
    {
    //Declaring Variables
    int price, downpayment, tradeIn, months,loanAmt, interest;
    double annualInterest, payment;
    String custName, inputPrice,inputDownPayment,inputTradeIn,inputMont hs, inputAnnualInterest;
    BufferedReader dataIn = new BufferedReader(new InputStreamReader(System.in));

    //Get Input from User
    System.out.println("What is your name? ");
    custName = dataIn.readLine();
    System.out.print("What is the price of the car? ");
    inputPrice = dataIn.readLine();
    System.out.print("What is the downpayment? ");
    inputDownPayment = dataIn.readLine();
    System.out.print("What is the trade-in value? ");
    inputTradeIn = dataIn.readLine();
    System.out.print("For how many months is the loan? ");
    inputMonths = dataIn.readLine();
    System.out.print("What is the decimal interest rate? ");
    inputAnnualInterest = dataIn.readLine();

    //Conversions
    price = Integer.parseInt(inputPrice);
    downpayment = Integer.parseInt(inputDownPayment);
    tradeIn = Integer.parseInt(inputTradeIn);
    months = Integer.parseInt(inputMonths);
    annualInterest =Double.parseDouble(inputAnnualInterest);


    interest =Integer.parseInt(String.valueOf(annualInterest/12));
    loanAmt = price-downpayment-tradeIn;
    payment=(loanAmt/((1/interest)-(1/(interest*Math.pow(1+interest,months)))));
    //Output
    System.out.print("The monthly payment for " + custName + " is $");
    System.out.println(payment);
    }
    }

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: I'm not sure where there is a problem with the code...

    Quote Originally Posted by Blondedude092 View Post
    I'm not sure where there is a problem with the code...
    And neither are we. Consider telling us about any problems you may be having and post any error messages if you have them. Our mind reading abilities are not as strong as you seem to imagine them to be.

    Next we'll work on use of code tags, ut the above information will suffice for now.

  3. #3
    Blondedude092 is offline Member
    Join Date
    Sep 2012
    Posts
    16
    Rep Power
    0

    Default Re: I'm not sure where there is a problem with the code...

    Exception in thread "main" java.lang.NumberFormatException: For input string: "0.004166666666666667"
    at java.lang.NumberFormatException.forInputString(Num berFormatException.java:48)
    at java.lang.Integer.parseInt(Integer.java:458)
    at java.lang.Integer.parseInt(Integer.java:499)
    at Bert.main(Bert.java:44)
    Java Result: 1

  4. #4
    jnicholas2012 is offline Member
    Join Date
    Sep 2012
    Posts
    2
    Rep Power
    0

    Thumbs down Re: I'm not sure where there is a problem with the code...

    import java.io.*;


    public class Bert
    {
    public static void main(String[] args)throws IOException
    {
    //Declaring Variables
    int price, downpayment, tradeIn, months,loanAmt, interest;
    double annualInterest, payment;
    String custName, inputPrice,inputDownPayment,inputTradeIn,inputMont hs = null,
    inputAnnualInterest;
    BufferedReader dataIn = new BufferedReader(new InputStreamReader(System.in));

    //Get Input from User
    System.out.println("What is your name? ");
    custName = dataIn.readLine();
    System.out.print("What is the price of the car? ");
    inputPrice = dataIn.readLine();
    System.out.print("What is the downpayment? ");
    inputDownPayment = dataIn.readLine();
    System.out.print("What is the trade-in value? ");
    inputTradeIn = dataIn.readLine();
    System.out.print("For how many months is the loan? ");

    System.out.print("What is the decimal interest rate? ");
    inputAnnualInterest = dataIn.readLine();

    //Conversions
    price = Integer.parseInt(inputPrice);
    downpayment = Integer.parseInt(inputDownPayment);
    tradeIn = Integer.parseInt(inputTradeIn);
    months = Integer.parseInt(inputMonths);
    annualInterest =Double.parseDouble(inputAnnualInterest);


    interest =Integer.parseInt(String.valueOf(annualInterest/12));
    loanAmt = price-downpayment-tradeIn;
    payment=(loanAmt/((1/interest)-(1/(interest*Math.pow(1+interest,months)))));
    //Output
    System.out.print("The monthly payment for " + custName + " is $");
    System.out.println(payment);
    }
    }






    I'm not sure if it's any help, but class Bert is public, should be declared in a file named Bert.java I corrected any mistakes I found in your code and replaced it with the code above. Final error is the one I just mentioned about declaring a file named Bert.

  5. #5
    huupderitis is offline Member
    Join Date
    Sep 2012
    Posts
    8
    Rep Power
    0

    Default Re: I'm not sure where there is a problem with the code...

    It would appear to me based on the error that you entered in a really long double like 0.0000404044 or some junk... and the value it wanted was an integer.

  6. #6
    Blondedude092 is offline Member
    Join Date
    Sep 2012
    Posts
    16
    Rep Power
    0

    Default Re: I'm not sure where there is a problem with the code...

    Here is the output when I run the program...
    run:
    What is your name?
    d
    What is the price of the car? 1
    What is the downpayment? 1
    What is the trade-in value? 1
    For how many months is the loan? 1
    What is the decimal interest rate? 1
    Exception in thread "main" java.lang.NumberFormatException: For input string: "0.08333333333333333"
    at java.lang.NumberFormatException.forInputString(Num berFormatException.java:48)
    at java.lang.Integer.parseInt(Integer.java:458)
    at java.lang.Integer.parseInt(Integer.java:499)
    at Bert.main(Bert.java:43)
    Java Result: 1
    BUILD SUCCESSFUL (total time: 12 seconds)


    I tried the example and I got a result which ended up not even letting me enter the months, it prints out the question for interest on same line as the question for months.

Similar Threads

  1. Problem with code
    By koryvandell in forum New To Java
    Replies: 4
    Last Post: 04-25-2011, 04:28 AM
  2. GUI code problem
    By baf06 in forum New To Java
    Replies: 17
    Last Post: 04-07-2011, 03:46 PM
  3. Replies: 0
    Last Post: 02-21-2011, 11:50 AM
  4. Replies: 9
    Last Post: 09-21-2010, 04:15 PM
  5. Problem with zero in my code
    By fernando in forum New To Java
    Replies: 1
    Last Post: 08-05-2007, 06:39 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
  •