Welcome to Dream.In.Code
Become a Java Expert!

Join 149,519 Java Programmers for FREE! Get instant access to thousands of Java experts, tutorials, code snippets, and more! There are 1,379 people online right now. Registration is fast and FREE... Join Now!




java payroll system

 
Reply to this topicStart new topic

java payroll system, error messagae after run

lessa124
28 Jun, 2007 - 03:28 PM
Post #1

New D.I.C Head
*

Joined: 28 Jun, 2007
Posts: 3


My Contributions
I have added the code to the test program for pieceworker, and written the pieceworker program. Everything compiles with no errors, but when it runs It only displays the first two salariedemployee and hourlyemployee then finishes and I get this error message:

Exception in thread "main" java.util.IllegalFormatConversionException: f != java.lang.String


Here is the test code:

CODE
public class PayrollSystemTest
{
    public static void main( String [] args )
    {
        SalariedEmployee salariedEmployee =
            new SalariedEmployee( "John", "Smith", "111-11-1111", 800.00 );
        HourlyEmployee hourlyEmployee =
            new HourlyEmployee( "Karen", "Price", "222-22-2222", 16.75, 40 );
        CommissionEmployee commissionEmployee =
            new CommissionEmployee(
                "Sue", "Jones", "333-33-3333", 10000, .06 );
        BasePlusCommissionEmployee basePlusCommissionEmployee =
            new BasePlusCommissionEmployee(
                "Bob", "Lewis", "444-44-4444", 5000, .04, 300 );
        PieceWorkerEmployee pieceWorkerEmployee =
            new PieceWorkerEmployee( "Rick", "Bridges", "555-55-5555", 2.25, 400);
                
        
        System.out.println( "Employee processed individually:\n" );
        System.out.printf( "%s\n%s: $%,.2f\n\n",
            salariedEmployee, "earned", salariedEmployee.earnings() );
        System.out.printf( "%s\n%s: $%,.2f\n\n",
            hourlyEmployee, "earned", hourlyEmployee.earnings() );
        System.out.printf( "%s\n%s: $%,.2f\n\n",
            commissionEmployee, "earned", commissionEmployee.earnings() );
        System.out.printf( "%s\n%s: $%,.2f\n\n",
            basePlusCommissionEmployee,
            "earned", basePlusCommissionEmployee.earnings() );
        System.out.printf("%s\n%s: $%,.2f\n\n",
            pieceWorkerEmployee, "earned", pieceWorkerEmployee.earnings() );
        
        Employee employees[] = new Employee[ 5 ];
        
        employees[ 0 ] = salariedEmployee;
        employees[ 1 ] = hourlyEmployee;
        employees[ 2 ] = commissionEmployee;
        employees[ 3 ] = basePlusCommissionEmployee;
        employees[ 4 ] = pieceWorkerEmployee;
        
        System.out.println( "Employees processed polymorphically:\n" );
        
        for ( Employee currentEmployee : employees )
        {
            System.out.println( currentEmployee );
            
            if ( currentEmployee instanceof BasePlusCommissionEmployee )
            {
                BasePlusCommissionEmployee employee =
                    ( BasePlusCommissionEmployee ) currentEmployee;
                    
                double oldBaseSalary = employee.getBaseSalary();
                employee.setBaseSalary( 1.10 * oldBaseSalary );
                System.out.printf(
                    "new base salary with 10%% increase is: $%,.2f\n",
                    employee.getBaseSalary() );
            }
            System.out.printf(
                "earned $%,.2f\n\n", currentEmployee.earnings() );
            }
            
            for (int j = 0; j < employees.length; j++ )
                System.out.printf( "Employee %d is a %s\n", j,
                    employees[ j ].getClass().getName() );
    }
}





now here is the pieceworker code:

CODE
public class PieceWorkerEmployee extends Employee
{
    private double wage;
    private int pieces;
    
    public PieceWorkerEmployee( String first, String last, String ssn,
        double pieceWage, int piecesWorked )
    {
        super( first, last, ssn );
        setWage( pieceWage );
        setPieces( piecesWorked );
    }
    
    
    public void setWage( double pieceWage )
    {
        wage =  ( pieceWage >= 0.0 ) ? 0.0 :pieceWage;
    }
    
    public double getWage()
    {
        return wage;
    }
    
    public void setPieces( int piecesWorked )
    {
        pieces =  ( piecesWorked >= 0 ) ? 0 : piecesWorked;  
    }
    
    public int getPieces()
    {
        return pieces;
    }
    
    public double earnings()
        {
            return getPieces() * getWage();
        }
        
    public String toString()
    {
        return String.format( "%s: s\n%s: $%,.2f; %s: %.2f",
            "piece employee", super.toString(),
            "pieces worked", getPieces(),
            "piece wage", getWage() );
    }
}


This post has been edited by alcdotcom: 2 Jul, 2007 - 01:46 PM
User is offlineProfile CardPM
+Quote Post

Ellie
RE: Java Payroll System
4 Jul, 2007 - 09:32 AM
Post #2

D.I.C Regular
Group Icon

Joined: 17 Jan, 2007
Posts: 427



Thanked: 4 times
Dream Kudos: 150
My Contributions

Without seeing your code for the other employee classes, this is a bit difficult to solve. I would suggest though printing each employee's data to the console as you create them to check they have been created correctly. I often use this method to work out what's wrong.

User is offlineProfile CardPM
+Quote Post

lessa124
RE: Java Payroll System
4 Jul, 2007 - 10:51 AM
Post #3

New D.I.C Head
*

Joined: 28 Jun, 2007
Posts: 3


My Contributions
QUOTE(Ellie @ 4 Jul, 2007 - 10:32 AM) *

Without seeing your code for the other employee classes, this is a bit difficult to solve. I would suggest though printing each employee's data to the console as you create them to check they have been created correctly. I often use this method to work out what's wrong.



Thanks for taking a look. I found the problem in my print statements. It works now, next time I will make sure to post all the different parts.
User is offlineProfile CardPM
+Quote Post

Ellie
RE: Java Payroll System
5 Jul, 2007 - 12:00 AM
Post #4

D.I.C Regular
Group Icon

Joined: 17 Jan, 2007
Posts: 427



Thanked: 4 times
Dream Kudos: 150
My Contributions
Great, glad you got it sorted! icon_up.gif
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/7/09 08:15PM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live Java Help!

Java Tutorials

Reference Sheets

Java Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month