Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 17 of 17

Thread: [Help] Java Project: Electricity Bill

  1. #1
    Junior Member
    Join Date
    Nov 2011
    Posts
    17
    My Mood
    Daring
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Question [Help] Java Project: Electricity Bill

    Hi Guys,
    this is my first post at this great forum
    i need help making an electricity bill based on a table i have which is kinda complicated for a java beginner programmer.
    here is the project details:
    Project_one.doc
    and this is what i've done so far:
    PHP Code:
    import java.util.*;
    /*
     * To change this template, choose Tools | Templates
     * and open the template in the editor.
     */

    /**
     *
     * @author deathpa1N
     */
    public class Abdulkareem_1113065 {

        
    /**
         * @param args the command line arguments
         */
        
    public static void main(String[] args) {
        
    String Name null
        
    short Service;
        
    Long Account;
        
    int billNum;
        
    int OldMtrRdng;
        
    int NewMtrRdng;
        
    String Month;
        
    double unpaid;
        
    double currentblnc;
        
    double otherchrgs;
        
    int Total;
        
    int RatePerUnit;
     
        
        
    Scanner in1=new Scanner(System.in);
        
    System.out.println("Enter name of owner Name of Apartment or Flat or Shop:");
        
    Name in1.next();
        
    Scanner in2=new Scanner(System.in);
        
    System.out.println("Enter 1. for Residential, 2. for Commercial, 3. for Governmental,  4. for Agricultural, 5. for Charities, 6. for Private educational establishments, 7.  for Private health establishments");
        
    Service in2.nextShort();
        
    Scanner in3=new Scanner(System.in);
        
    System.out.println("Enter account Number:");
        
    Account in3.nextLong();
        
    Scanner in4=new Scanner(System.in);
        
    System.out.println("Enter Bill Number:");
        
    billNum in4.nextInt();
        
    Scanner in5=new Scanner(System.in);
        
    System.out.println("Enter Old Meter Reading:");
        
    OldMtrRdng in5.nextInt();
        
    Scanner in6=new Scanner(System.in);
        
    System.out.println("Enter New Meter Reading:");
        
    NewMtrRdng in6.nextInt();
        
    Scanner in7=new Scanner(System.in);
        
    System.out.println("Enter Bill Month:");
        
    Month in7.next();
        
    Scanner in8=new Scanner(System.in);
        
    System.out.print("Enter any unpaid balance:");
        
    unpaid in8.nextDouble();
        
    Scanner in9=new Scanner(System.in);
        
    System.out.println("Enter any other charges:");
        
    otherchrgs in9.nextDouble();
        
    Total NewMtrRdng-OldMtrRdng;
        if (
    Total >= && Total <=1000)
        
    RatePerUnit=5;
        else if (
    Total >= 1001 && Total <=2000)
        
    RatePerUnit=5;
        else if (
    Total >= 2001 && Total <=3000)
        
    RatePerUnit=10;
        else if (
    Total >= 3001 && Total <=4000)
        
    RatePerUnit=10;
        else if (
    Total >= 4001 && Total <=5000)
        
    RatePerUnit=12;
        else if (
    Total >= 5001 && Total <=6000)
        
    RatePerUnit=12;
        else if (
    Total >= 6001 && Total <=7000)
        
    RatePerUnit=15;
        else if (
    Total >= 7001 && Total <=8000)
        
    RatePerUnit=20;
        else if (
    Total >= 8001 && Total <=9000)
        
    RatePerUnit=22;
        else if (
    Total >= 9001 && Total <=10000)
        
    RatePerUnit=24;
        else if (
    Total 10000)
        
    RatePerUnit=26
    any ideas on how to let java take a rate between 1-1000 and 1001-2000 and so on ..
    based on the service the user choose ( Commercial, Residental, etc. ) how can i put the consumption rate of each one of them.
    Sorry for my bad english
    Last edited by deathpain; November 7th, 2011 at 11:53 AM.


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    18,662
    Thanks
    45
    Thanked 1,960 Times in 1,934 Posts

    Default Re: [Help] Java Project: Electricity Bill

    how to let java take a rate between 1-1000 and 1001-2000 and so on ..
    Use an if statement with the condition specifying the range of values. Something like:
    if(x > 3 && x < 10) { ...

    Your chained if /else if statements should also work.

    Print out the value of the rate after the if tests to see if it has the correct value.

  3. #3
    Junior Member
    Join Date
    Nov 2011
    Posts
    17
    My Mood
    Daring
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: [Help] Java Project: Electricity Bill

    Quote Originally Posted by Norm View Post
    Use an if statement with the condition specifying the range of values. Something like:
    if(x > 3 && x < 10) { ...

    Your chained if /else if statements should also work.

    Print out the value of the rate after the if tests to see if it has the correct value.
    thanks man ,,
    and the other thing
    as u can see in the attached file there is a table on how kwh consumption is calculated,,
    for each service there is a consumption rate
    for example at 4001-5000 kwh the consumption rate for Residential is 12 but for Commercial is 20..
    so it's up to the user to choose Residential or Commercial
    how can i let java take rates of each based on user choice

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    18,662
    Thanks
    45
    Thanked 1,960 Times in 1,934 Posts

    Default Re: [Help] Java Project: Electricity Bill

    how can i let java take rates of each based on user choice
    I don't know how your program determines what the user has chosen.
    You will need to get and save that information so you can use it later to determine what equation to use to compute the bill.

  5. #5
    Junior Member
    Join Date
    Nov 2011
    Posts
    17
    My Mood
    Daring
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: [Help] Java Project: Electricity Bill

    Quote Originally Posted by Norm View Post
    I don't know how your program determines what the user has chosen.
    You will need to get and save that information so you can use it later to determine what equation to use to compute the bill.
    i know how to compute the bill but i don't know how to let java take ( Residential Rates or Commercial Rates ) i don't know how to save it as a statement in java

  6. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    18,662
    Thanks
    45
    Thanked 1,960 Times in 1,934 Posts

    Default Re: [Help] Java Project: Electricity Bill

    how to save it as a statement in java
    Define a variable and assign it the value:
    final int ResRate = 123.4;
    final int ComRate = 234.5;

    Then use the variable in the formula to compute the bill.

  7. #7
    Junior Member
    Join Date
    Nov 2011
    Posts
    17
    My Mood
    Daring
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: [Help] Java Project: Electricity Bill

    Quote Originally Posted by Norm View Post
    Define a variable and assign it the value:
    final int ResRate = 123.4;
    final int ComRate = 234.5;

    Then use the variable in the formula to compute the bill.
    it doesn't have a final rate ,,
    check the file i attached to get the point

  8. #8
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    18,662
    Thanks
    45
    Thanked 1,960 Times in 1,934 Posts

    Default Re: [Help] Java Project: Electricity Bill

    What does the variable: Service contain?

  9. #9
    Junior Member
    Join Date
    Nov 2011
    Posts
    17
    My Mood
    Daring
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: [Help] Java Project: Electricity Bill

    check the attached file project_one.doc in first post and see the table

  10. #10
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    18,662
    Thanks
    45
    Thanked 1,960 Times in 1,934 Posts

    Default Re: [Help] Java Project: Electricity Bill

    Can you copy the relevant parts into your program so it can be seen as part of your posting on this thread?

  11. #11
    Junior Member
    Join Date
    Nov 2011
    Posts
    17
    My Mood
    Daring
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: [Help] Java Project: Electricity Bill

    i will get u to the point,,
    if the user put the service on Residential
    this will be the Rates:
    PHP Code:
    if (Total >= && Total <=1000)
        
    RatePerUnit=5;
        else if (
    Total >= 1001 && Total <=2000)
        
    RatePerUnit=5;
        else if (
    Total >= 2001 && Total <=3000)
        
    RatePerUnit=10;
        else if (
    Total >= 3001 && Total <=4000)
        
    RatePerUnit=10;
        else if (
    Total >= 4001 && Total <=5000)
        
    RatePerUnit=12;
        else if (
    Total >= 5001 && Total <=6000)
        
    RatePerUnit=12;
        else if (
    Total >= 6001 && Total <=7000)
        
    RatePerUnit=15;
        else if (
    Total >= 7001 && Total <=8000)
        
    RatePerUnit=20;
        else if (
    Total >= 8001 && Total <=9000)
        
    RatePerUnit=22;
        else if (
    Total >= 9001 && Total <=10000)
        
    RatePerUnit=24;
        else if (
    Total 10000)
        
    RatePerUnit=26
    The RatePerUnit is changed when the user choose Commercial so the value can't be permanent ,
    for example;
    if (Total >= 1 && Total <=1000)
    RatePerUnit=5 for Residential
    but for Commercial:
    if (Total >= 1 && Total <=1000)
    RatePerUnit=12;

  12. #12
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    18,662
    Thanks
    45
    Thanked 1,960 Times in 1,934 Posts

    Default Re: [Help] Java Project: Electricity Bill

    If you have two sets of rates then you need logic for each rate. You have posted the logic for the Residential.
    Now you need logic for the Commerical.

    If the two rate schedules have the same ranges of KWHs used, you might be able to use an array to get the rates from vs hardcoding them in the logic as you have done above. Use logic similar to what you have above to find what range of KWHs were used and save that info as an index into an array. Have two arrays: one for Residential and one for Commerical. Use the index to get the rate from the array.

  13. #13
    Junior Member
    Join Date
    Nov 2011
    Posts
    17
    My Mood
    Daring
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: [Help] Java Project: Electricity Bill

    Quote Originally Posted by Norm View Post
    If you have two sets of rates then you need logic for each rate. You have posted the logic for the Residential.
    Now you need logic for the Commerical.

    If the two rate schedules have the same ranges of KWHs used, you might be able to use an array to get the rates from vs hardcoding them in the logic as you have done above. Use logic similar to what you have above to find what range of KWHs were used and save that info as an index into an array. Have two arrays: one for Residential and one for Commerical. Use the index to get the rate from the array.
    i don't know to do arrays we didn't take these yet, is there an another way to do it ?
    i have finished the logic for the 7 sets i have in the table but i don't know how to switch between them based on the user choice

  14. #14
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    18,662
    Thanks
    45
    Thanked 1,960 Times in 1,934 Posts

    Default Re: [Help] Java Project: Electricity Bill

    how to switch between them based on the user choice
    Use an if statement.

  15. #15
    Junior Member
    Join Date
    Nov 2011
    Posts
    17
    My Mood
    Daring
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: [Help] Java Project: Electricity Bill

    Quote Originally Posted by Norm View Post
    Use an if statement.
    1. for Residential, 2. for Commercial, 3. for Governmental, 4. for Agricultural, 5. for Charities, 6. for Private educational establishments, 7. for Private health establishments,

    if (Service==1)
    then i put the rates ?
    can u show me the way ?

  16. #16
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    18,662
    Thanks
    45
    Thanked 1,960 Times in 1,934 Posts

    Default Re: [Help] Java Project: Electricity Bill

    You need to repeat the code you posted in #11 above for the Commerical.
    pseudo code:
    if (residential) {
    code from post #11
    }else if (commerical){
    code from post #11 modified for Commerical
    }else if(government) {
    ... more of the same
    } .... more of the same

    As you can see this will be a lot of repeated code. This a natural place to use arrays. But you say that will come later in your lessons.

    What techniques has your teacher given you that you can use here?

  17. The Following User Says Thank You to Norm For This Useful Post:

    deathpain (November 7th, 2011)

  18. #17
    Junior Member
    Join Date
    Nov 2011
    Posts
    17
    My Mood
    Daring
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: [Help] Java Project: Electricity Bill

    Quote Originally Posted by Norm View Post
    You need to repeat the code you posted in #11 above for the Commerical.
    pseudo code:
    if (residential) {
    code from post #11
    }else if (commerical){
    code from post #11 modified for Commerical
    }else if(government) {
    ... more of the same
    } .... more of the same

    As you can see this will be a lot of repeated code. This a natural place to use arrays. But you say that will come later in your lessons.

    What techniques has your teacher given you that you can use here?
    he taught us that repeated actions can be done by if statements only
    and thanks man ,, u're awesome i know how to do it now
    Last edited by deathpain; November 7th, 2011 at 01:44 PM.

Similar Threads

  1. Java Project
    By ask2001 in forum Paid Java Projects
    Replies: 11
    Last Post: February 12th, 2011, 12:20 AM
  2. Replies: 0
    Last Post: August 30th, 2010, 07:34 AM
  3. Replies: 2
    Last Post: August 1st, 2010, 06:29 AM
  4. [SOLVED] I Need some help for a java project
    By george in forum Algorithms & Recursion
    Replies: 8
    Last Post: April 24th, 2010, 11:12 AM
  5. Java project
    By monika88a in forum AWT / Java Swing
    Replies: 5
    Last Post: January 19th, 2010, 11:10 PM