Question: Lab Assignment #8 Given the following Java modular program below: Modify the program to write non-static value-returning Modify the following program that computes the product

Lab Assignment #8 Given the following Java
Lab Assignment #8 Given the following Java modular program below: Modify the program to write non-static value-returning Modify the following program that computes the product of two integers to a program that uses a value-returning methods one named computeCalories( ) that will compute the total calories by passing in the numCookies as an method named computeProduct( ). Also, write a void method named display Product( ) that displays the output. The argument and the other named computeCaloriePerCookie( ) to compute the number of calories in each cookie. method has to pass the num/ and the num? into the method as arguments. Name the new class Also, be sure to declare all constants locally in the body of the method and compute the caloriePerCookie. Your ComputeProduct ValReturn. Enter the modified program w/methods and Execute on JDoodle.com and submit. program should contain four (4) non-static value-returning methods and one (1) non-static void method to "Name: Name: display the output. *Description: "Description: import jaya.util Scanner, import java.util.Scanner, import java. util.Scanner; //make the Scanner class available public class ComputeProduct ( public class CookieCaloriesMethod : public class ComputeProduct ValReturn public static void main (String[ ] args) ( Create global Scanner object public static void main(String args) Create Scanner object Scanner keyboard - new Scanner (System in); Scanner keyboard - new Scanner( System in); Scanner keyboard = new Scanner(System.inje //declare Scanner object - must declared globally public static void main (String[ ] args) ( //create class object CookieCaloriesMethod cemObject - new CookieCaloriesMethod(); //declare class object "variable declarations ComputeProduct ValReturn epvrObj = new ComputeProduct Val Return(); int numl, num?, produc - //declare constants #variable declarations int numl, num?, product; final int CALORIES SERVING = 300; "prompt the user to enter integers final int COOKIES BAG = 40: System out printin("Enter two integers:"); num 1 " cpvrObj.getNum 10); //method call statement for value-return gerNum]() numI - keyboard .nextint(); um2 "upvrObj.getNum2: Winsethad call statement for valugrungeNAME final int NUM PER SERVINGS = 10; Im2 - keyboard.nextInt(): //declare variables "method call statement to call value-return method computeProduct) compute the product product - cpvrObj.computeProduct (num], num2) String name; noduct - num! * num2: / method call statement to call void mehod displayProduct() int numCookies, caloricPerCookie, totalCalories; Toutput the product spurObj.displayProduct (numl, num2, product): ystem out. printin( "The product of " + numi + " and "+ num2+ " is " System. out.print("Enter your name: "); //use a non-static value-returning method get Name( ) oduct /on-static value-returning method definition name - keyboard.nextLine(); public int getNum10 System out print ("Enter first integer:"): System.out.print("Enter number of cookies eaten: "); //use a non-static value-returning method getNumCookies() int nl = keyboard.nextint(); numCookies - keyboard.nextInt(); return al; morePer Cookie - CALORIES SERVING/(COOKIES BAG/NUM PER SERVINGS) blic int getNum2() totalCalories - caloricPerCookie * numCookies; System out print( Enter second integer ") W/method call statement to call display TotalCalories() and pass in two arguments inl n2 - keyboard.newIng); return n2; cemObject.display TotalCalories(name, totalCalories); Won-static value-returning method definition public int computeProduct(int numl, int num?)( //method definition for a non-static void method return num * num2; public void display TotalCalories(String name, int totalCalories) { Won-static void method definition System.out.printIn(name + " ate a total of " + totalCalories + " calories."); public void displayProduct (int num1, int num2, int product) "/output the product System. out printIn(" The product of "+ numi + " and " + num2 + " is "+ producty 2. Design/write a Java program that contains a method definition named times Fifty(). The method should accept an integer argument when it is called. When the method is called, it should return the product of its argument multiplied times 50. Also write the void method display Results() to display/print the results. Name the class Compute TimesFifty. Then enter, execute/test it on JDoodle.com and submit in Blackboard. 3. A Java program contains the following method definition: public int cube (int num) { return (num * num * num) Write a method call statement that passes the argument value 6 to this method and assigns its return value to the variable result. Also write the non-static void method displayCube( ). Name the class ComputeCube. Test the complete program on JDoodle.com and then submit in Blackboard

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!