import java.util.*;
public class lab9
{
public static void main(String args[])
{
Scanner input = new Scanner( System.in );
final double BONUS0 = 0.0;
final double BONUS1 = 25.0;
final double BONUS2 = 50.0;
final double BONUS3 = 100.0;
final double BONUS4 = 200.0;
System.out.println("Enter employee's first name:");
String firstName;
System.out.println("Enter employee's last name:");
String lastName;
System.out.println("Enter this year's units:");
int unitsThisYear;
System.out.println("Enter last year's units:");
int unitsLastYear;
double bonus;
{
if ((unitsThisYear > unitsLastYear) && (unitsThisYear < 1000))
{
bonus = BONUS1;
System.out.println("Bonus is $" +bonus);
}
else if ((unitsThisYear > unitsLastYear) && (unitsThisYear > 1001) && (unitsThisYear < 3000))
{
bonus = BONUS2;
System.out.println("Bonus is $" +bonus);
}
else if ((unitsThisYear > unitsLastYear) && (unitsThisYear > 3001) && (unitsThisYear < 6000))
{
bonus = BONUS3;
System.out.println("Bonus is $" +bonus);
}
else if ((unitsThisYear > unitsLastYear) && (unitsThisYear > 6001))
{
bonus = BONUS4;
System.out.println("Bonus is $" +bonus);
}
else
{
bonus = BONUS0;
System.out.println("Bonus is $" +bonus);
}
}
}//end main
}//end class
I kept getting an error of else without if but i manages to fix it but now I'm getting the error of not initializing the varible. I dont understand why it keeps saying that the variable unitsThisYear and unitsLastYear are not initialzed. I thought I initialized it with the lines: int unitsThisYear; int unitsLastYear;
lab9.java:25: error: variable unitsThisYear might not have been initialized
if ((unitsThisYear > unitsLastYear) && (unitsThisYear < 1000))
^
lab9.java:25: error: variable unitsLastYear might not have been initialized
if ((unitsThisYear > unitsLastYear) && (unitsThisYear < 1000))
^
Aucun commentaire:
Enregistrer un commentaire