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

# Thread: Help! electricity bill project

1. ## 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. ## Re: Help! electricity bill project

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?

3. ## 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. ## Re: Help! electricity bill project

Originally Posted by Norm

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. ## Re: Help! electricity bill project

Start with one combination. Write the code and test it to see what happens.

6. ## 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. ## 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?

8. ## 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. ## 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. ## 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");
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("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. ## 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. ## 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. ## 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. ## Re: Help! electricity bill project

Originally Posted by GregBrannon
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. ## 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. ## 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