1 Attachment(s)
[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:
Attachment 834
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 >= 1 && 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
Re: [Help] Java Project: Electricity Bill
Quote:
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.
Re: [Help] Java Project: Electricity Bill
Quote:
Originally Posted by
Norm
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
Re: [Help] Java Project: Electricity Bill
Quote:
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.
Re: [Help] Java Project: Electricity Bill
Quote:
Originally Posted by
Norm
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
Re: [Help] Java Project: Electricity Bill
Quote:
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.
Re: [Help] Java Project: Electricity Bill
Quote:
Originally Posted by
Norm
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
Re: [Help] Java Project: Electricity Bill
What does the variable: Service contain?
Re: [Help] Java Project: Electricity Bill
check the attached file project_one.doc in first post and see the table
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?
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 >= 1 && 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;
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.
Re: [Help] Java Project: Electricity Bill
Quote:
Originally Posted by
Norm
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
Re: [Help] Java Project: Electricity Bill
Quote:
how to switch between them based on the user choice
Use an if statement.
Re: [Help] Java Project: Electricity Bill
Quote:
Originally Posted by
Norm
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 ?
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?
Re: [Help] Java Project: Electricity Bill
Quote:
Originally Posted by
Norm
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