Click here to Skip to main content
15,889,116 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
After trying to compile the program I receive the following errors:

Java
C:\Java 1\New folder (2)\Chapter 03\Bert.java:23: unreported exception java.io.IOException; must be caught or declared to be thrown
		  custName = dataIn.readLine();
                                            ^
C:\Java 1\New folder (2)\Chapter 03\Bert.java:25: unreported exception java.io.IOException; must be caught or declared to be thrown
		  inputPrice = dataIn.readLine();
                                              ^
C:\Java 1\New folder (2)\Chapter 03\Bert.java:28: unreported exception java.io.IOException; must be caught or declared to be thrown
		  inputDownPayment = dataIn.readLine();
                                                    ^
C:\Java 1\New folder (2)\Chapter 03\Bert.java:31: unreported exception java.io.IOException; must be caught or declared to be thrown
		  inputTradeIn = dataIn.readLine();
                                                ^
C:\Java 1\New folder (2)\Chapter 03\Bert.java:34: unreported exception java.io.IOException; must be caught or declared to be thrown
		  inputMonths = dataIn.readLine();
                                               ^
C:\Java 1\New folder (2)\Chapter 03\Bert.java:37: unreported exception java.io.IOException; must be caught or declared to be thrown
		  inputAnnualInterest = dataIn.readLine();


What I have tried:

import java.io.*;

public class Bert
{
   	public static void main(String[] args)
   	{
	   	//Declaring Variables
	   	int price, downpayment, tradeIn, months;
	   	double annualInterest, payment, interest, loanAmt;
	   	String custName="", inputPrice="",inputDownPayment="",inputTradeIn="",inputMonths="", 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();
		  price = Integer.parseInt(inputPrice);
		System.out.print("What is the downpayment?  ");
		  inputDownPayment = dataIn.readLine();
		  downpayment = Integer.parseInt(inputDownPayment);
		System.out.print("What is the trade-in value?  ");
		  inputTradeIn = dataIn.readLine();
		  tradeIn = Integer.parseInt(inputTradeIn);
		System.out.print("For how many months is the loan?  ");
		  inputMonths = dataIn.readLine();
		  months = Integer.parseInt(inputMonths);
		System.out.print("What is the decimal interest rate?  ");
		  inputAnnualInterest = dataIn.readLine();
		  annualInterest =Double.parseDouble(inputAnnualInterest);

        //Calculations
		interest = 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);
   	}
}
Posted
Updated 27-Jul-18 0:38am
v3

1 solution

You need to add exception to method signature
public static void main(String[] args) throws IOException {
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900