Question: java Labwork Methods allow us to perform some task by calling on it in a different part of the code. This helps us save time

Labwork Methods allow us to perform some task by calling on it in a different part of the code. This helps us save time because we don't have to retype the same code again. Instructions: Download Lab Work 7.2 from Mimir. Take in two lines of input. o The first line of input string can take in "difference", "sum", or "product" and save it into the variable type. o The second line of input string can take in any two-digit string ("12":"47" etc.), and save it into the variable digits. o Assume, that the user will always put in "difference", "sum", or "product" in the first line of input and a two-digit value in the second input string. Use methods to do the math of the requested type. "sum" should take the sum of the two digits in the string digits = "42". -> 4 + 2 = 6 Output: "The sum of the 2 digits is: 6 o "product" should take the product of the two digits in the string digits = "42", -> 4x2 = 8 Output: "The product of the 2 digits is: 8" o "difference" should take the difference between the product and sum of the digits (product - sum) digits - "42": -> 8- 6 = 2 Output: ""The difference between the product and sum is: 2" The output format should be: "The sum of the 2 digits is: o "product The product of the 2 digits is: o "difference" "The difference between the product and sum is: Hints to remember: 6 Substring allows us to get parts of strings Integer.parseInt() allows us to convert strings (with number values) to String.valueOfD) allows us to convert integers to type string Methods can have input and output . o "sum" type int O /*Instructions: Toke in two lines of input. The first tine con take in difference", "sum", or "product and save it into type. The second Line of input can take in any two digit string ("12", "47", etc.), and save it into digits. Assume that the user will always put in difference", "us", or "product" in the first line of input, and that the user will always put in a two digit value in the second input. Use methods to do the math of the requested type. - sum" should take the sum of the two digits in the string "product" should take the product of the two digits in the string "difference" should take the difference between the product and sun of the digits (product Sum) Class lab7_2 { // create method that calculates the sum of two digits in a string here // creste method that calculates the product of two digits in a string here 11 (con create method that celcutates the difference between the product and sum of two digits in a string here public static void main(String[] args) { Scanner sc - new Scanner(System.in); I System.out.println("What type of math would you like to do?"); String type; 11 difference, sun, product type - sc.input.nextLine(); System.out.println("What digits would you like to do the math on?"); String digits; digits 7 8 Check the type inputted and do the corresponding moth with String digits here. 32 } //end min > Ilend class 14
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
