(Java) Make sure output match! Take a look at the following code: public class Employee extends Person {     private static int numEmployees = 0;       private double salary;     private String title;       public Employee() {         super();         this.title = "";         this.salary=0.0;     }       public Employee(String name, int age, String gender, Address a, double salary, String title) {         super(name,age,gender,a);         this.salary = salary;         this.title = title;     }         public double getSalary() {         return this.salary;     }         public String getTitle() {         return this.title;     }         public static int getNumEmployees() {         return numEmployees;     }       public void setSalary(double salary) {         this.salary = salary;     }       public void setTitle(String title) {         this.title = title;     }       public static void updateNumEmployees() {         numEmployees += 1;     }       @Override public String toString() {         return "Name: "+this.getName()+"\n" +                 "Age: "+this.getAge()+"\n" +                 "Gender: "+this.getGender()+"\n" +                 "Address: "+this.getAddress().getStreetNumber()+" "+this.getAddress().getStreetName()+"\n" +                 "Salary: $"+this.getSalary()+"\n" +                 "Title: "+this.getTitle();     } }   We are going to alter the Employee constructors so that one constructor calls this() and one constructor calls super() Recall that this() calls the constructor of the same class When you call super(), you are calling the constructor of the parent class. Specifically, we are going to alter the default constructor for the Employee class to call this() instead of super() Open up this method, remove the call to super() and replace it with a call to this() to call the multi-argument constructor. /**      * Default constructor for the    * Employee class. Calls the    * multi-argument constructor of the      * this class      */    public Employee() { this(//fill in here);     } Note that your call to this(....) will call the below constructor:     public Employee(String name, int age, String gender, Address a, double salary, String title)         You will need to pass in 6 arguments: "Name unknown" 0 "Gender unknown" new Address() 0.0 "Title unknown" Now, copy and paste the below code into EmployeeTest.java to verify that your default constructor works properly: /**  * EmployeeTest.java  * @author  * CIS 36B, Activity 12.1  */ import java.util.Scanner; public class EmployeeTest {     public static void main(String[] args) {         System.out.println("***Calling the Employee default constructor***");         Employee E = new Employee();         System.out.println(E);     } } Required Output:   ***Calling the Employee default constructor*** Name: Name unknown Age: 0 Gender: Gender unknown Address: 0 Street unknown Salary: $0.0 Title: Title unknown When your program is giving the required output as shown above, upload Employee.java

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

(Java)

Make sure output match!

Take a look at the following code:

public class Employee extends Person {

    private static int numEmployees = 0;

 

    private double salary;

    private String title;

 

    public Employee() {

        super();

        this.title = "";

        this.salary=0.0;

    }

 

    public Employee(String name, int age, String gender, Address a, double salary, String title) {

        super(name,age,gender,a);

        this.salary = salary;

        this.title = title;

    }

 

 

    public double getSalary() {

        return this.salary;

    }

 

 

    public String getTitle() {

        return this.title;

    }

 

 

    public static int getNumEmployees() {

        return numEmployees;

    }

 

    public void setSalary(double salary) {

        this.salary = salary;

    }

 

    public void setTitle(String title) {

        this.title = title;

    }

 

    public static void updateNumEmployees() {

        numEmployees += 1;

    }

 

    @Override public String toString() {

        return "Name: "+this.getName()+"\n" +

                "Age: "+this.getAge()+"\n" +

                "Gender: "+this.getGender()+"\n" +

                "Address: "+this.getAddress().getStreetNumber()+" "+this.getAddress().getStreetName()+"\n" +

                "Salary: $"+this.getSalary()+"\n" +

                "Title: "+this.getTitle();

    }

}

 

  • We are going to alter the Employee constructors so that one constructor calls this() and one constructor calls super()
  • Recall that this() calls the constructor of the same class
  • When you call super(), you are calling the constructor of the parent class.
  • Specifically, we are going to alter the default constructor for the Employee class to call this() instead of super()
  • Open up this method, remove the call to super() and replace it with a call to this() to call the multi-argument constructor.
/**
     * Default constructor for the
   * Employee class. Calls the
   * multi-argument constructor of the
     * this class
     */

   public Employee() {
this(//fill in here);
    }
  • Note that your call to this(....) will call the below constructor:
    public Employee(String name, int age, String gender, Address a, double salary, String title)
       
  • You will need to pass in 6 arguments:
  1. "Name unknown"
  2. 0
  3. "Gender unknown"
  4. new Address()
  5. 0.0
  6. "Title unknown"
  • Now, copy and paste the below code into EmployeeTest.java to verify that your default constructor works properly:
/**
 * EmployeeTest.java
 * @author
 * CIS 36B, Activity 12.1
 */

import java.util.Scanner;

public class EmployeeTest {
    public static void main(String[] args) {
        System.out.println("***Calling the Employee default constructor***");
        Employee E = new Employee();
        System.out.println(E);
    }
}


Required Output:
 
***Calling the Employee default constructor***
Name: Name unknown
Age: 0
Gender: Gender unknown
Address: 0 Street unknown
Salary: $0.0
Title: Title unknown
  • When your program is giving the required output as shown above, upload Employee.java
Expert Solution
Explanation

I have defined a default constructor in the class Address that will call the parameterized constructor of the same class and initialize the variables of Address type.

Next, in the class Employee(), I have defined the default constructor.

Inside the default constructor, I have passed this() with six arguments, that will call the parameterized constructor of the same class.

Next, in the EmployeeTest class I have created an object of the class Employee and then printed it to check the output.

trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps with 1 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY