CAN YOU HELP ME BY SOLVING THIS PROGRAM. | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

CAN YOU HELP ME BY SOLVING THIS PROGRAM.

Make program for Starc Electricity Department that will generate the Electricity Bill based upon the current and old meter reading of an electricity meter.The following slabs should be used to calculate the bill. 1)Fixed Meter Rental and line maintainance charge @ 250$. 2)First 100 units will be charged @ 3.25$/unit. 3)After 100 units,every unit will be charged @ 4.75$/unit. 4)Service tax of 11.5% will be added to the final bill. 5)A sum of 50$ will be charged as late fee if the bill is paid after due date.

20th Feb 2017, 6:01 PM
NiKlAuS
NiKlAuS - avatar
8 Answers
+ 4
What have you done so far? What is your problem in detail?
20th Feb 2017, 6:23 PM
Tashi N
Tashi N - avatar
+ 4
I think the task is to get the user inputs 'oldMeterReading' and 'newMeterReading'. All other values are fixed or can be calculated by the given conditions. So far so good - your program is executable. 1. I think you have to use the subtraction newMeterReading - oldMeterReading to get the units the customer has to pay. Experience from my bills ^^ 2. Then test if the resulting units > 100 and calculate the price on that condition. 3. After that your calculation is correct. 4. You can use boolean late, there are only two possible values. 5. Think about refactoring your code, some of the variable names are confusing and the structure can be improved. 6. Check if the user inputs are correct. What if the user inputs String and not double? 7. println doesn't need an additional \n to print a new line. Hopes that helps you.
20th Feb 2017, 7:32 PM
Tashi N
Tashi N - avatar
+ 4
Actually you pay your 'consumption' of power for a determined time range. You only tell your power company your new meter reading. The company knows your old meter reading, that is the value you told them a year ago. And the difference of the two values is what you consumed over that year. I think the first 100 units are actually less expensive than the units more than that, but maybe that is different in other countries to what I know.
20th Feb 2017, 7:56 PM
Tashi N
Tashi N - avatar
+ 3
Better ^^ Make the methods static, you don't need to create an object then. You don't really need it... And it must be currentunits - oldunits, no need of Math.abs then... Could only be negative if the customer turned back the meter ^^. Better check the input, old must be bigger than new.
20th Feb 2017, 8:19 PM
Tashi N
Tashi N - avatar
+ 3
Remember checking the double parsing on input. And try to mention what I wrote about the first 100 units and the units after that... Don't give up, it's getting better and better the more you think about it!
20th Feb 2017, 8:24 PM
Tashi N
Tashi N - avatar
+ 2
I have written this at night so there could be errors check if you want and let me know.Thanks
20th Feb 2017, 8:13 PM
Fahad
Fahad - avatar
+ 1
Thanks Tashi N,Seriously i never paid any bills except for school ones but isn't "First 100 units" for each of current and old ones or is it work like the way you said?
20th Feb 2017, 7:43 PM
Fahad
Fahad - avatar
+ 1
I havn't tested it alot but here you go:) import java.util.Scanner; import java.lang.Math; public class electricbill {double unitprice; double unitpricenorm=3.25; double unitpriceextra=4.75; private double total=0; public static void main(String[] args) { Scanner sc = new Scanner(System.in); System.out.println("Please type OldUnits:"); double oldUnits=sc.nextDouble(); System.out.println("Please type CurrentUnits:"); double currentUnits=sc.nextDouble(); System.out.println("Please type true if after due date otherwise false:"); boolean afterDuedate=sc.nextBoolean(); electricbillbill=new electricbill(); bill.cashCalculate(oldUnits,currentUnits,afterDuedate); } public void cashCalculate(double oldunits,double currentunits,boolean late){ currentunits=Math.abs(currentunits-oldunits); total+=unitPriceCalculate(currentunits); total+=250;//fixed_rental_line_charges total+=0.115;//Service tax of 11.5% if(late==true){ total+=50; } System.out.println("The Total is "+total+"
quot;); total=0; unitprice=0; } public double unitPriceCalculate(double units){ if (units>100){ unitprice=(units-100)*unitpriceextra; unitprice=100*unitpricenorm; }else if(units<=100){ unitprice=units*unitpricenorm; } return unitprice; } } }
20th Feb 2017, 8:12 PM
Fahad
Fahad - avatar