Wednesday, February 23, 2011

BlueJ programs on electric bill and customer bill

BlueJ programs on electric bill and customer bill

It is observed from different ICSE Computer Application papers of previous years that one program on either electric bill or customer bill using else if ladder can be expected in ICSE 2011 Computer examination. Two types of such program are given below.

The first program is a simple one.

Details of the program on customer bill



A customer purchase items from a shop and if the purchase amount exceeds or equals to Rs. 5000, then the discount is applicable.
The slabs of discount are as follows:
Purchase amount >=5000 and <7000 – Discount is 2% on purchase
Purchase amount >=7000 and <10000 – Discount is 2.5% on purchase
Purchase amount above 10000 – Discount is 2.75% on purchase

Here in this program we have to take the amount of purchase from user and display the customer bill.

How to proceed on the program of customer bill



We will simply check the block where the purchase amount fits and the discount amount will be deducted from the purchased amount.


import java.io.*;
class bill
{
double payable ,purchase;
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
public void takeAmount()throws IOException
{
System.out.println("Enter the purchased amount");
purchase=Double.parseDouble(br.readLine().trim());
}
public void dispBill()
{
if(purchase>=5000)
{
if(purchase<=7000)
{
payable=purchase-purchase*2/100;
}
else if(purchase<=10000)
{
payable=purchase-purchase*2.5/100;
}
else
{
payable=purchase-purchase*2.75/100;
}
}
else
payable=purchase;
System.out.println("payable amount="+payable);
}
public static void main(String args[])throws IOException
{
bill ob=new bill();
ob.takeAmount();
ob.dispBill();
}
}




The second BlueJ program is little bit difficult. This program is on calculating electric bill of a customer.

Details of the program



Monthly rent of electricity is Rs.200.00 and 50 units per month is free.
On remaining units consumed first 100 units are charged at the rate of Rs. 1 per unit
On remaining units, the first 100 units are charged at the rate of Rs. 1.5 per unit
The rest units are charged at the rate of Rs. 2 per unit

Here in this program we have to take the units consumed from user and the electric bill of the customer will be displayed.

How to proceed in this electric bill program



This program needs lots of care. Firstly the rent is fixed and a customer has to pay it whatever may be the units consumed. If the units exceed 50 units then only calculations are required and in such case 50 to be deducted from total units. (50 units is free). For first 100 units or the remaining units – which is less, is multiplied by the rate per unit. If the units are less than 100 then ‘unit’ variable is reinitialized with -1 so that the last ‘if(unit>0)’ statement is not encountered. This process is carried out in all the if and else.


import java.io.*;
class Electric
{
double payable=200;
int unit;
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
public void takeAmount()throws IOException
{
System.out.println("Enter the Units consumed");
unit=Integer.parseInt(br.readLine().trim());
}
public void dispBill()
{
if(unit>50)
{
unit=unit-50;
if(unit>100)
{
payable=payable+100*1;
unit=unit-100;
}
else
{
payable=payable+unit*1;
unit=-1;
}
if(unit>100)
{
payable=payable+100*1.5;
unit=unit-100;
}
else
{
payable=payable+unit*1.5;
unit=-1;
}

if(unit>0)
{
payable=payable+unit*2;
}
}
System.out.println("payable amount="+payable);
}
public static void main(String args[])throws IOException
{
Electric ob=new Electric();
ob.takeAmount();
ob.dispBill();
}
}


In case of both the programs if you are using BlueJ editor to execute these programs, remove the method ‘public static void main(String args[])’ from the coding.

1 comment: