This program is supposed to add the hours from the input until the input ='s "done" but even after the input ='s "done" and the boolean is set to true in the while loop, it doesn't end the loop, and I can't figure out why. If someone inputs for example, Friday 4 done the code should output the day total and 4 as a result but it doesn't break the loop, and multiple inputs don't add the number of hours.
import java.util.Scanner;
public class SuperMarket
{
public static void main(String args[]) throws Exception
{
// 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 hoursTotalString = "";
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);
hoursTotal= hoursTotal+hoursWorked;
prevDay = dayOfWeek;
System.out.println("\t" + DAY_FOOTER + String.valueOf(hoursTotal));
}
while(done == false){
System.out.println("Enter day of week or done to quit: ");
dayOfWeek = input.nextLine();
if( prevDay != dayOfWeek){
hoursTotal =0;
}
System.out.print("Enter hours worked: ");
hoursWorkedString = input.nextLine();
prevDay = dayOfWeek;
hoursTotal= hoursTotal+hoursWorked;
System.out.println("\t" + DAY_FOOTER + String.valueOf(hoursTotal));
if(dayOfWeek == "done"){
done = true;
break;
}
}
System.out.println(DAY_FOOTER + "(" + prevDay + ") " + hoursTotal);
System.exit(0);
} // End of main() method.
} // End of SuperMarket class.