1

I'm a beginner in Java, and I am receiving a format specifier error. Just want to say that I am required to use the printf statement here.

Please see my code listed below:

package assignmentproject1;
/* CHANGE (FINAL) VAR NAMES, SCAN & VERIFY, 
ORGANIZE AND PUT FORMULAS ON BOTTOM, ORGANIZE VAR @ TOP, */
import java.util.*;
public class Project1 
{

    public static void main (String[] args) 
    {

        Scanner stdin = new Scanner (System.in);



        final double FEDTAX = 0.25, CALITAX = 0.09075, SS_MEDI_FICA = 0.0765,
                UEIDI = 0.02, OVERTIMEHOURS; 
        double  fedtax, ss_medi_fica, grossPay, rate, totalcost_to_Employer, 
                calitax, netPay, hours, ueidi, employerFICA;
        boolean overtime = false;



        //Inputs rate and hours, then calculates the gross pay.
        System.out.print ("Enter hourly rate in dollars and cents --> ");
        rate =  stdin.nextDouble ();



        while (rate > 0)
        {           
            System.out.print ("Enter number of hours and tenths worked --> ");
            hours = stdin.nextInt ();  

            System.out.println ();// LINE SPACER

            System.out.println ("               PAYROLL REPORT");

            System.out.printf ("Rate:%38.2f                            \n",rate);

            System.out.printf ("Hours:%37.2f                           \n",hours);



            grossPay = rate * hours; //calculates gross pay.
            fedtax = grossPay * FEDTAX; //calculates federal tax.       
            calitax = grossPay * CALITAX; //calculates state (CA) tax.
            ss_medi_fica = grossPay * SS_MEDI_FICA; //employee pays for FICA.
            ueidi = grossPay * UEIDI;        
            employerFICA = grossPay * SS_MEDI_FICA; //employer pays for FICA.            
            netPay = grossPay - (fedtax + CALITAX + SS_MEDI_FICA);
            totalcost_to_Employer = grossPay + employerFICA 
                + UEIDI;

            //CHECKS CONDITION        
            System.out.println ();// LINE SPACER

            if (hours > 40)
            { 
                overtime = true;
                grossPay = rate * 40 + (hours - 40) * (rate * 1.5);
                System.out.printf ("Gross Pay: %32.2f \n", grossPay   
                + "includes overtime");
            }
            else
            {
                grossPay = rate * hours;
                System.out.printf ("Gross Pay: %32.2f \n", grossPay);



            System.out.printf ("Federal Tax: %30.2f \n", fedtax);

            System.out.printf ("State Tax: %32.2f \n", calitax);

            System.out.printf ("FICA: %37.2f \n", ss_medi_fica);

            System.out.printf ("Net Pay: %34.2f \n", netPay);

            System.out.println ();

            System.out.printf ("Employer's FICA contribution: %13.2f \n", 
                employerFICA);

            System.out.printf ("Employer's UEI and DI contribution: %7.2f \n",
                UEIDI);

            System.out.printf ("Cost to Employer: %25.2f \n", 
                totalcost_to_Employer);                    




            }

            System.out.print ("Enter hourly rate in dollars and cents --> ");
            rate =  stdin.nextDouble ();    

            overtime = false;/*have to reset overtime, 
                                so it doesn't apply to regular hours*/
        }




    }//end main

}//end class

I keep receiving errors when I input decimal values for both variables hours and rate.

I also receive errors when I input a number > 40 for the variable hours.

If I use integers only for hours OR payrate, then it seems to work fine.

4

0 回答 0