I keep getting the error message "else without if". It is saying the second else (else done = false;) is not connected to the if. What am I missing? I tried to enclose the whole if-else statement in "" but that didn't work. Also, I'm not asking this question to check the rest of the code, but if you see any other problems, please let me know.
// SuperMarket.java - This program creates a report that lists weekly hours worked
// by employees of a supermarket. The report lists total hours for
// each day of one week.
// Input: Interactive
// Output: Report.
import java.util.Scanner;
public class SuperMarket
{
public static void main(String args[])
{
// Declare variables.
final String HEAD1 = "WEEKLY HOURS WORKED";
final String DAY_FOOTER = " Day Total "; // Leading spaces are intentional.
final String SENTINEL = "done"; // Named constant for sentinel value.
double hoursWorked = 0; // Current record hours.
String hoursWorkedString = ""; // String version of hours
String dayOfWeek; // Current record day of week.
double hoursTotal = 0; // Hours total for a day.
String prevDay = ""; // Previous day of week.
boolean done = false; // loop control
Scanner input = new Scanner(System.in);
// Print two blank lines.
System.out.println();
System.out.println();
// Print heading.
System.out.println(HEAD1);
// Print two blank lines.
System.out.println();
System.out.println();
// Read first record
System.out.println("Enter day of week or done to quit: ");
dayOfWeek = input.nextLine();
if(dayOfWeek.compareTo(SENTINEL) == 0)
done = true;
else
{
System.out.print("Enter hours worked: ");
hoursWorkedString = input.nextLine();
hoursWorked = Integer.parseInt(hoursWorkedString);
prevDay = dayOfWeek;
}
while(done == false)
{
System.out.println("\\4.0\\6.0\\2.0Monday for " + dayTotal + "\\3.0\\2.0Tuesday for " + dayTotal + "\\3.0\\5.0\\7.0Wednesday for " + "\\5.0Thursday for " + dayTotal + "\\4.0\\3.0\\4.0Friday for " + dayTotal + "\\8.0\\8.0\\8.0Saturday for " + dayTotal + "0.0Sunday for " + dayTotal);
hoursTotal = 0;
prevDay = hoursWorked;
}
System.out.println(dayOfWeek + " " + hoursWorked + hoursTotal);
hoursTotal++;
if((dayOfWeek = dayOfWeek.compareTo(SENTINEL) == 0));
{
hoursWorked = dayOfWeek.compareTo(SENTINEL);
prevDay = dayOfWeek;
done = true;
}
else
done = false;
// Include work done in the dayChange() method
if(dayOfWeek.compareTo(SENTINEL) == 0)
System.out.println(DAY_FOOTER + "(" + prevDay + ") " + hoursTotal);
System.exit(0);
} // End of main() method.
} // End of SuperMarket class.
Thank you very much!
Aucun commentaire:
Enregistrer un commentaire