Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- class EB
- {
- int consumerno;
- String consumername;
- int prev_month_reading;
- int curr_month_reading;
- int type_EB_connection;
- int usage;
- double billamount=0;
- void display()
- {
- System.out.println("Consumer No"+" "+consumerno);
- System.out.println("Consumer Name"+" "+consumername);
- System.out.println("EB usage"+" "+usage);
- System.out.println("Amount to be paid"+" "+billamount);
- }
- }
- public class EBBill {
- public static void main(String[] args) {
- EB e=new EB();
- Scanner s=new Scanner(System.in);
- System.out.println("Enter the consumer number");
- e.consumerno=s.nextInt();
- System.out.println("Enter the consumer name");
- e.consumername=s.next();
- System.out.println("Enter the previous month reading in units");
- e.prev_month_reading=s.nextInt();
- System.out.println("Enter the current month reading in units");
- e.curr_month_reading=s.nextInt();
- System.out.println("Enter the type of EB Connection press 1 or 2.... 1.domestic 2.commercial");
- e.type_EB_connection=s.nextInt();
- e.usage =e.curr_month_reading-e.prev_month_reading;
- e.billamount=0;
- switch(e.type_EB_connection)
- {
- case 1:
- if(e.usage<=100)
- {
- e.billamount=e.usage*1;
- e.display();
- }
- else if(e.usage>100 & e.usage<=200)
- {
- e.billamount=e.usage*2.50;
- e.display();
- }
- else if(e.usage>200 & e.usage<=500)
- {
- e.billamount=e.usage*4;
- e.display();
- }
- else
- {
- e.billamount=e.usage*6;
- e.display();
- }
- break;
- case 2:
- if(e.usage<=100)
- {
- e.billamount=e.usage*2;
- e.display();
- }
- else if(e.usage>100 & e.usage<=200)
- {
- e.billamount=e.usage*4.50;
- e.display();
- }
- else if(e.usage>200 & e.usage<=500)
- {
- e.billamount=e.usage*6;
- e.display();
- }
- else
- {
- e.billamount=e.usage*7;
- e.display();
- }
- break;
- default:
- System.out.println("Type of Connection is in valid.");
- System.out.println("Enter the type of EB Connection press 1 or 2.... 1.domestic 2.commercial");
- }
- }
- }
Add Comment
Please, Sign In to add comment