Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Here is the signature of the method printWaterBill(doubleunitsConsumed, double u

ID: 3611101 • Letter: H

Question

Here is the signature of the method printWaterBill(doubleunitsConsumed, double unitPrice). Variable unitesConsumed standsfor the number of water units actually consumed. Variable unitPricestands for the price of one unit of water. The body of this methodis currently empty(the part within the curly braces)

   public static void printWaterBill(doubleunitsConsumed, double unitPrice)
   
     {


     }
Complete the body of the method by writing inside the curly bracesthe code specified in the following requirements:
   -Define a variable called waterbillAmount
   -Compute the water bill amount on the basis of theprovided units of water consumed and price per unit. the amount ofthe water bill is the price the consumer has to pay for the waterunits consumed. Assign the value to the waterbillAmount.
    -Print the bill information on the terminalwindow (standard output). the bill information is displayed onthree lines. the first line displays the number of units consumed,the second displays the price per unit, and the third displays thewater bill amount. For instance, when invoked with 34.5 units ofwater consumed and 2.35 for the price of the units, the methodprints:

         the number ofunits of water consumed is: 34.5
         The price per unitof water is: 2.35
          The amountof the water bill is: 81.075
At this point how should the method printWaterBill be modified sothat it also returns the water bill amount?
Include in your code hidden comments.



Explanation / Answer

import java.io.*; import java.util.*; import java.lang.*; public class WaterBill { public static void printWaterBill(double unitsConsumed,double unitPrice) {    double waterbillAmount = 0.0;    System.out.println("the number of units of waterconsumed is: " + unitsConsumed);    System.out.println("The price per unit of wateris: " + unitPrice);       waterbillAmount = (unitsConsumed *unitPrice);       System.out.println(" The amount of the waterbill is: " +waterbillAmount);       }//end of printWaterBill Fucntion /* to return the waterbillAmount, The function has to bemodified as below public static double printWaterBill(doubleunitsConsumed, double unitPrice) {    double waterbillAmount = 0.0;    System.out.println("the number of units of waterconsumed is: " + unitsConsumed);    System.out.println("The price per unit of wateris: " + unitPrice);       waterbillAmount = (unitsConsumed *unitPrice);       System.out.println(" The amount of the waterbill is: " +waterbillAmount);       return waterbillAmount; }//end of printWaterBill Fucntion */ public static void main(String [] arg) {    printWaterBill(34.5, 2.35);    System.out.println();       }//end of main }//end of class