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 16 of 16

Thread: Help! electricity bill project

  1. #1
    Junior Member
    Join Date
    Jan 2014
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Help! electricity bill project

    Hello!
    I need help with this project below. I am not sure how to incorporate the rate per month and the three rate zones. Ive spent so much time and I seem to get no where! I am new to java, thanks for your time!

    Problem: Electricity billing charges vary with the season and amount used.

    Southwest Power and Light provides electricity at the basic rate of $ 0.10 per kilowatt for the
    months December through February, 0.12 per kilowatt for the months of March through May, and
    0.15 per kilowatt for the remaining months.

    Customer billing is divided into three rate zones: 0-350 kilowatts, 351 – 500 kilowatts, and above
    500 kilowatts. Usage up to 350 kilowatts is billed at the basic rate. Usage between 350 and 500
    kilowatts is billed at 10% above the basic rate. Above 500, billing is 25% above the basic rate.
    These surcharges apply only to the usage falling within the respective rate zone.


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,165
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Help! electricity bill project

    What have you tried so far? Please post your code.

    how to incorporate the rate per month
    You need to know what month the bill is for to set the rates. How is the month specified?
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,517
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: Help! electricity bill project

    Welcome to the Forum! Please read this topic to learn how to post your code correctly along with other useful info for newcomers.

  4. #4
    Junior Member
    Join Date
    Jan 2014
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Help! electricity bill project

    Quote Originally Posted by Norm View Post
    What have you tried so far? Please post your code.


    You need to know what month the bill is for to set the rates. How is the month specified?

    I need to show 10 different ones with all the possible combinations

  5. #5
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,165
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Help! electricity bill project

    Start with one combination. Write the code and test it to see what happens.
    If you don't understand my answer, don't ignore it, ask a question.

  6. #6
    Junior Member
    Join Date
    Jan 2014
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Help! electricity bill project

    alright right now I have the dialogue for the program but I cant figure out the math and variables...

  7. #7
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,165
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Help! electricity bill project

    Can you do the math on paper? The instructions seem simple enough.

    What would be the cost of 400 kw used in February?
    If you don't understand my answer, don't ignore it, ask a question.

  8. #8
    Junior Member
    Join Date
    Jan 2014
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Help! electricity bill project

    I know how to do the math its just doing it in java with variables is hard I am always overlapping variables or messing it up somehow...

  9. #9
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,517
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: Help! electricity bill project

    Show the Java version of the equations you've tried, the ones with "overlapping variables," and maybe we can help you fix those.

  10. #10
    Junior Member
    Join Date
    Jan 2014
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Help! electricity bill project

    Ok, here is what I have so far. Sorry it took so long working 40 hrs a week + school is brutal!
    public class MDKProject1Zip {
     
     
     
        public static void main(String[] args) {
     
     
     
            //input dialog
            System.out.println("Southwest Power and Light ");
            System.out.println("Electric Utility Charges");
             System.out.print("Please enter your name(Last, First) >");
             Scanner scan = new Scanner(System.in);
            String name =scan.nextLine();
            System.out.print("meter reading date (mm/dd/yyyy) > ");
            String date =scan.nextLine();
            System.out.print("Enter electricity used (KW) > ");
            double kw =scan.nextDouble();
     
            /* NOT DONE (uhhh how do i do this using SDF)
            if month is between Jan and Feb the rate is $0.10/kw
            if month is between March and May the rate is $0.12/kw
            if month is between April to Dec. the rate is $.015/kw
     
     
            */
            double KwTier2 = (350-kw);
            double KwTier3 = (500-kw);
     
           double rateTier1 =  kw * 1;
           double rateTier2 = (KwTier2)*.1;
           double rateTier3 = (KwTier3)*.25;
     
            double chargeTier1 = rateTier1;
            double chargeTier2 = KwTier2 * rateTier2;
            double chargeTier3 = KwTier3 * rateTier3;
     
          /*not done
            double BaseCharge =0;
            double OverBaseCharge =0;
            double ExcessCharge = 0;
            double Total =0;
            */
     
            System.out.println("Name: " +name);
            System.out.println("Meter reading date:" +date);
            System.out.println("Electricity used (KW): " +kw);
     
            System.out.println("Baseline Charge: " );
            System.out.println("Over baseline Charge:" );
            System.out.println("Excess Charge: ");
            System.out.println("Total amount due: " );
     
        }
     
    }

  11. #11
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,517
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: Help! electricity bill project

    how do i do this using SDF
    What's SDF? An approach would be to use a number of 'if' statements that set the correct rate based on the meter reading date.

  12. #12
    Junior Member
    Join Date
    Jan 2014
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Help! electricity bill project

    Thanks, Greg. I'll try the if statements
    simple date format = SDF
    one example:
    //Get the current date from the system clock
            Date now = new Date();
     
            SimpleDateFormat sdf = new SimpleDateFormat ("MMMM,d,yyyy h:m:ss a");
            System.out.println(sdf.format(now));

    but actually i dont think i need to use that, that would just be making things more complicated...
    How can i use the if statement to recognize only the numbers of the month in my string date?
    from
    System.out.print("meter reading date (mm/dd/yyyy) > ");
            String date =scan.nextLine();

  13. #13
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,517
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: Help! electricity bill project

    Ah, the acronym sounded familiar, but I couldn't pull it, and using an SDF is not a bad way to go.

    Alternatively, if the date is entered correctly, the mm, dd, and yyyy parts can be easily separated by using String methods. If you're familiar with arrays, the split() method might do. Otherwise, pull the parts needed from the String using substrings.

  14. #14
    Junior Member
    Join Date
    Jan 2014
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Help! electricity bill project

    Quote Originally Posted by GregBrannon View Post
    Ah, the acronym sounded familiar, but I couldn't pull it, and using an SDF is not a bad way to go.

    Alternatively, if the date is entered correctly, the mm, dd, and yyyy parts can be easily separated by using String methods. If you're familiar with arrays, the split() method might do. Otherwise, pull the parts needed from the String using substrings.
    could you show me an example of any of those ways? preferably the easiest one, im new thanks!

  15. #15
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,517
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: Help! electricity bill project

    Being new isn't an excuse for not reading the String API and learning how to use the split() and/or substring() methods. In fact, it's the reason I'm not going to do it for you. Read the String API and about those methods I've suggested. Then review the SimpleDateFormat API and the examples provided for that. You determine which is 'easiest' for you and decide which approach to use. Come back after you've made your decision and have written some code that you need help with.

  16. #16
    Member
    Join Date
    May 2011
    Location
    west palm beach, FL
    Posts
    189
    My Mood
    Tired
    Thanks
    41
    Thanked 11 Times in 10 Posts

    Default Re: Help! electricity bill project

    to make it a bit easier it doesn't say in your original post that it needs the day or year so you could just ask for the month. you will be testing what month it is and using that to determine the cost so day and year are irrelevant

Similar Threads

  1. electricity bill on java
    By rajasingh1 in forum Member Introductions
    Replies: 2
    Last Post: March 1st, 2013, 01:07 AM
  2. [SOLVED] [Help] Java Project: Electricity Bill
    By deathpain in forum Java Theory & Questions
    Replies: 16
    Last Post: November 7th, 2011, 02:39 PM
  3. Project - Please Help
    By toxikbuni in forum Java Theory & Questions
    Replies: 0
    Last Post: April 20th, 2010, 09:58 AM