hi, so im new to java, fresh off the c++ shores (what a nightmare programing is :p) and i have what should be a really simple assignment
1. The electicity accounts of residents in a very small town are calculated as follows:
* If 500 units or less are used the cost is 2 cents per unit;
* If more than 500, but not more than 1000 units are used , the cost is $10 for the first 500 units , and then 5 cents for every unit in excess of 500;
* If more than 1000 units are used, the cost is $35 for the first 1000 units plus 10 cents for every unit in excess of 1000.
* In addition, a basic service fee of $5 is charged, no matter how much eletricity is used.
Write program which reads any five consumptions from keaboard and uses for loop to calculate and display the total charge for each one. For example
If data is 200 500 700 1000 1500, the answers will be $9, $15, $25, $40,$90.
so i coded it out and all, but the math just doesnt make sense, like its not adding up to what it should be -_-
i thought maybe it had something to do with my 3 if statements, but when i tried doing else if or just plain else eclipse yelled at me, is there some hidden java secret im missing?
import java.util.Scanner;
public class Homework1
{
public Homework1()
{
}
public static void main(String[] args)
{
double v1, total;
Scanner keyboard = new Scanner(System.in);
for(int i = 0; i < 5; i++)
{
System.out.println("Enter the number of units of electricity used");
v1 = keyboard.nextInt();
if (v1 < 500);
total = ((v1 * .02) + 5);
if (v1 > 500);
total = (v1 - 500) * .05 + 15;
if (v1 > 1000);
total = (v1 - 1000) * .10 + 40;
System.out.print("Your total is: ");
System.out.println(total);
}
}
}