8 Replies - 5764 Views - Last Post: 21 August 2013 - 02:06 AM Rate Topic: -----

#1 divyajagan  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 14
  • Joined: 12-August 13

Electricity bill calculation

Posted 13 August 2013 - 12:09 AM

i need to calculate an electricity bill(based upon monthly consumed units) using arrays concept and i should not give any ratesperunit in the program direcly.......need ur help thanks in advance
Is This A Good Question/Topic? 0
  • +

Replies To: Electricity bill calculation

#2 blackcompe  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1155
  • View blog
  • Posts: 2,533
  • Joined: 05-May 05

Re: Electricity bill calculation

Posted 13 August 2013 - 01:51 AM

And what do you expect from us? Explain what you've done and what you need help with.
Was This Post Helpful? 0
  • +
  • -

#3 divyajagan  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 14
  • Joined: 12-August 13

Re: Electricity bill calculation

Posted 13 August 2013 - 09:38 PM

View Postblackcompe, on 13 August 2013 - 01:51 AM, said:

And what do you expect from us? Explain what you've done and what you need help with.


i have given the program which i tried and gathered but in that i have given the direct values (tarriff rates which i cant change if govmt changes after 6 months)and so now am in need to do a windows appplication which should have a settings where i can change the government tarrifs.Am new to this....guide me thanks in advance...

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());
}
public void dispBill()
{
if(unit>50)
{
unit=unit-50;
if(unit>100)
{
payable=payable+100*0.70;
unit=unit-100;
}
else
{
payable=payable+unit*0.70;
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();
}
}


This post has been edited by blackcompe: 13 August 2013 - 09:47 PM
Reason for edit:: Cleanup post

Was This Post Helpful? 0
  • +
  • -

#4 blackcompe  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1155
  • View blog
  • Posts: 2,533
  • Joined: 05-May 05

Re: Electricity bill calculation

Posted 13 August 2013 - 09:50 PM

1. Format your code.
2. You have logic written, and now you need to throw a GUI around it. You need to go through the Swing tutorials.
3. I suggest using a dialog window to ask the the user for the units and the tariff. Then also use a JOptionPane to display the bill.

It's as simple as saying:

String input = JOptionPane.showInputDialog("Enter units: ");
int units = Integer.parseInt(input);


This post has been edited by blackcompe: 13 August 2013 - 09:58 PM

Was This Post Helpful? 1
  • +
  • -

#5 divyajagan  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 14
  • Joined: 12-August 13

Re: Electricity bill calculation

Posted 19 August 2013 - 10:30 PM

thanks a lot.......
Was This Post Helpful? 0
  • +
  • -

#6 g00se  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2720
  • View blog
  • Posts: 11,448
  • Joined: 20-September 08

Re: Electricity bill calculation

Posted 20 August 2013 - 06:39 AM

You'd be better off using a ResourceBundle in which to store rates - they change infrequently. This is what i use in my own domestic calculator
Was This Post Helpful? 0
  • +
  • -

#7 divyajagan  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 14
  • Joined: 12-August 13

Re: Electricity bill calculation

Posted 20 August 2013 - 08:24 PM

am sorry am new to this can you explain it
Was This Post Helpful? 0
  • +
  • -

#8 g00se  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2720
  • View blog
  • Posts: 11,448
  • Joined: 20-September 08

Re: Electricity bill calculation

Posted 21 August 2013 - 01:47 AM

http://docs.oracle.c...le/concept.html

A ResourceBundle is much the same as Properties really but is easier to load
Was This Post Helpful? 0
  • +
  • -

#9 divyajagan  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 14
  • Joined: 12-August 13

Re: Electricity bill calculation

Posted 21 August 2013 - 02:06 AM

Thankyou,will try with this.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1