Question

Following is the EmployeeTester class, which creates object of the class Employee and calls the methods...

Following is the EmployeeTester class, which creates object of the class Employee and calls the methods of that object. The EmployeeTester class is written to test another class: Employee. You are required to implement the class Employee by:

  1. declaring its instance variables: name, age, salary.
  2. implementing its constructor.
  3. implementing its methods:

getEmployeeName(),

getEmployeeAge(),

getEmployeeSalary(),

setEmployeeAge(int empAge),

     setEmployeeSalary(double empSalary)

public class EmployeeTester {

public static void main(String args[]) {

// Construct an object

Employee employeeOne = new Employee("Ahmad Abdullah");

// Call methods for the object

employeeOne.setEmployeeAge(30);

employeeOne.setEmployeeSalary(5000);

     

// Print the Employee details 
System.out.println("Name:"+ employeeOne.getEmployeeName());
System.out.println("Age:" + employeeOne.getEmployeeAge() );
System.out.println("Salary:" + employeeOne.getEmployeeSalary() ); 
 

   }

}

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Note: Could you plz go through this code and let me know if u need any changes in this.Thank You
=================================

// Employee.java

public class Employee {
   private String name;
   private int age;
   private double salary;

   /**
   * @param employeeName

   */
   public Employee(String employeeName) {
       this.name = employeeName;
   }

   /**
   * @return the employeeName
   */
   public String getEmployeeName() {
       return name;
   }

   /**
   * @param employeeName
   * the employeeName to set
   */
   public void setEmployeeName(String employeeName) {
       this.name = employeeName;
   }

   /**
   * @return the employeeAge
   */
   public int getEmployeeAge() {
       return age;
   }

   /**
   * @param employeeAge
   * the employeeAge to set
   */
   public void setEmployeeAge(int employeeAge) {
       this.age = employeeAge;
   }

   /**
   * @return the employeeSalary
   */
   public double getEmployeeSalary() {
       return salary;
   }

   /**
   * @param employeeSalary
   * the employeeSalary to set
   */
   public void setEmployeeSalary(double employeeSalary) {
       this.salary = employeeSalary;
   }

   /*
   * (non-Javadoc)
   *
   * @see java.lang.Object#toString()
   */
   @Override
   public String toString() {
       return "Employee [employeeName=" + name + ", employeeAge="
               + age + ", employeeSalary=" +salary + "]";
   }

}

==============================

output:

package org.students;

public class EmployeeTester {

   public static void main(String[] args) {
       Employee employeeOne = new Employee("Ahmad Abdullah");

       // Call methods for the object

       employeeOne.setEmployeeAge(30);

       employeeOne.setEmployeeSalary(5000);

         

       // Print the Employee details
       System.out.println("Name:"+ employeeOne.getEmployeeName());
       System.out.println("Age:" + employeeOne.getEmployeeAge() );
       System.out.println("Salary:" + employeeOne.getEmployeeSalary() );

   }

}

================================

output:

Name:Ahmad Abdullah
Age:30
Salary:5000.0

==========================Thank You

