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);
}
}
Re: I'm not sure where there is a problem with the code...
Quote:
Originally Posted by
Blondedude092
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.
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
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.
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.
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.