Hey guys this is my first post and I kind of need the answer ASAP, as it is due by midnight tonight (yes I know, way to procrastinate right?). I am taking an online Java programming class and I have been struggling but I actually fully debugged this program... or so I thought. When I went to run it, it allows me to enter all my info, but after the last calculation, I get this error message(also pictured below):
"Exception in thread "main" java.lang.ArithmeticException: / by zero
at bert.Bert.main(Bert.java:40)
BUILD FAILED (total time: 18 seconds)"
Can anyone help please?? I have my code attached as 2 images, but in case you'd rather view it in text, here is my code:
package bert;
import java.io.*;
public class Bert {
public static void main(String[] args) throws IOException{
BufferedReader dataIn = new BufferedReader (new InputStreamReader(System.in));
//Declaring Variables
int price, downpayment, tradeIn, months,loanAmt=0, interest =0;
double annualInterest, payment;
String custName, inputPrice,inputDownPayment,inputTradeIn,inputMonths, inputAnnualInterest;
//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);
//Calculations
payment=loanAmt/((1/interest)-(1/(interest*Math.round(1+ months))));
//Output
System.out.print("The monthly payment for " + custName + " is $");
System.out.println((int)payment);
}
/**
* @param args the command line arguments
*/
// TODO code application logic here
}
