Sie sind auf Seite 1von 5

EX NO:1 ELECTRICITY BILL

1)Develop a Java application to generate Electricity bill. Create a class with the

following members: Consumer no., consumer name, previous month reading, current month reading,
type

of EB connection (i.e domestic or commercial). Compute the bill amount using the following tariff. If the

type of the EB connection is domestic, calculate the amount to be paid as follows:

First 100 units - Rs. 1 per unit

101-200 units - Rs. 2.50 per unit

201 -500 units - Rs. 4 per unit

501 units - Rs. 6 per unit

If the type of the EB connection is commercial, calculate the amount to be paid as

follows:

First 100 units - Rs. 2 per unit

101-200 units - Rs. 4.50 per unit

201 -500 units - Rs. 6 per unit

501 units - Rs. 7 per unit

Aim:

To create a Java console application used to generate electricity bill based on connection type (Domestic

and Commercial) and consumption. Both are having different tariff slots.

Algorithm:

Step 1 Start the process

Step 2 Get the user informations [Name, Consumer Number, Reading’s of previous and currentmonth,

Connection Type]

Step 3 Compute units consumed by user [Current Month Reading – Previous Month Reading]
Step 4 Check the connection type

Step 5 If a connection type is domestic goto switch case 1

Step 6 If a connection type is commercial goto switch case 2

Step 7 Display Bill Details [Name, Consumer Number, No of units consumed]

Step 8 Display amount payable

Step 9 Stop the Process

Program:

import java.io.*;

import java.util.*;

class ComputeElectricityBill

public static void main(String args[])

String cname; //consumer name

int cnum;

long units1;

long units2;

long units;

Scanner sc=new Scanner(System.in);

System.out.println("enter the consumer name");

cname=sc.nextLine();

System.out.println("enter the consumer number");


cnum=sc.nextInt();

System.out.println("Press 1 for Domestic EB connection OR Press 2 for commercial EB


Connection");

int choice;

choice=sc.nextInt();

System.out.println("enter number of previous month units");

units1=sc.nextLong();

System.out.println("enter number of current month units");

units2=sc.nextLong();

units=units1+units2;

double billpay=0;

switch(choice)

case 1:

if(units<=100)

billpay=units*1.00;

else if(units>100 && units<=200)

billpay=units*2.50;

else if(units>200 && units<=500)

billpay=units*4;

else if(units>=501)

billpay=units*6;

System.out.println("The consumer name is"+cname);

System.out.println("The consumer num is "+cnum);


System.out.println("The total units consumed by you is"+units);

System.out.println(" Your Bill to pay : " + billpay);

break;

case 2:

if(units<=100)

billpay=units*2.00;

else if(units>100 && units<=200)

billpay=units*4.50;

else if(units>200 && units<=500)

billpay=units*6;

else if(units>=501)

billpay=units*7;

System.out.println("The consumer name is"+cname);

System.out.println("The consumer num is "+cnum);

System.out.println("The total units consumed by you is"+units);

System.out.println(" Your Bill to pay : " + billpay);

break;

default:

System.out.println("Inappropriate Option");
}

Output:

enter the consumer name

xyz

enter the consumer number

123

Press 1 for Domestic EB connection 2 for commercial EB Connection

enter number of previous month units

250

enter number of current month units

520

The consumer name is xyz

The consumer num is 123

The total units consumed by you is770

Your Bill to pay : 5390.0

Das könnte Ihnen auch gefallen