Question – 4
import java.util.Scanner;
class ElectricBill
{
String n;
int units;
double bill;
void accept()
{
Scanner scn = new Scanner(System.in);
System.out.print("Enter Customer Name : ");
n = scn.nextLine();
System.out.print("Enter No. of Units consumed : ");
units = scn.nextInt();
}
void calculate()
{
if(units <= 100)
bill = units*2.0;
else if(units <=300)
bill = 200.0+((units-100)*3.0);
else if(units > 300)
{
bill = 200.0+600.0+((units-300)*5.0);
double surchg = bill*2.5/100;
bill=bill+surchg;
}
}
void print()
{
System.out.println("Name of the customer : "+n);
System.out.println("No. of units consumed : "+units);
System.out.println("Bill amount : "+bill);
}
public static void main()
{
ElectricBill obj = new ElectricBill();
obj.accept();
obj.calculate();
obj.print();
}
}