Hi chaps, what do we define as a client of a class please? I keep reading about "clients of a class" but I don't understand what that means. Maybe it is better to have some examples: take the following 2 files:
//Employee.java
public class Employee{
public static void main(String[] args){
EmployeeClass employee1 = new EmployeeClass("your name 1", "your surname 1", 0.0);
System.out.println("Printing values '1' initialized by the constructor.");
System.out.printf("Name:%s ", employee1.getName());
System.out.printf("\nSurnname:%s ", employee1.getLastName());
System.out.printf("\nSalary:" + employee1.getSalary());
EmployeeClass employee2 = new EmployeeClass("your name 2", "your surname 2", 0.0);
System.out.println("\n\nPrinting values '2' initialized by the constructor.");
System.out.printf("Name:%s ", employee2.getName());
System.out.printf("\nSurnname:%s ", employee2.getLastName());
System.out.printf("\nSalary: " + employee2.getSalary());
//setting the values of the instance variables of first employee
employee1.setName("John");
employee1.setLastName("Smith");
employee1.setSalary(19000.50);
//getting the values of the instance variables of first employee
System.out.println("\n\nPrinting the values of first employee's details after having set them");
System.out.printf("Name:%s ", employee1.getName());
System.out.printf("\nSurnname:%s ", employee1.getLastName());
System.out.println("\nSalary: \u00A3" + employee1.getSalary());
//increase 10% salary
System.out.print("\na 10% rise will give a new salary of \u00A3" + employee1.salaryIncrease());
//setting the values of the instance variables of second employee
employee2.setName("Michael");
employee2.setLastName("McWry");
employee2.setSalary(23000.50);
//getting the values of the instance variables of second employee
System.out.println("\n\nPrinting the values of second employee's details after having set them");
System.out.printf("Name:%s ", employee2.getName());
System.out.printf("\nSurnname:%s ", employee2.getLastName());
System.out.println("\nSalary: \u00A3" + employee2.getSalary());
//increase 10% salary
System.out.print("\na 10% rise will give a new salary of \u00A3" + employee2.salaryIncrease() + "\n");
}
}
SO which one is the client of which class please?
thanks
and this
//EmployeeClass.java
public class EmployeeClass{
private String firstName;
private String lastName;
private double salary;
//constructor taking 3 parameters
public EmployeeClass(String name, String surname, double money){
firstName = name;
lastName = surname;
salary = money;
}
//setters to set the instance variables
public void setName(String name){
firstName = name;
}
public void setLastName(String surname){
lastName = surname;
}
public void setSalary(double money){
if(money >= 0.0){
salary = money;
}
}
//getters to get the values back
public String getName(){
return firstName;
}
public String getLastName(){
return lastName;
}
public double getSalary(){
return salary;
}
//salary rise of 10%
public double salaryIncrease(){
salary += ((salary / 100) * 10);
return salary;
}
}