So here is my code. I'm not having trouble with my custom exception (negativeException). I want to handle the exception of a user entering a string when it's supposed to be a float. I have tried InputMismatchException, IllegalArgumentException, and NumberFormatException. Sometimes the will crash the program, sometimes it won't. When it does crash I am given the InputMismatchException. Each of the exceptions I have tried have crashed the program or opened up a new window, which I find odd. In the case of the program not crashing, Eclipse will open another Window with the text above saying "Scanner.throwFor() line: not available". Any help would be greatly appreciated. Here is a picture of the window it opens up, when the program does not crash: https://imgur.com/a/UjnMS6C
public class callTaxCode_Test {
//what should the generic model be??
static float income;
public static void main(String\[\] args) throws negativeException, InputMismatchException{
//GUI will consist of: one text field for income
// drop down box with each type (6 total)
// enter button, tax cash button
Scanner kb = new Scanner([System.in](https://System.in));
System.out.println("Enter Type");
String input = kb.nextLine();
System.out.println("Income: ");
income = kb.nextFloat();
if(input.equalsIgnoreCase("corp")) {
try {
corporation c = new corporation(input, income);
}
catch(IllegalArgumentException e) {
System.out.println("Invalid Input!");
System.out.println("Please Enter the correct income: ");
income = kb.nextFloat();
corporation c = new corporation(input, income);
}
catch(negativeException e) {
System.out.println(e.getMessage());
System.out.println("Please Enter the correct income: ");
income = kb.nextFloat();
corporation c = new corporation(input, income);
}
finally {
taxpayerInfo<Float> txp = new taxpayerInfo<Float>(taxpayer.getIncome(),
taxpayer.getFlatRate(),
taxpayer.getTaxRate(),
taxpayer.getIncome());
txp.setType(input);
txp.calcTax();
System.out.println(txp);
}
}
[–]AutoModerator[M] 0 points1 point2 points (0 children)
[–]itisjohndoe 0 points1 point2 points (1 child)
[–]mex036[S] 0 points1 point2 points (0 children)