Java Protect the following code, all exceptions must be handle. Rewrite the following code or add...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
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 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
Expert Answer:
Posted Date:
Students also viewed these computer network questions
-
I need help with question 2. . You need to determine the profit maximizing price for a video game console. Currently you charge $180 and sell 2 million consoles per year. It costs $150 to produce a...
-
Let A, B be sets. Define: (a) the Cartesian product (A B) (b) the set of relations R between A and B (c) the identity relation A on the set A [3 marks] Suppose S, T are relations between A and B, and...
-
can someone solve this Modern workstations typically have memory systems that incorporate two or three levels of caching. Explain why they are designed like this. [4 marks] In order to investigate...
-
QUESTION 7 We discussed the selection sort sorting algorithm. What is the worst case time complexity of selection sort when sorting a list of n elements? o(lg n) O(n) O(n lg n) O(n) O(log n) O(1)
-
When should an NFPO make a reclassification of its net assets?
-
Based on input from his second-grade students, New York teacher Michael Schurr was able to redesign his classroom to better serve the students needs. In the book Design Thinking for Educators, he...
-
Calculate the capacitance-to-neutral in F/m and the admittance-to-neutral in S/km for the single-phase line in Problem 4.8. Neglect the effect of the earth plane. Data From Problem 4.8:- A 60-Hz...
-
Jim Hetzel manufactures and sells homemade wine, and he wants to develop a standard cost per gallon. The following are required for production of a 50-gallon batch. 3,000 ounces of grape concentrate...
-
Linda and Don are married and file a joint return. In 2020, they received $12,000 in Social Security benefits and $35,000 in taxable pension benefits and interest. If Linda in part (a) works...
-
A manufacturer of a new smart watch wants to examine preferences for digital versus analog faces for marketing purposes. A sample of n = 200 people is selected, and these individuals are classified...
-
Why must a product design be developed prior to a process plan? (LO3.1)
-
374. Maximize U(x, y) = 8x4/5 y 1/5; 4x + 2y = 12
-
Provide a 300- to 500-word substantiated summary on how your research question(s) align with the studys purpose and place the references in the reference section. Purpose Statement The purpose of...
-
Why does the Advisory Board Company recommend that hospitals must shift from an "asset-based service strategy" to a "service-based asset strategy"?
-
Using the terms from each group, you must compose a 1-2 sentence statement which CONNECTS all 3 terms in such a way that a TRUE statement is expressed Group 1 1. AT-WILL EMPLOYEE 2. SEXUAL...
-
Show (using $ figures) how your business will be able to service its dues or offer suitable ROI. #per Month 4 Project A S Project B 6 Project C 7 Project D $ Cost per 9 Month 10 Project A 11 Project...
-
What steps must a business take to implement a program of social responsibility?
-
A lessor entered into a 5-year lease appropriately classified as a sales-type lease. The cost of the underlying asset was \(\$ 40,000\) and the fair value of the asset was \(\$ 50,000\). The lease...
-
Using the information from Exercise 17-72, complete the following requirements from the lessor's perspective. Required a. Determine the classification of the lease to Try-Star Leasing Company. b....
-
Lessory Corporation, a manufacturer of equipment, enters into a lease of specialized equipment with LesseeX Corp. Title to the asset remains with Lessory Corp upon lease expiration. LesseeX Corp does...
Study smarter with the SolutionInn App