Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

The DarulAman Water Utility (DWU) authority requires you to write a program that can calculate water usage charges and display water bills to its customers.

  1. The DarulAman Water Utility (DWU) authority requires you to write a program that can calculate water usage charges and display water bills to its customers. There are three types of customers: Home, Commercial and Industrial. The water charge rates vary depending on the customer usage type as described below (code H means Home usage, code C means Commercial usage and code I means Industrial usage):

Code

Price

H

RM40.00 plus RM0.015 per litre

C

RM1000.00 for the first 40,000 litres used plus RM0.25 for each additional litre used

I

RM2000.00 if usage is between 40,000 and 100,000 litres (inclusive)

RM3000.00 if usage is more than 100,000 litres

The program requires three inputs which are customer Account number, usage type code and customer water usage (in litres). The program will reread the usage type code if a wrong code is entered. The output will display the water bill which contains the account number, the usage type, the water usage and the calculated water charge amount. The calculated charge must be displayed to TWO (2) decimal digits.

The example of the program running (with three samples of inputs and outputs) are shown below (underlined texts are inputs to the program):

Account No:> 12345 Usage Type Code:> H Water Usage (in litres):> 1000 *****Water Bill***** Account No = 12345 Usage Type = Home Water Usage in Litres = 1000.0 Bill Amount = RM55.00 Do you want to check for another customer? [Y/N] : Y Account No:> 121212 Usage Type Code:> C Water Usage (in litres):> 40100 *****Water Bill***** Account No = 121212 Usage Type = Commercial Water Usage in Litres = 40100.0 Bill Amount = RM1025.00 Do you want to check for another customer? [Y/N] : Y Account No:> 313131 Usage Type Code:> U Usage Type Code:> E Usage Type Code:> I Water Usage (in litres):> 40100 *****Water Bill***** Account No = 313131 Usage Type = Industry Water Usage in Litres = 40100.0 Bill Amount = RM2000.00 Do you want to check for another customer? [Y/N] : N

The program uses TWO (2) methods. The first method named computeCharge is to compute the water charge amount. The second method named displayWaterBill is used for displaying (output) the water bill.

Based on the given descriptions, complete the following code:

  1. Complete the implementation of the computeCharge method as shown below:

public static double computeCharge(String code, double usage) {

double charge = 0.0;

}

  1. Complete the implementation of the displayWaterBill method as shown below:

public static void displayWaterBill(int acct, String code, double usage, double amount) {

System.out.println(*****Water Bill*****);

System.out.println(Account No = + acct);

System.out.print(Usage Type = );

}

  1. Complete the implementation of the program main method as shown below:

import java.util.Scanner; public class DWU {

public static void main(String[] args) {

char check;

int accountNo;

String usageTypeCode;

double waterUsage, billAmount;

Scanner scan = new Scanner(System.in);

System.out.print(Account No:>);

accountNo = scan.nextInt();

}

}

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_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

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

Get Started

Recommended Textbook for

Inference Control In Statistical Databases From Theory To Practice Lncs 2316

Authors: Josep Domingo-Ferrer

2002nd Edition

3540436146, 978-3540436140

More Books

Students also viewed these Databases questions

Question

2. How does communication shape cultures and social communities?

Answered: 1 week ago