Im coding this application and I cant figure out how to make the last bit to work. It asks for user input in a loop until they do not want to input any more entries, it should then use the entered data to calculate a total and averages.
From what i have it just uses the last entry from the loop and not the entire loop. Any help would be appreciated, thanks!
To sum up the program will:
* Ask whether the consultant is a partner (y/n)
* Asks for employee hours
* Calculate the total cost for the employee
* Output the Employee type, Employee Hours and Employee Cost
* Repeat if desired
Then it will: (heres where im having trouble)
*Tabulate the total number of employees
* Tabulate the total project cost
* Calulate the average hours per employee
* Calculate the average project hourly billing rate
and output it to the console.
Code:
import java.text.NumberFormat;
import java.util.Scanner;
public class BillingAppp
{
public static void main(String[] args)
{
// welcome the user to the program
System.out.println("Weclome to the Billing Application");
System.out.println(); // print a blank line
final double PARTNER_RATE = 300.00;
final double REGULAR_RATE = 150.00;
double employeeRate = 0;
int employeeCount = 0;
double payRate = 0.0;
double totalCost = 0.0;
double workHours = 0.0;
double averageBilling = 0.0;
double averageHours = 0.0;
String employeeType = "employeeType";
// create a Scanner object named sc
Scanner sc = new Scanner(System.in);
String choice = "y";
while (!choice.equalsIgnoreCase("n"))
{
// get the input from the user declaring which consultant and assigns string and rate
System.out.print("Is the consultant a partner?: (y/n) ");
choice = sc.next();
employeeCount = employeeCount + 1;
if (choice.equals("y") || choice.equals("Y"))
payRate = PARTNER_RATE;
if (choice.equals("y") || choice.equals("Y"))
employeeType = "Partner Consultant";
if (choice.equals("n") || choice.equals("N"))
payRate = REGULAR_RATE;
if (choice.equals("n") || choice.equals("N"))
employeeType = "Regular Consultant";
System.out.print("Enter Employee Hours: ");
workHours = sc.nextDouble();
System.out.println();
//calculate total cost
averageHours = workHours / employeeCount;
averageBilling = totalCost / employeeCount;
totalCost = (payRate * workHours);
NumberFormat currency = NumberFormat.getCurrencyInstance();
System.out.println(
"Employee Type: " + employeeType + "\n" +
"Employee Hours: " + (workHours) + "\n" +
"Total Employee Cost: " + currency.format(totalCost) + "\n");
System.out.println();
// see if the user wants to add another employee
System.out.print("Do you want to add another employee? (y/n): ");
choice = sc.next();
System.out.println();
}
// calculate and display total number of employees, total project cost, avg hours worked, avg billing rate
NumberFormat currency = NumberFormat.getCurrencyInstance();
String message = "Total number of Employees: " + employeeCount + "\n"
+ "Total Project Cost: " + currency.format(totalCost) + "\n"
+ "Average Hours Worked : " + (averageHours) + "\n"
+ "Average Billing Rate: " + currency.format(averageBilling) + "\n";
System.out.println(message);
}
}