Question

# class: ElectricBillInstance Variable/ data member:String n – to store the name of the customerint units – to store the number of units consumeddouble bill – to store the amount to paidMember methods:Void accept() – to accept the name of the customer and number of units consumedVoid calculate() – to calculate the bill as per the following tariff :

```				```
Number of units — Rate per unit
First 100 units — Rs.2.00
Next 200 units — Rs.3.00
Above 300 units — Rs.5.00
A surcharge of 2.5% charged if the number of units consumed is above 300 units.
```
```

# Share code with your friends

Code

```				```
import java.util.Scanner;

public class ElectricBill
{
String n;
int units;
double bill;
public ElectricBill()
{
n="";
units=0;
bill=0;

}
public void accept()
{
Scanner sc = new Scanner(System.in);
System.out.print("Enter the name of customer: ");
n = sc.next();
System.out.print("Enter units: ");
units = sc.nextInt();
}
public void calculate()
{
if (units<= 100)
{
bill = units * 2;
}
else if (units>100 && units<=300)
{
bill =100*2+ (units-100) * 3;
}
else
{
bill = 100*2 + 200*3+(units-300) * 5;
double charge = bill * 2.5 / 100;
bill = bill + charge;
}
}
public void print()
{
System.out.println("Name of the customer: " +n);
System.out.println("Number of units consumed: " +units);
System.out.println("Bill amount: " +bill);
}
public static void main(String[] args)
{
ElectricBill ob1 = new ElectricBill();
ob1.accept();
ob1.calculate();
ob1.print();
}
}

```
```

Sale

50
Sale

150
Sale

200
Sale

50
Sale

50
Sale

50
Sale

50
Sale

50
Sale

50