Page 278 - CA_Blue( J )_Class10
P. 278
Program 5 Define a class Bill as described below:
Data members
name : to store the name of the consumer
cons_no : to store the consumer number
unit : to store the unit consumed
bill : total amount to be paid
Member methods
accept() : to read the data of a person
cal() : to calculate the bill amount as per criteria.
Units Consumed Rate
Up to 100 units 1.50/unit
Next 100 units 2.50/unit
Next 200 units 3.50/unit
Above 400 units 4.00/unit
Display() : to display the output as per the format:
Consumer Name Consumer No Unit Consumed Bill Amount
– – – –
1 import java.util.*;
2 class Bill
3 {
4 String name;
5 long cons_no;
6 int unit ;
7 double bill;
8 void accept()
9 {
10 Scanner sc=new Scanner(System.in);
11 System.out.println("Enter the name:");
12 name=sc.next();
13 System.out.println("Enter the consumer no.:");
14 cons_no=sc.nextLong();
15 System.out.println("Enter the unit consumed:");
16 unit=sc.nextInt();
17 }
18 void cal()
19 {
20 if(unit<=100)
21 bill=unit*1.5;
276276 Touchpad Computer Applications-X

