Friday, December 3, 2010

BlueJ programs on electric bill and customer bill


It is observed from different ICSE Computer Application papers of previous years  that one program on 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

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 the payable amount to be displayed.

About the program

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 100units are charged at the rate of Rs. 1 per unit
On remaining units, the first 100units 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 payable amount to be displayed.

About the 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 function ‘public static void main(String args[])’ from the coding.

12 comments:

  1. wap to accept a no. from the keyboard and display the sum even digit present in this no.

    ReplyDelete
  2. import java.io.*;
    public class stack
    {
    int n,c=0,x;
    BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
    public void take() throws IOException
    {
    System.out.println("Enter number : ");

    n=Integer.parseInt(br.readLine());


    while(n>0)
    {
    x=n%10;
    if(x%2==0)
    c=c+x;
    n=n/10;
    }
    System.out.println("Sum of even digits:"+c);
    }
    }

    ReplyDelete
  3. wap to accept two no.s and swap it

    ReplyDelete
  4. import java.io.*;
    class S
    {
    BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
    int a,b;
    public void take()throws Exception
    {
    System.out.println("Enter 1st Number:");
    a=Integer.parseInt(br.readLine());
    System.out.println("Enter 2nd Number:");
    b=Integer.parseInt(br.readLine());
    a=a+b;
    b=a-b;
    a=a-b;
    System.out.println("Now 1st number="+a+ " and 2nd number="+b);
    }
    }

    ReplyDelete
  5. wap to convert entered no. into words.( at least three digits).

    ReplyDelete
  6. import java.io.*;
    public class Word
    {
    int n,h,t,u;
    String s1[]={"One Hundred","Two Hundred","Three Hundred","Four Hundred","Five Hundred","Six Hundred","Seven Hundred","Eight Hundred","Nine Hundred"};
    String s2[]={"Ten","Eleven","Twelve","Thirteen","Fourteen","Fifteen","Sixteen","Seventeen","Eighteen","Nineteen"};
    String s3[]={"Twenty","Thirty","Fourty","Fifty","Sixty","Seventy","Eighty","Ninety"};
    String s4[]={"One","Two","Three","Four","Five","Six","Seven","Eight","Nine"};
    BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
    public void take() throws IOException
    {
    System.out.println("Enter number : ");
    n=Integer.parseInt(br.readLine());
    h=n/100;
    System.out.print(s1[h-1]+ " ");
    t=n%100;
    u=t%10;
    t=t/10;
    if(t==1)
    System.out.print(s2[t-1]+ " ");
    else
    {
    System.out.print(s3[t-2]+ " ");
    if(u!=0)
    System.out.print(s4[u-1]+ " ");
    }
    }
    public static void main(String args[])throws Exception
    {
    Word ob=new Word();
    ob.take();
    }
    }

    ReplyDelete
  7. wap to print the sum of the series.

    (1)^3 + (2)^3 + (3)^3 + -------(n)^3

    ReplyDelete
  8. import java.io.*;
    public class Series
    {
    int sum=0;
    int i,n;
    BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
    public void take() throws IOException
    {
    System.out.println("Enter the value of 'n' : ");
    n=Integer.parseInt(br.readLine());
    for(i=1;i<=n;i++)
    {
    sum=sum+(int)Math.pow(i,3);
    }
    System.out.println("Sum of the series="+sum);
    }
    public static void main(String args[])throws Exception
    {
    Series ob=new Series ();
    ob.take();
    }
    }

    ReplyDelete
  9. Wap to input a String and print frequency of each character of the string.

    ReplyDelete
  10. Please check the program posted on December 18 2011.

    ReplyDelete
  11. wap to check for smith number

    ReplyDelete

Subscribe via email

Enter your email address:

Delivered by FeedBurner