java - Accepting multiple inputs loop -
i've written program in java series of calculations, payroll program 4 different types of employees. i'm having issue trying make not exit after input completed.
for example: user asked how many employees in company. there should start asking employee #1's type (manager, hourly, etc...) keep asking until total employees met, example 4. after each input it's okay employee's name , information output.
here's have far, complete, working program. thing left part described above.
any resources me work out solution more valuable rewriting code.
thanks!
import java.util.scanner; import java.text.decimalformat; public class payrollswitch { public static void main(string[] args) { // first input group int employeetype; // 1-4 (manager, hourly, commissioned, pieceworker) int compsize; // company size (4 - 10) int hourswrkd; // whole number, no partial hours. string employeename; // name of employee // pay each worker type double ratemanagerwrkr = 800.00;// fixed weekly salary double managerbonus = 750.00; // $750.00 bonus manager double ratehourwrkr; // hourly + overtime > 40 = 1.5 time hourly rate double hourovertime = 1.5; // if hourswrkd > 40 double hourovertimestore; // stores value double ratecommwrkr = 650.00; // fixed weekly salary double commbonus = 250.00; // $250.00 bonus commissioned worker double commwklysal; // 5.7% time weekly salary (650.00 * 5.7) double ratepiecewrkr = 400.00; // fixed weekly salary // deductions double medicaldues = 20.00; // $20.00 per pay period double fedtax = 0.30; // 30% of gross double socialsec = 0.05; // 5% of gross double deductdues; double fedtaxfinal; double socialsecfinal; // totals double managergross; double managernet; double hourgross; double hournet; double commgross; double commnet; double piecegross; double piecenet; // convert decimals match ####.## place ($9999.99) decimalformat df = new decimalformat("####.##"); string employeetitle; scanner input = new scanner(system.in); system.out.print("enter employee paycode (1-4): "); employeetype = input.nextint(); switch (employeetype) { case 1: { employeetitle = "manager"; system.out.println("you selected manager!"); system.out.print("what's name? :"); employeename = input.next(); system.out.print("enter amount of hours worked week: "); hourswrkd = input.nextint(); system.out.println("name: " + employeename); system.out.println("title: " + employeetitle); system.out.println("type: " + employeetype); system.out.println("hours worked: " + hourswrkd); managergross = ratemanagerwrkr + managerbonus; system.out.println("gross pay: $" + df.format(managergross)); system.out.println("federal tax: $" + df.format(managergross * fedtax)); system.out.println("social security: $" + df.format(managergross * socialsec)); system.out.println("medical: $" + df.format(medicaldues)); fedtaxfinal = managergross * fedtax; socialsecfinal = managergross * socialsec; deductdues = (fedtaxfinal + socialsecfinal + medicaldues); managernet = (managergross - deductdues); system.out.println("net pay: $" + df.format(managernet)); } break; case 2: { employeetitle = "hourly"; system.out.println("you selected hourly!"); system.out.print("what's name? :"); employeename = input.next(); system.out.print("enter amount of hours worked week: "); hourswrkd = input.nextint(); system.out.print("enter hourly rate: $"); ratehourwrkr = input.nextdouble(); hourgross = ratehourwrkr * hourswrkd; system.out.println("name: " + employeename); system.out.println("title: " + employeetitle); system.out.println("type: " + employeetype); // begin checking hours worked if (hourswrkd > 40) { hourovertimestore = (hourswrkd - 40) * ratehourwrkr * hourovertime; system.out.println("hours worked: " + hourswrkd); system.out.println("overtime hours: " + (hourswrkd - 40)); system.out.println("gross pay: $" + df.format(hourgross + hourovertimestore)); system.out.println("federal tax: $" + df.format(hourgross * fedtax)); system.out.println("social security: $" + df.format(hourgross * socialsec)); system.out.println("medical: $" + df.format(medicaldues)); fedtaxfinal = hourgross * fedtax; socialsecfinal = hourgross * socialsec; deductdues = (fedtaxfinal + socialsecfinal + medicaldues); hournet = (hourgross - deductdues); system.out.println("net pay: $" + df.format(hournet)); } else { hourgross = hourswrkd * ratehourwrkr; hourovertimestore = 0; system.out.println("hours worked: " + hourswrkd); system.out.println("gross pay: $" + df.format(hourgross + hourovertimestore)); system.out.println("federal tax: $" + df.format(hourgross * fedtax)); system.out.println("social security: $" + df.format(hourgross * socialsec)); system.out.println("medical: $" + df.format(medicaldues)); fedtaxfinal = hourgross * fedtax; socialsecfinal = hourgross * socialsec; deductdues = (fedtaxfinal + socialsecfinal + medicaldues); hournet = (hourgross - deductdues); system.out.println("net pay: " + df.format(hournet)); } } break; case 3: { employeetitle = "commission"; system.out.println("you selected commission!"); system.out.print("what's name? :"); employeename = input.next(); system.out.print("enter amount of hours worked week: "); hourswrkd = input.nextint(); system.out.println("name: " + employeename); system.out.println("title: " + employeetitle); system.out.println("type: " + employeetype); system.out.println("hours worked: " + hourswrkd); commgross = ratecommwrkr + commbonus; commwklysal = (0.057 * ratecommwrkr); system.out.println("commission made: $" + df.format(commwklysal)); system.out.println("gross pay: $" + df.format(commwklysal + commgross)); system.out.println("federal tax: $" + df.format((commwklysal + commgross) * fedtax)); system.out.println("social security: $" + df.format((commwklysal + commgross) * socialsec)); system.out.println("medical: $" + df.format(medicaldues)); fedtaxfinal = (commwklysal + commgross) * fedtax; socialsecfinal = (commwklysal + commgross) * socialsec; deductdues = (fedtaxfinal + socialsecfinal + medicaldues); commnet = (commwklysal + commgross) - deductdues; system.out.println("net pay: $" + df.format(commnet)); } break; case 4: { employeetitle = "pieceworker"; system.out.println("you selected pieceworker!"); system.out.print("what's name? :"); employeename = input.next(); system.out.print("enter amount of hours worked week: "); hourswrkd = input.nextint(); system.out.println("name: " + employeename); system.out.println("title: " + employeetitle); system.out.println("type: " + employeetype); system.out.println("hours worked: " + hourswrkd); piecegross = ratepiecewrkr; system.out.println("gross pay: $" + df.format(piecegross)); system.out.println("federal tax: $" + df.format(piecegross * fedtax)); system.out.println("social security: $" + df.format(piecegross * socialsec)); system.out.println("medical: $" + df.format(medicaldues)); piecenet = piecegross - fedtax - socialsec - medicaldues; system.out.println("net pay: $" + df.format(piecenet)); } break; } } }
you not asking "number of employees" user in code.hope want.
package test; import java.util.scanner; import java.text.decimalformat; public class test { public static void main(string[] args) { // first input group int employeetype; // 1-4 (manager, hourly, commissioned, pieceworker) int compsize; // company size (4 - 10) int hourswrkd; // whole number, no partial hours. string employeename; // name of employee // pay each worker type double ratemanagerwrkr = 800.00;// fixed weekly salary double managerbonus = 750.00; // $750.00 bonus manager double ratehourwrkr; // hourly + overtime > 40 = 1.5 time hourly rate double hourovertime = 1.5; // if hourswrkd > 40 double hourovertimestore; // stores value double ratecommwrkr = 650.00; // fixed weekly salary double commbonus = 250.00; // $250.00 bonus commissioned worker double commwklysal; // 5.7% time weekly salary (650.00 * 5.7) double ratepiecewrkr = 400.00; // fixed weekly salary // deductions double medicaldues = 20.00; // $20.00 per pay period double fedtax = 0.30; // 30% of gross double socialsec = 0.05; // 5% of gross double deductdues; double fedtaxfinal; double socialsecfinal; // totals double managergross; double managernet; double hourgross; double hournet; double commgross; double commnet; double piecegross; double piecenet; // convert decimals match ####.## place ($9999.99) decimalformat df = new decimalformat("####.##"); string employeetitle; int numberofemployees=0; scanner input = new scanner(system.in); system.out.print("enter number of employees in company "); numberofemployees = input.nextint(); for(int i=0;i<numberofemployees;i++) { system.out.println("----------------------------------------------"); system.out.println("enter information employee number " + integer.tostring(i+1)); system.out.print("enter employee paycode (1-4): "); employeetype = input.nextint(); switch (employeetype) { case 1: { employeetitle = "manager"; system.out.println("you selected manager!"); system.out.print("what's name? :"); employeename = input.next(); system.out.print("enter amount of hours worked week: "); hourswrkd = input.nextint(); system.out.println("name: " + employeename); system.out.println("title: " + employeetitle); system.out.println("type: " + employeetype); system.out.println("hours worked: " + hourswrkd); managergross = ratemanagerwrkr + managerbonus; system.out.println("gross pay: $" + df.format(managergross)); system.out.println("federal tax: $" + df.format(managergross * fedtax)); system.out.println("social security: $" + df.format(managergross * socialsec)); system.out.println("medical: $" + df.format(medicaldues)); fedtaxfinal = managergross * fedtax; socialsecfinal = managergross * socialsec; deductdues = (fedtaxfinal + socialsecfinal + medicaldues); managernet = (managergross - deductdues); system.out.println("net pay: $" + df.format(managernet)); } break; case 2: { employeetitle = "hourly"; system.out.println("you selected hourly!"); system.out.print("what's name? :"); employeename = input.next(); system.out.print("enter amount of hours worked week: "); hourswrkd = input.nextint(); system.out.print("enter hourly rate: $"); ratehourwrkr = input.nextdouble(); hourgross = ratehourwrkr * hourswrkd; system.out.println("name: " + employeename); system.out.println("title: " + employeetitle); system.out.println("type: " + employeetype); // begin checking hours worked if (hourswrkd > 40) { hourovertimestore = (hourswrkd - 40) * ratehourwrkr * hourovertime; system.out.println("hours worked: " + hourswrkd); system.out.println("overtime hours: " + (hourswrkd - 40)); system.out.println("gross pay: $" + df.format(hourgross + hourovertimestore)); system.out.println("federal tax: $" + df.format(hourgross * fedtax)); system.out.println("social security: $" + df.format(hourgross * socialsec)); system.out.println("medical: $" + df.format(medicaldues)); fedtaxfinal = hourgross * fedtax; socialsecfinal = hourgross * socialsec; deductdues = (fedtaxfinal + socialsecfinal + medicaldues); hournet = (hourgross - deductdues); system.out.println("net pay: $" + df.format(hournet)); } else { hourgross = hourswrkd * ratehourwrkr; hourovertimestore = 0; system.out.println("hours worked: " + hourswrkd); system.out.println("gross pay: $" + df.format(hourgross + hourovertimestore)); system.out.println("federal tax: $" + df.format(hourgross * fedtax)); system.out.println("social security: $" + df.format(hourgross * socialsec)); system.out.println("medical: $" + df.format(medicaldues)); fedtaxfinal = hourgross * fedtax; socialsecfinal = hourgross * socialsec; deductdues = (fedtaxfinal + socialsecfinal + medicaldues); hournet = (hourgross - deductdues); system.out.println("net pay: " + df.format(hournet)); } } break; case 3: { employeetitle = "commission"; system.out.println("you selected commission!"); system.out.print("what's name? :"); employeename = input.next(); system.out.print("enter amount of hours worked week: "); hourswrkd = input.nextint(); system.out.println("name: " + employeename); system.out.println("title: " + employeetitle); system.out.println("type: " + employeetype); system.out.println("hours worked: " + hourswrkd); commgross = ratecommwrkr + commbonus; commwklysal = (0.057 * ratecommwrkr); system.out.println("commission made: $" + df.format(commwklysal)); system.out.println("gross pay: $" + df.format(commwklysal + commgross)); system.out.println("federal tax: $" + df.format((commwklysal + commgross) * fedtax)); system.out.println("social security: $" + df.format((commwklysal + commgross) * socialsec)); system.out.println("medical: $" + df.format(medicaldues)); fedtaxfinal = (commwklysal + commgross) * fedtax; socialsecfinal = (commwklysal + commgross) * socialsec; deductdues = (fedtaxfinal + socialsecfinal + medicaldues); commnet = (commwklysal + commgross) - deductdues; system.out.println("net pay: $" + df.format(commnet)); } break; case 4: { employeetitle = "pieceworker"; system.out.println("you selected pieceworker!"); system.out.print("what's name? :"); employeename = input.next(); system.out.print("enter amount of hours worked week: "); hourswrkd = input.nextint(); system.out.println("name: " + employeename); system.out.println("title: " + employeetitle); system.out.println("type: " + employeetype); system.out.println("hours worked: " + hourswrkd); piecegross = ratepiecewrkr; system.out.println("gross pay: $" + df.format(piecegross)); system.out.println("federal tax: $" + df.format(piecegross * fedtax)); system.out.println("social security: $" + df.format(piecegross * socialsec)); system.out.println("medical: $" + df.format(medicaldues)); piecenet = piecegross - fedtax - socialsec - medicaldues; system.out.println("net pay: $" + df.format(piecenet)); } break; } } system.out.println("thank using application"); } }
Comments
Post a Comment