Use app×
Join Bloom Tuition
One on One Online Tuition
JEE MAIN 2026 Crash Course
NEET 2026 Crash Course
CLASS 12 FOUNDATION COURSE
CLASS 10 FOUNDATION COURSE
CLASS 9 FOUNDATION COURSE
CLASS 8 FOUNDATION COURSE
0 votes
1.5k views
in Computer by (49.9k points)
closed by

Define a class ElectricBill with the following specifications :

class : ElectricBill 

Instance variables /data member : 

String n – to store the name of the customer 

int units – to store the number of units consumed 

double bill – to store the amount to be paid 

Member methods : 

void accept ( ) – to accept the name of the customer and number of units consumed 

void calculate ( ) – to calculate the bill as per the following tariff : 

A surcharge of 2.5% charged if the number of units consumed is above 300 units. 

Write a main method to create an object of the class and call the above member methods.

1 Answer

+1 vote
by (49.0k points)
selected by
 
Best answer

import java.io.*; 

class ElectricBill { 

String n; 

int units; 

double bill ; 

void accept() throws IOException { 

BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); 

System.out.print(“Name of the customer = “); 

n = reader.readLine( ); 

System.out.print( “Number of units consumed = “); 

String un = reader. readLine( ); 

units=Integer .parselnt(un); 

void calculate!) { 

if(units < = 100) 

bill = 2.00*units; 

if(units< =300) bill = 3.00*units;

if (units > 300) bill = 5.00*units; 

void print( ) { 

System.out.println(“Naine of the customer:” +n); 

System.out.println(“Number of units consumed:” +units); 

System.out.println(“Bill amount:” + bill); 

public static void main(String argsQ) throws IO 

Exception { ElectricBill eb = new ElectricBill( ); 

eb. accept!); 

eb.calculate(); 

}

Welcome to Sarthaks eConnect: A unique platform where students can interact with teachers/experts/students to get solutions to their queries. Students (upto class 10+2) preparing for All Government Exams, CBSE Board Exam, ICSE Board Exam, State Board Exam, JEE (Mains+Advance) and NEET can ask questions from any subject and get quick answers by subject teachers/ experts/mentors/students.

Categories

...