Hello everyone,
I have a reall small questions and i am stuck in the end of my code. I need just someone explane it to me please or maybe i am confused. Take a look...
Questions:
Create a class called "Employee" that includes three pieces of information as instance variables: a first name, last name, and monthly salary. Your class should have a constructor that initializes the three instance variables. Provide a set and get method for each instance variable. If the monthly salary is not positive, set it to zero.
Write a test application, aka client code, named UseEmployee that demonstrate the class you just created. Create two employee objects and display each object's yearly salary. Then give each employee a 10% raise and display each employee's yearly salary again.
The Employee Class: add another method to the employee class, named adjustSalary that would accept a percentage value and adjusts the salary of a given employee object accordingly. Make sure to go to the employee class and make use of this method as follows: increase emp1's salary by 10% and decrease emp2's salary by 5%.
I did all what he asked me but i stouck in the 5% !!! If i divided it; it will be the same as multibliy so how i can make the second employee have decrease 5%
There is my code
public class Employee {
// Instance Variables
private String firstName; // instance variable that stores the first name
private String lastName; // instance variable that stores the last name
private double monthlySalary; // instance variable
// Default Constructor
public Employee(){
this.firstName = "";
this.lastName = "";
this.monthlySalary = 0.0;
}
// non\default Constructor
public Employee (String firstName, String lastName, double monthlySalary){
this.firstName = firstName;
this.lastName = lastName;
this.monthlySalary = monthlySalary;
// if the monthly salary is not positive, set it to 0.0.
if (monthlySalary < 0)
monthlySalary = 0.0;
}
public void setFirstName (String firstName)
{
this.firstName = firstName;
}
public String getFirstName (){
return firstName;
}
public void setLastName (String lastName){
this.lastName = lastName;
}
public String getLastName ()
{
return lastName;
}
public void setMonthlySalary (double monthlySalary){
this.monthlySalary = monthlySalary;
}
public double getMonthlySalary ()
{
return monthlySalary;
}
public void adjustSalary(double percentage){
this.monthlySalary = (this.monthlySalary * percentage) + this.monthlySalary;
}
public void adjSalary(double percentage){
this.monthlySalary = (this.monthlySalary / percentage) + this.monthlySalary;
}
public String toString(){
String output = "";
output += "\nEmployee Information: ";
output += "\nEmployee firsName: " + this.firstName;
output += "\nEmployee lastName: " + this.lastName;
output += "\nEmployee monthlySalary: " + this.monthlySalary;
return output;
}
}
public class UseEmployee {
public static void main(String[] args) {
Employee sameer = new Employee (" Sameer ", " Karali ", 5000);
System.out.println(sameer);
sameer.adjustSalary(0.10);
System.out.println(sameer);
Employee nithan = new Employee ( " Nithan ", " Smith ", 6000);
System.out.println(nithan);
nithan.adjSalary(0.05);
}
}