我从来没有遇到过这个问题,因为没有给出错误,我什至不确定在哪里看。我用这个程序玩得很开心(这是我第一次做方法)。在此问题之前,它一直在抛出异常。虽然我研究了那篇文章并设法修复了错误,但我觉得它不正确。请让我知道整个代码是否关闭(最好是一些建设性的批评)或者我是否接近:
import java.io.*;
public class InsuranceMethod2//class name here, same as file name
{
// use BufferedReader class to input from the keyboard
// declare a variable of type BufferedReader
private BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
//declare variable for input
private String inputString;
String carChoice;
boolean insurable;
int year;
public void InsuranceMethod2()throws IOException{//constructor, place class name here
String carChoice;
boolean insurable;
int year;
initialize();
insureProcess();
cleanUp();
}//end constructor
public void initialize(){
System.out.println();
System.out.println("Insurance Process Intializing");
}//end initialize
public void insureProcess() throws IOException {
String carChoice;
boolean insurable;
int year;
System.out.println("Enter your vehicle model: ");
inputString = input.readLine();
carChoice = inputString;
if(carChoice.equalsIgnoreCase("ford") || carChoice.equalsIgnoreCase("chevy") || carChoice.equalsIgnoreCase("toyota"))
{
System.out.println("Enter the vehicle year: ");
inputString = input.readLine();
year = Integer.parseInt(inputString);
if(year >= 1990)
{
System.out.println("Your vehicle is insurable");
}
}
}
public boolean checkModel(){
if(carChoice.equalsIgnoreCase("Ford")|| carChoice.equalsIgnoreCase("Chevy")|| carChoice.equalsIgnoreCase("Toyota"))
{
return true;
}
else
{
return false;
}
}//end checkModel
public boolean checkYear(int year){
return false;
}//end checkYear
public void printResults(boolean insurable){
}//end printResults
public void cleanUp(){
System.out.println("Program ending");
}//end cleanUp
public static void main(String [] args) throws IOException // main method
{
new InsuranceMethod2(); //class constructor name
} // end the main method
} // end the program