Bug 635 - Java Exception Error when input text that is not number
Summary: Java Exception Error when input text that is not number
Status: RESOLVED FIXED
Alias: None
Product: 2021 CS3343 Hall Admission System
Classification: Unclassified
Component: Scoring and Weighting Record Section (show other bugs)
Version: unspecified
Hardware: PC Windows
: Normal normal
Assignee: Azim
URL:
Depends on:
Blocks:
 
Reported: 2021-12-04 15:16 HKT by amble3232
Modified: 2021-12-04 15:19 HKT (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description amble3232 2021-12-04 15:16:16 HKT
Background:
I am doing the unit testing in eclipse 2021-06 (4.20.0) on method convertScore() in Area_Eca class. 

Steps to Reproduce:
1. Run the package with testHall_Admission
2. Run the method “void testConvertScore” in testArea_eca class
3. Run @ParameterizedTest with “/testResource/testCreateArea_eca.csv”
4. Input the test case "Other String,true,,Test invalid input and then throw exception"

Actual result:
After the run the above steps, the system return “java.lang.NumberFormatException: For input string:Other String” in the console.

Expected result:
I expect the system to indicate the value is wrong if the input was wrong. I think the system should throw an exception and return nothing.
Comment 1 newbie 2021-12-04 15:17:29 HKT
For now, the system only accepts the number string and special strings like float number and DSE characters. Therefore when having other strings like "Other String", the system will throw a Java Exception directly as Java predefine error.

Adding a function to allow validate input and telling users the input have an error.

I will pass it to the developer to design a new function to do validation.
Comment 2 Azim 2021-12-04 15:19:17 HKT
I just added a class for validation of the input. The class is named Validation.

To validate the score, use the following method. I also added validation for other input. Now the bug is solved.

Solution:
===============
public static boolean validationScore(String input, String academicType) {
Double temp = 0.0;
	if(input==null||academicType==null) return false;
	if(academicType.equals("DSE")) {
		if(input.equals("5**")||input.equals("5*")||input.equals("5")||input.equals("4")||input.equals("3")||input.equals("2")||input.equals("1")||input.equals("U"))
		return true;
	}else {
		if(!checkDouble(input))
			return false;
		temp = Double.parseDouble(input);
		if(temp<=4.3 && temp>=0)
		return true;
	}
	return false;
}