Computer Science, asked by saarya8887, 4 months ago

write a program in java to accept the total units consumed by a customer and calculate the bill, if the electricity board charges the bill according to the number of units consumed:
First 100 units- 80 paisa per unit.
Next 200 units- Rs 1 per unit.
Above 300 units- Rs 2.50 per unit.​

Answers

Answered by kamalrajatjoshi94
19

Answer:

import java.util.*;

public class Bill

{

public static void main(String args[ ])

{

Scanner in=new Scanner(System.in);

int units;

String name;

double bill=0.0;

System.out.println("Enter the name of the consumer");

name=in.nextLine();

System.out.println("Enter the units consumed");

units=in.nextInt();

if(units<=100)

{

bill=unit*0.80;

}

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

{

bill=(100 * 10) + (units-200) *1;

}

else if(units>300)

{

bill=(100 * 0.8) + (100 * 1) + (units - 200)* 2.5;

}

System.out.println("Name of consumer:"+name);

System.out.println("Units consumed="+units);

System.out.println("The total bill consumed by the customer="+bill);

}

}

(Note I wrote 0.8,as 1 rupee=100 paisa)

Similar questions