Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Modifying The Code Language: JAVA Source Code: import java.lang.*; import java.util.Scanner; public class Main { public class WaterBillAnnualSummary { public static double computeAverage(double[] values) {

Modifying The Code

Language: JAVA

Source Code:

import java.lang.*; import java.util.Scanner; public class Main { public class WaterBillAnnualSummary { public static double computeAverage(double[] values) { double total = 0; double average = 0; for (double element : values) ; total = total + element; average = total / values.length; return average; } public static double computeAverage(int[] values) { double total = 0; double average = 0; for (int element : values) total = total + element; average = (double) total / values.length; return average; } public static int findLowest(int[] values) { int result = values[0]; for (int element : values) if (element  result) result = element; return result; } public static void main(String[] args) { int[] presentReading = new int[12]; int[] startReading = new int[12]; Scanner scanner = new Scanner(System.in); String consumer = ""; char cType = 'x'; int[] nCMUsed = new int[12]; int minCMResidential = 12; double minBillResidential = 180.00; float rateResidential = 30.00F; int minCMCommercial = 30; double minBillCommercial = 600.00; float rateCommercial = 50.00F; double[] amountDue = new double[12]; showIntroduction(); System.out.print("Enter the name of the water consumer: "); consumer = scanner.nextLine(); cType = readTypeOfConsumer(); startReading[0] = readStartReading(); for (int index = 0; index : "); if (t != 'r' && t != 'R' && t != 'c' && t != 'C') { System.out.println("The valid types are r for residential and c for commercial."); } } while (t != 'r' && t != 'R' && t != 'c' && t != 'C'); return t; } public static double computeAmountDue(int c, char t, int min1, double minB1, int min2, double minB2, float rate1, float rate2) { double amount = 0; switch (t) { case 'r': case 'R': if (c  

Requirements:

image text in transcribed

image text in transcribed

* (Hypothetical Annual Water Bill Summary Problem ) * The water bills for the 12 months of a year by a water service * subscriber is summarized as follows.

Inputs: * Water Meter Reading at the beginning of the year (i.e. January 1) * Water Meter Readings at the end of each of the 12 months * Payment Rates (Minimum Bill, price of water per cubic meter)

* Outputs: * Cubic meters of water consumed for each month (monthly consumption) * Amount paid for each month based on given rates (monthly payment) Average of monthly consumptions * Average of monthly payments * The month during which the amount of water consumed is highest * The month during which the amount of water consumed is lowest *

* Algorithm * 1. Read the name of the water consumer (consumer). * 2. Read The classification (cType) of the consumer such * that the only valid values for cType is "commercial" or "residential". * 3. Read water meter reading in cubic meters at the beginning of the year (previousR[@]). * 4.For month 1 to 12 * Read the water meter reading in cubic meters at the end of the month (presentR) such * that present cannot be less than previousR. Store the value in an array. *

* Compute the volume of water consumed for the month (consumption) * by subtracting the previous from presentr. Store the value in an array.

* Compute the amount due (amount Due) from the consumer based on * the following rules * If cType is residential and consumption 12, the amount due is 180.88 + (consumption - 12)*30.08 * If cType is commercial and consumption 30, the amount due is 600.00 + (consumption - 30)*50.00

* Store the value in an array.

* 5. Determine the average of the monthly water consumptions. * 6. Determine the average of the monthly payments. * 7. Determine the month during which water consumed is highest. * 8. Determine the month during which water consumed is least. * 9. Print the name of the consumer. * 10. Print the consumer type. * 11. Print the water meter reading at the beginning of the year. 12. Print a table showing the 12 months, water meter readings at * the end of each month, the amount paid due to the water * consumption for each month. * 13. Print the average of the monthly water consumptions. * 14. Print the average of the monthly payments. * 15. Print the month during which water consumption is highest. * 16. Print the month during which water consumption is lowest. */ // Modify the algorithm/program as you deem necessary

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions