Question: Java Protect the following code, all exceptions must be handle. Rewrite the following code or add exceptions everywhere that applies. public class CalcNeedExceptions {

Java Protect the following code, all exceptions must be handle. Rewrite the following code or add exceptions everywhere that applies. public class CalcNeedExceptions { public static void main(String[] args) { String firstNumber = ('user input for first number goes here!"); String secNumber = ("user input for second number goes here!"); String output = String.valueOf(efficiencyFactor(Double.parseDouble(divide(first Number, secNumber)))); System.out.println(output); public static double efficiencyFactor(double sum) { } final double efficiencyMinimum = 0.98765; return (sum * efficiencyMinimum); public static String divide(String a, String b) { } } return String.valueOf((Double.parseDouble(a)) / (Double.parseDouble(b))); public static String add(String a, String b) { return String.valueOf((Double.parseDouble(a)) + (Double.parseDouble(b))); public static String mul(String a, String b) { } return String.valueOf((Double.parseDouble(a)) * (Double.parseDouble(b))); public static String sub(String a, String b) { } return String.valueOf((Double.parseDouble(a)) - (Double.parseDouble(b))); A partially completed program is given below which includes: the class Q1, its key attribute "myID", and the main() method. A call to function testString() is made in main() and the return value is printed. Write the function definition for testString(). The string argument to this function will be converted to an integer. Exception handling is needed if any character in the string argument is not a digit. If an error is found, testString() returns -1. If there is no error, testString() will return the difference between such an integer and your student number (i.e., subtract your student ID from this integer; you must hard-code your student number In the program). Code comment is not needed } public class Q1 { static private String myID = "999999999"; public static void main(String[] args) { int result = testString(myID); characters } System.out.println(result); //exception handling is needed if myID contains non-digit //Write the function definition of testString() as your answer for this question //testString() returns the difference between its argument (after converting it as integer) and your student number //Note: this function must provides exception handling for converting its string argument
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
