Writing a program that is to end when "stop" is entered in the name field during execution. However, I cannot seem to get it to do so. Code is below:
Code:
public static void main(String[] args) {
// TODO code application logic here
Scanner scanner = new Scanner(System.in);
String cleanInputBuffer;
boolean end = false; // is the input name stop?
while (end == false) // as long as end is false, proceed
{
System.out.print("Enter employee name: ");
String name = scanner.nextLine();
if (name.toLowerCase() == "stop")
{
end = true; // when the stop is detected, change the boolean
}
System.out.print("Enter number of hours worked in a week: ");
double hours = scanner.nextDouble();
while (hours < 0) //if a negative number will loop next command
{
System.out.print("Enter a positive number of hours worked:"); // prompt
hours = scanner.nextDouble();
}
System.out.print("Enter hourly pay rate (Do not include dollar sign): ");
double rate = scanner.nextDouble();
while (rate < 0) //if a negative number will loop next command
{
System.out.print ("Enter a positive hourly rate of pay:");
rate = scanner.nextDouble();
}
/* tax rates should be entered as a decimal point i.e. 20% = .20 */
System.out.print("Enter federal tax withholding rate: ");
double fedTax = scanner.nextDouble();
System.out.print("Enter state tax withholding rate: ");
double stateTax = scanner.nextDouble();
System.out.println("Employee Name: " + name + ".");
double grossPay;
grossPay = rate * hours;
double fedwithHolding;
fedwithHolding = fedTax * grossPay;
double statewithHolding;
statewithHolding = stateTax * grossPay;
double deduction;
deduction = fedwithHolding + statewithHolding;
double netPay;
netPay = grossPay - deduction;
System.out.println("The netpay is $"+ netPay +".");
cleanInputBuffer = scanner.nextLine();
} // end outer while
} // end method main
} // end class PayrollProgramPart
Comment