I need to write a program for my CIS class, I feel I have the majority set up. Being 95%, To sum it all up simply. I have to write a program that prompts the user to input their name, pay rate, hours worked. It then takes the data, calculates the gross pay, then subtracts the tax, then prints it all to the screen. The program should allow multiple users to add data for however number of employee's, which forces me to believe I need to set a value they must enter to end the program. Problem is I am regrettably stumped on how to code it so when the value is entered, the program ends. I'm almost certain a while loop is needed, but any sort of feedback would be much appreciated.
package program1;
import java.util.*;
public class Program1 {
static Scanner console = new Scanner (System.in);
public static void main(String[] args) {
String firstName, lastName ;
double payRate;
int hoursWorked;
double netPay;
double grossPay;
String formatNet;
System.out.println("Please enter the employee's name. (Enter a -1 when finished): ") ;
firstName = console.nextLine();
lastName = console.nextLine();
System.out.println("Please enter the employee's pay rate. ");
payRate = console.nextDouble();
System.out.println("Please enter the employee's hours worked. ");
hoursWorked = console.nextInt();
if(hoursWorked > 40)
{
grossPay = payRate * hoursWorked * 1.5;
}
else
{
grossPay = payRate * hoursWorked;
}
netPay = grossPay - (grossPay * .15);
formatNet = String.format("%.2f", netPay);
System.out.println(firstName +" "+ lastName + "'s net pay is " + formatNet);
}
}