Question about sentinal loops with strings
import java.io.*;
import javax.swing.JOptionPane;
public class WritePayrollFile {
static String year, month, day, name;
static double weeklyhoursWorked, overtimehoursWorked, bonusPaid;
public static void main(String[] args) {
// TODO Auto-generated method stub
writeData();
}
private static void writeData() {
// TODO Auto-generated method stub
year = JOptionPane.showInputDialog("Enter Year of today: ");
month = JOptionPane.showInputDialog("Enter Month of today: ");
day = JOptionPane.showInputDialog("Enter day of today: ");
FileWriter payrollfile;
try {
payrollfile = new FileWriter("Monthlypayroll.txt");
BufferedWriter buffer = new BufferedWriter(payrollfile);
PrintWriter stream = new PrintWriter(buffer);
stream.println(year+day+month);
while(!"END".equals(name)) {
name = JOptionPane.showInputDialog("Enter Name: ");
weeklyhoursWorked = Double.parseDouble(JOptionPane.showInputDialog("En ter weekly hours worked: "));
overtimehoursWorked = Double.parseDouble(JOptionPane.showInputDialog("En ter over time hours worked: "));
bonusPaid = Double.parseDouble(JOptionPane.showInputDialog("En ter any bonus paid: "));
}
double normalhours = weeklyhoursWorked * 4;
stream.println(name+","+normalhours+","+overtimeho ursWorked+","+bonusPaid);
stream.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
Looking at the while loop: I want the user to enter the name, weekly hours worked, and over time hours worked and bonuspaid. Then the loop starts again at asking the name. at that point the user types "END" to exit out of the loop.
When i run the above set of codes, the loop goes through twice and then writes the txt file. How can I make the loop end when the user types END?
Thank you