Add a comment
Know the answer?
Add Answer to:
Following is the EmployeeTester class, which creates object of the class Employee and calls the methods...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Question 1 1 pts Which of the following is not a valid class name in Java?...

    Question 1 1 pts Which of the following is not a valid class name in Java? O MyClass MyClass1 My_Class MyClass# Question 2 1 pts Which of the following statements is False about instance variables and methods? Instance variables are usually defined with private access modifier. Instance variables are defined inside instance methods. Instance methods are invoked on an object of the class that contains the methods. A class can have more than one instance variables and methods. Question 3...

  • ****Here is the assignment **** Purpose: To write an Object-Oriented application that creates a Java class...

    ****Here is the assignment **** Purpose: To write an Object-Oriented application that creates a Java class with several instance variables, a constructor to initialize the instance variables, several methods to access and update the instance variables’ values, along with other methods to perform calculations. Also, write a test class that instantiates the first class and tests the class’s constructor and methods. Details: Create a class called Rectangle containing the following: Two instance variables, An instance variable of type double used...

  • Write a Java class named Employee to meet the requirements described in the UML Class Diagram...

    Write a Java class named Employee to meet the requirements described in the UML Class Diagram below: Note: Code added in the toString cell are not usually included in a regular UML class diagram. This was added so you can understand what I expect from you. If your code compiles cleanly, is defined correctly and functions exactly as required, the expected output of your program will solve the following problem: “An IT company with four departments and a staff strength...

  • Using your Dog class from earlier this week, complete the following: Create a new class called...

    Using your Dog class from earlier this week, complete the following: Create a new class called DogKennel with the following: Instance field(s) - array of Dogs + any others you may want Contructor - default (no parameters) - will make a DogKennel with no dogs in it Methods: public void addDog(Dog d) - which adds a dog to the array public int currentNumDogs() - returns number of dogs currently in kennel public double averageAge() - which returns the average age...

  • Java Problem 2: Employee (10 points) (Software Design) Create an abstract class that represents an Employee and contains abstract method payment. Create concrete classes: SalaryEmployee, CommissionEm...

    Java Problem 2: Employee (10 points) (Software Design) Create an abstract class that represents an Employee and contains abstract method payment. Create concrete classes: SalaryEmployee, CommissionEmployee, HourlyEmployee which extend the Employee class and implements that abstract method. A Salary Employee has a salary, a Commision Employee has a commission rate and total sales, and Hourly Employee as an hourly rate and hours worked Software Architecture: The Employee class is the abstract super class and must be instantiated by one of...

  • In a project named 'DogApplication', create a class called 'Dog' 1. declare two instance variables in...

    In a project named 'DogApplication', create a class called 'Dog' 1. declare two instance variables in 'Dog' : name (String type) age (int type) 2. declare the constructor for the 'Dog' class that takes two input parameters and uses these input parameters to initialize the instance variables 3. create another class called 'Driver' and inside the main method, declare two variables of type 'Dog' and call them 'myDog' and 'yourDog', then assign two variables to two instance of 'Dog' with...

  • Java CSE 135 Which methods does the ChoiceQuestion class inherit from its superclass? Which methods does...

    Java CSE 135 Which methods does the ChoiceQuestion class inherit from its superclass? Which methods does it override? Which methods does it add? public class Question{ . . . public void display() { System.out.println(text); }} public class ChoiceQuestion extends Question{ . . . public void display() { super.display(); for (int i = 0; i < choices.size(); i++) { int choiceNumber = i + 1; System.out.println(choiceNumber + ": " + choices.get(i)); } }} public class QuestionDemo{ public static void main(String[] args)...

  • given the following two classes Within a file named Rational.java, define a public class named Rational...

    given the following two classes Within a file named Rational.java, define a public class named Rational such that … the Rational class has two private instance variables, numerator and denominator, both of type int the Rational class defines two public accessor methods, numerator() and denominator() the Rational class defines a constructor that has one String parameter a throws clause indicates that this constructor could potentially throw a MalformedRationalException this constructor throws a MalformedRationalException in the following circumstances … When the...

  • Given code: /** * Provides some methods to manipulate text * */ public class LoopyText {...

    Given code: /** * Provides some methods to manipulate text * */ public class LoopyText { private String text;    /** * Creates a LoopyText object with the given text * @param theText the text for this LoopyText */ public LoopyText(String theText) { text = theText; }    //Your methods here } Given tester code: /** * Tests the methods of LoopyText. * @author Kathleen O'Brien */ public class LoopyTextTester { public static void main(String[] args) { LoopyText loopy =...

  • Rewrite following code down below using Factory Pattern. -------------------------Staff.java--------------------------- import java.util.*; public class Staff extends Employee...

    Rewrite following code down below using Factory Pattern. -------------------------Staff.java--------------------------- import java.util.*; public class Staff extends Employee {    private int HourlyRate;    /**Constructor Staff which initiates the values*/    public Staff() {    super();    HourlyRate=0;    }    /**Overloaded constructor method    * @param ln last name    * @param fn first name    * @param ID Employee ID    * @param sex Sex    * @param hireDate Hired Date    * @param hourlyRate Hourly rate for the work...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT