In: Computer Science
Create a java program that has a code file with main() in it and
another code file with a separate class. You will be creating
objects of the class in the running program, just as the chapter
example creates objects of the Account class.
Your system handles employee records and processes payroll for
them. Create a class called Employee that holds the following
information: first name, last name, monthly salary, and sales
bonus. The class should have all the gets and sets and have a
method to report the yearly salary (which is the monthly salary *
12 + the sales bonus.)
[Note: Before anyone asks. You cannot have spaces in variable
names. So you might call the first one firstName, first_name, fname
or any other appropriate and legal variable name. The write up
above is telling you the information to be stored in English, not
java.]
Create 2 objects of Employee in your main code class and display
their names, monthly, and yearly salaries. Then give them each a
100 pay raise to their monthly salary. (Hint: use the get() to read
it out to a variable, add 100, then use the set() to store it back
in) Then display their names, monthly, and yearly salaries
again.
[Note2: You can hard code the names, and salaries you are storing
in the 2 employee objects or ask the user for them with a Scanner.
Either way is fine. It is perfectly all right from a grading
standpoint to just give it test values like the chapter example
does.]
Please use beginner level Java and NetBeans 8.0
class Employee {
private String fname;
private String lname;
private double mSalary;
private double salesBonus;
public Employee() {
super();
}
// construtor to initialize the values
public Employee(String aFname, String aLname, double
aSalary, double aSalesBonus) {
super();
fname = aFname;
lname = aLname;
mSalary = aSalary;
salesBonus = aSalesBonus;
}
// getters and setters
public String getFname() {
return fname;
}
public void setFname(String aFname) {
fname = aFname;
}
public String getLname() {
return lname;
}
public void setLname(String aLname) {
lname = aLname;
}
public double getSalary() {
return mSalary;
}
public void setSalary(double aSalary) {
mSalary = aSalary;
}
public double getSalesBonus() {
return salesBonus;
}
public void setSalesBonus(double aSalesBonus)
{
salesBonus = aSalesBonus;
}
// returns the yearlySalary
public double yearlySalary() {
return mSalary * 12 +
salesBonus;
}
// toString will return all the object
details
public String toString() {
return "Employee [Fist Name=" +
fname + ", Last Name=" + lname + ", Monthly Salary=" + mSalary + ",
salesBonus=" + salesBonus
+ "]";
}
}
public class TestEmployee {
public static void main(String[] args) {
// creating 2 objects
Employee e1 = new Employee("Uday",
"Kumar", 5000, 500);
Employee e2 = new
Employee("Keerthi", "Reddy", 6000, 100);
// printing 2 objects
System.out.println(e1);
System.out.println(e2);
// giving 100 hike for both
employees
e1.setSalary(e1.getSalary() +
100);
e2.setSalary(e2.getSalary() +
100);
// printing 2 objects
System.out.println("After giving
100 hike");
System.out.println(e1);
System.out.println(e2);
}
}
Note : If you like my answer please rate and help me it is very Imp for me