Portfolio Title





 

 

Student Portfolio >> Index >> Coding >> JAVA Exercise 5

 
public class Employee
 {
 protected String name; 
 protected double salary; 
 protected int hireYear; 
         
 
 /* overloaded constructors */
 public Employee( String empName, double empSalary, int empHireYear ) 
   {
   name = empName;
   salary = empSalary;
   hireYear = empHireYear;
   }
         
 public Employee( ) // constructor with two parameters
   {
   name = "John Citizen";
   salary = 50000.00;
   hireYear = 2000;
   }
 
/* ======================================================================================
   exercise changes GETTERS
   ====================================================================================== */
 public String getName() // gets employee name
   {
   return name; 
   }
         
 public double getSalary() // gets salary
   {
   return salary; 
   }
         
 public int getHireYear() // gets hire year
   {
   return hireYear; 
   }
 
 
/* ======================================================================================
   exercise changes SETTERS
   ====================================================================================== */
         
 public void setName(String varName) // sets employee name
   {
   name= varName; 
   }
         
 public void setSalary(double varSalary) // sets salary
   {
   salary = varSalary; 
   }
         
 public void setHireYear( int varHireYear ) // sets hire year
   {
   hireYear = varHireYear; 
   }
 
 
           /* ======================================================================================
   PRINT info on screen
   ====================================================================================== */
         
 public void display() 
   {
   System.out.println( "Employee Name = " + name + " Salary = " + salary + " Hire Year = " + hireYear); 
   }
         
 
 
/* ======================================================================================
   OVERLOAD raiseSalary
   ====================================================================================== */
         
 public void raiseSalary(double byPercent) 
   {
   salary = salary + (salary * byPercent);
   }
         
 public void raiseSalary(int Amount) 
   {
   salary = salary + Amount;
   }
         
 
 
}
         

 

<< Back                                                                                                                                                                                        Forward >> 

Coding | Website Scripting | Visual Design | Instructional Design | Website Design | Website Design Tools

 

Copyright 2005 Kerstin Kegel