You are required to write an application called Customer Billing System.  This system will calculate water usage charges for a month that has been imposed by Syarikat Air Melaka Berhad.  This system will categorise users into residential users and industrial users and calculate the charges based on data entered by the user.  Data needed are the type of customer (Residential or Industrial), past meter reading and current meter reading.

Given the charge rate as follows:

For Residential:
0 – 15 m3   : RM 0.82 every m3
15.1 – 40 m3    : RM 0.65 every m3
40.1 m3 and above   : RM 0.42 every m3
Minimum charge is RM 5.00




For Industrial:
0 m3 and above  : RM 1.47 every m3
Minimum charge is RM15.00

Instruction:
The above application must be able to hold information for up to 5 customers.  Use an array and repetition structure to store information about users such as type of customer, past meter reading, current meter reading and charges.  Write a structured Java program to develop the above system by following the steps below:

a)  Prompt the user to input the type of customer, past meter reading and current meter reading.  Next, get the difference between current meter reading and past meter reading.
b)  Separate them as either R/r for Residential or I/i for Industrial.  You can use any one of the two selection structures.
c)  Calculate the charges based on rates given above.  If there is no water consumption, the minimum charge will be imposed.  You can use any one of the two selection structures.
d)  Display information about the type of customer, past meter reading, current meter reading and charges for each customer.  Print the information in table format.  
import java.util.*;

class BillingSystem1{
 public static void main (String [] args){

int[] anArray;
anArray = new int[5];



double Charges = 0;
double water_usage = 0;
double current_meter;
double past_meter;
double c_meter;
double p_meter;


 for (int i = 1; i<= 5; i ++){
System.out.println();
System.out.println("BILLING SYSTEM");
System.out.println("===============");
System.out.println();
System.out.println("MENU");
System.out.println();
System.out.println("SELECT USER TYPE");
System.out.println();
System.out.println("R - RESIDENTAL");
System.out.println("I - INDUSTRIAL\n");

Scanner scanner = new Scanner(System.in);
char character = scanner.next().charAt(0);

       if (character == 'r' || character == 'R'){

       System.out.println ("\nRESIDENTAL");

       System.out.println("\nENTER PAST METER >\n");
       past_meter = scanner.nextDouble ();
       System.out.println ("YOUR PASS METER >\t"  + past_meter +"\n");

       System.out.println("\nENTER CURRENT METER >\n");
       current_meter = scanner.nextDouble ();
       System.out.println ("YOUR CURRENT METER >\t"  + past_meter +"\n");

       water_usage = current_meter - past_meter;{

         if ((water_usage > 0)&&(water_usage <= 15))
         Charges = (water_usage * 0.82 )+5.00;

         else if ((water_usage > 15)&&(water_usage <= 40))
         Charges = (water_usage * 0.65 )+5.00;

         else if (water_usage > 40)
         Charges = (water_usage * 0.42 )+5.00;


  else if (water_usage <= 0)
  Charges = 5.00;

System.out.println("DISPLAY");
System.out.println("====================");
System.out.println ("----------------------------------------------------------------------");
System.out.println (" User Type | CURRENT READING| PASS READING | USAGES | Charges(RM) ");
System.out.println ("-----------------------------------------------------------------------");
System.out.println("     "+character +"          " +current_meter +"m3             " +past_meter +"m3            m3"+water_usage +"             rm " +Charges);
System.out.println ("-----------------------------------------------------------------------");


}}


 else if (character == 'i'|| character == 'I'){

         System.out.println ("\nINDUSTRIAL");

         System.out.println("\nENTER PAST METER >\n");
         p_meter = scanner.nextDouble ();
         System.out.println ("YOUR PASS METER >\t"  + p_meter +"\n");

         System.out.println("\nENTER CURRENT METER >\n");
         c_meter = scanner.nextDouble ();
         System.out.println ("YOUR CURRENT METER >\t"  + c_meter +"\n");

         water_usage = c_meter - p_meter;{

           if (water_usage > 0)
           Charges = (water_usage * 1.47+15.00 );

           else
           Charges = 15.00;

System.out.println("PAPARAN MAKLUMAT BIL");
System.out.println("====================");
System.out.println ("----------------------------------------------------------------------");
System.out.println (" User Type | CURRENT READING| PASS READING | USAGES | Charges(RM)");
System.out.println("     "+character +"          " +c_meter +"             " +p_meter +"            "+water_usage +"           " +Charges);
System.out.println ("----------------------------------------------------------------------");



}}



 else 
 { 

  System.out.println();
  System.out.println("INVALID ENTRY\n");
  System.out.println("SELECT USER TYPE");
  System.out.println();
  System.out.println("R - RESIDENTAL");
  System.out.println("I - INDUSTRIAL\n");

}
}

guys...i tried so many times to use array for these solution...but failed...so anybody can help with the coding...please...?!

If you are getting errors, please copy and paste the full text here.

The above application must be able to hold information for up to 5 customers. Use an array and repetition structure to store information about users such as type of customer, past meter reading, current meter reading and charges. Write a structured Java program to develop the above system by following the steps below:

now my problems are i can't safe up to five customers particulars and display it in table form aft finish entering customer no. 5. i dono use array.

can u guide...?

Define a class to hold the information for a Customer.
Prompt the user for all the Customer's data.
Create a Customer object with the new class and the data the user entered.
Save that object in the array:

// Something like this:

Customer[] customers = new Customer[5]; // to hold data for 5 customers

// Begin loop to get data for 5 customers
  // get data for class object
  Customer cstmr = new Customer(<data here for constructor>);  // create object
  customers[ix] = cstmr; // save object in array
// end loop
Member Avatar for Wazzza95

I don't know much about Java, but it looks easy enough to pick up. I'd like to say one thing though... Given my understanding of the original question, I think the calculations in the first post are incorrect.

My justification on the above statement is this... A residential customer has a water usage of 7 (eg 3 to 10), my charge is $5.81. The calculation gives over $10.00.

The other thing I'll say is it looks like we're being asked to do someone's assignment. Help is one thing, but doing the assignment - just explain the code with snippets.

Shoot me down in flames if you like, but that's my post.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.