Results 1 to 6 of 6
  1. #1
    Join Date
    Apr 2015
    Posts
    3
    Rep Power
    0

    Default Payroll System java code help?

    Hi, I have the instructions attached into a PDF into this post and I will post the codes that I have so far. I need help with my Tester code the most.

    Here's Employee:

    Java Code:
    public abstract class Employee{
       
       private String firstName;
       private String lastName;
       
       public Employee(String first, String last){
          firstName = first;
          lastName = last;
       }
       
       public void setFirstName(String first){
          firstName = first;
       }
       
       public String getFirstName(){
          return firstName;
       }
       
       public void setLastName(String last){
          lastName = last;
       }
       
       public String getLastName(){
          return lastName;
       }
       
       public String toString(){
          return String.format(getFirstName(), getLastName());
       }
       
       public abstract double earnings();
    }
    Here's Manager:
    Java Code:
    public class Manager extends Employee{
        private double weeklySalary;
    
        
         public Manager(String first, String last,
            double salary){
            super(first, last); 
           setWeeklySalary(salary); 
         } 
    
         
         public void setWeeklySalary(double salary){
            weeklySalary = salary < 0.0 ? 0.0 : salary;
         } 
    
        
         public double getWeeklySalary(){
            return weeklySalary;
        } 
    
         
         public double earnings(){
            return getWeeklySalary();
         } 
    
        
         public String toString(){
            return String.format("Manager: %s\n%s: $%,.2f",
               super.toString(), "weekly salary", getWeeklySalary());
       } 
    }
    Here's HourlyEmployee:
    Java Code:
    public class HourlyEmployee extends Employee{
        private double wage; 
        private double hours; 
         
        public HourlyEmployee(String first, String last,
           double hourlyWage, double hoursWorked){
           super(first, last);
            setWage(hourlyWage); 
            setHours(hoursWorked); 
         }
        
        public void setWage(double hourlyWage){
            wage = (hourlyWage < 0.0) ? 0.0 : hourlyWage;
         } 
    
         
        public double getWage(){
            return wage;
         } 
    
        
        public void setHours(double hoursWorked){
            hours = ((hoursWorked >= 0.0) && (hoursWorked <= 168.0))?
               hoursWorked : 0.0;
         } 
    
         
        public double getHours(){
            return hours;
         } 
    
        
        public double earnings(){
            if (getHours() <= 40) 
               return getWage() * getHours();
            else
               return 40 * getWage() + (getHours() - 40) * getWage() * 1.5;
        } 
    
         
        public String toString(){
            return String.format("hourly employee: %s\n%s: $%,.2f; %s: %,.2f",
               super.toString(), "hourly wage", getWage(),
               "hours worked", getHours());
        } 
    }
    And here's my Tester code that doesn't work. I don't know what to change in it:
    Java Code:
    public class Tester{
       public static void main( String args[] ){
    
           Manager manager =
              new Manager( "Steve", "Davis", 1200.00 );
           Manager manager =
              new Manager( "Alex", "Bowers", 0.00 );
           HourlyEmployee hourlyEmployee =
              new HourlyEmployee( "John", "Kanet", 35.5, 50 );
           HourlyEmployee hourlyEmployee =
              new HourlyEmployee( "Matthew", "Williams", 25, 40 );
           HourlyEmployee hourlyEmployee =
              new HourlyEmployee( "Atanas", "Radenski", -45, 80 );
           
    
           System.out.println( "Employees processed individually:\n" );
    
           System.out.printf( "%s\n%s: $%,.2f\n\n",
               manager, "earned", manager.earnings() );
           System.out.printf( "%s\n%s: $%,.2f\n\n",
               hourlyEmployee, "earned", hourlyEmployee.earnings() );
    
    
           Employee employees[] = new Employee[ 2 ];
    
    
             employees[ 0 ] = manager;
             employees[ 1 ] = hourlyEmployee;
            
           
    
            System.out.println( "Employees processed polymorphically:\n" );
    
    
            for(Employee currentEmployee : employees){
               System.out.println( 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 i = 0; i<employees.length; i++)
               System.out.printf("Employee %d is a %s\n", i,
                  employees[i].getClass().getName());
         } 
      }
    Let me know of any further questions for more detail or specifics. Thanks so much.
    Attached Files Attached Files

  2. #2
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    6,226
    Rep Power
    14

    Default Re: Payroll System java code help?

    When you ask for help you need to say specifically what problem you are having. That includes showing any errors (runtime or compile time). I can tell you that looking at your code I don't see a setBaseSalary or getBaseSalary method anywhere in your code. And where is the object employee defined? See lines 38 and 39 above.

    Regards,
    Jim
    Last edited by jim829; 04-23-2015 at 03:32 AM.
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

  3. #3
    Join Date
    Apr 2015
    Posts
    3
    Rep Power
    0

    Default Re: Payroll System java code help?

    Hello, yes I totally forgot. I was getting compiling errors in my Tester code, which are here:

    Tester.java:4: error: cannot find symbol
    Manager manager =
    ^
    symbol: class Manager
    location: class Tester
    Tester.java:5: error: cannot find symbol
    new manager( "Steve", "Davis", 1200.00 );
    ^
    symbol: class manager
    location: class Tester
    Tester.java:6: error: cannot find symbol
    Manager manager =
    ^
    symbol: class Manager
    location: class Tester
    Tester.java:7: error: cannot find symbol
    new manager( "Alex", "Bowers", 0.00 );
    ^
    symbol: class manager
    location: class Tester
    Tester.java:8: error: cannot find symbol
    HourlyEmployee hourlyEmployee =
    ^
    symbol: class HourlyEmployee
    location: class Tester
    Tester.java:9: error: cannot find symbol
    new HourlyEmployee( "John", "Kanet", 35.5, 50 );
    ^
    symbol: class HourlyEmployee
    location: class Tester
    Tester.java:10: error: cannot find symbol
    HourlyEmployee hourlyEmployee =
    ^
    symbol: class HourlyEmployee
    location: class Tester
    Tester.java:11: error: cannot find symbol
    new HourlyEmployee( "Matthew", "Williams", 25, 40 );
    ^
    symbol: class HourlyEmployee
    location: class Tester
    Tester.java:12: error: cannot find symbol
    HourlyEmployee hourlyEmployee =
    ^
    symbol: class HourlyEmployee
    location: class Tester
    Tester.java:13: error: cannot find symbol
    new HourlyEmployee( "Atanas", "Radenski", -45, 80 );
    ^
    symbol: class HourlyEmployee
    location: class Tester
    Tester.java:24: error: cannot find symbol
    Employee employees[] = new Employee[ 2 ];
    ^
    symbol: class Employee
    location: class Tester
    Tester.java:24: error: cannot find symbol
    Employee employees[] = new Employee[ 2 ];
    ^
    symbol: class Employee
    location: class Tester
    Tester.java:35: error: cannot find symbol
    for(Employee currentEmployee : employees){
    ^
    symbol: class Employee
    location: class Tester
    Tester.java:38: error: cannot find symbol
    double oldBaseSalary = employee.getBaseSalary();
    ^
    symbol: variable employee
    location: class Tester
    Tester.java:39: error: cannot find symbol
    employee.setBaseSalary( 1.10 * oldBaseSalary );
    ^
    symbol: variable employee
    location: class Tester
    Tester.java:42: error: cannot find symbol
    employee.getBaseSalary() );
    ^
    symbol: variable employee
    location: class Tester

    16 errors

    I've been trying to figure out what I am doing wrong to get such errors. I'll try to work on the things you've mentioned above. Thanks.

  4. #4
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    13,541
    Rep Power
    27

    Default Re: Payroll System java code help?

    How are you compiling this?
    Where are the files located?
    Are these classes in packages?
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  5. #5
    Join Date
    Apr 2015
    Posts
    3
    Rep Power
    0

    Default Re: Payroll System java code help?

    I'm compiling it with the jGrasp program and the classes are separate.

  6. #6
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    6,226
    Rep Power
    14

    Default Re: Payroll System java code help?

    Quote Originally Posted by confusedprogr1 View Post
    I'm compiling it with the jGrasp program and the classes are separate.
    You should be using packages. Using the default package (i.e. no package) is not a good idea. Read about them here.

    Regards,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

Similar Threads

  1. Replies: 6
    Last Post: 02-11-2013, 05:22 AM
  2. Shutdown the system using java code
    By jerry jessie in forum New To Java
    Replies: 1
    Last Post: 02-14-2012, 09:56 AM
  3. incomplete payroll in java ..
    By darlyn in forum New To Java
    Replies: 3
    Last Post: 08-17-2011, 11:38 AM
  4. backup -- payroll system
    By princess000 in forum Forum Lobby
    Replies: 10
    Last Post: 02-27-2011, 11:41 AM
  5. Payroll Part 2, Java
    By lplopez92 in forum New To Java
    Replies: 2
    Last Post: 03-24-2008, 01:55 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •