Bug 397 - Invalid input of letter will not be checked
Summary: Invalid input of letter will not be checked
Status: RESOLVED FIXED
Alias: None
Product: Group37
Classification: Unclassified
Component: calculation operation (show other bugs)
Version: unspecified
Hardware: PC Windows
: --- enhancement
Assignee: feiwu25-c
URL:
Depends on:
Blocks:
 
Reported: 2020-11-07 19:30 HKT by PAN Zhenyuan
Modified: 2020-11-08 17:27 HKT (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description PAN Zhenyuan 2020-11-07 19:30:27 HKT
Overview:
Invalid input of letter will not be checked

Step to reproduce:
1) Start the calculator
2) Enter a
3) Press Enter

Expected Result:
error message of invalid input.

Actual Result:
no response


Build Date & Hardware:
07-11-2020 on Window 10.0.18363
Comment 1 danielsuendaniel 2020-11-08 17:27:44 HKT
problem is using "while(!sc.hasNextInt())". It ignore all character and noway to show the problem input to user.

solution is edit the code from:
while (!sc.hasNextInt())
	sc.next();
int input = sc.nextInt();
sc.nextLine();
return input;


to:
String input = sc.nextLine();
try {
	int option = Integer.parseInt(input);
	return option;
} catch (NumberFormatException e) {
        throw new InvaildInputOptionException(String.valueOf(input));
}