Member 13652359 Ответов: 1

Почему я получаю "исключение незарегистрированный Ява.Ио.класс IOException; должны быть пойманы или как объявляют, были брошены ошибка"?


После попытки скомпилировать программу я получаю следующие ошибки:

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();


Что я уже пробовал:

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);
   	}
}

1 Ответов

Рейтинг:
0

wseng

Вам нужно добавить исключение в сигнатуру метода

public static void main(String[] args) throws IOException {