# Help! electricity bill project

Printable View

• January 30th, 2014, 06:21 PM
michaels91
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.
• January 30th, 2014, 06:41 PM
Norm
Re: Help! electricity bill project
What have you tried so far? Please post your code.

Quote:

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?
• January 31st, 2014, 04:31 AM
GregBrannon
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.
• January 31st, 2014, 04:45 PM
michaels91
Re: Help! electricity bill project
Quote:

Originally Posted by Norm
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
• January 31st, 2014, 06:19 PM
Norm
Re: Help! electricity bill project
Start with one combination. Write the code and test it to see what happens.
• January 31st, 2014, 08:28 PM
michaels91
Re: Help! electricity bill project
alright right now I have the dialogue for the program but I cant figure out the math and variables...
• January 31st, 2014, 08:35 PM
Norm
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?
• January 31st, 2014, 08:55 PM
michaels91
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...
• January 31st, 2014, 11:08 PM
GregBrannon
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.
• February 1st, 2014, 02:48 AM
michaels91
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!
Code Java:

```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: " );   }   }```
• February 1st, 2014, 03:31 AM
GregBrannon
Re: Help! electricity bill project
Quote:

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.
• February 1st, 2014, 03:48 AM
michaels91
Re: Help! electricity bill project
Thanks, Greg. I'll try the if statements
simple date format = SDF
one example:
Code Java:

```//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
Code Java:

```System.out.print("meter reading date (mm/dd/yyyy) > "); String date =scan.nextLine();```
• February 1st, 2014, 04:07 AM
GregBrannon
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.
• February 1st, 2014, 07:09 PM
michaels91
Re: Help! electricity bill project
Quote:

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!
• February 2nd, 2014, 03:27 AM
GregBrannon
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.
• February 7th, 2014, 12:18 PM
derekxec
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