1. Create a properly encapsulated class named Person that has the following: A String instance variable called name. ● ● A correctly overrided equals method which returns true if the name instance variable of the parameter and the reference variable calling the method are equal. (Do not forget the null and class type checks!) Compile your Person class. 2. Create a properly encapsulated class named Employee that inherits from Person and has the following: ● ● ● ● A constructor that takes three Strings as parameters for name, office, and hourlyWage and sets the instance variables of both the parent class and the Employee class. An overridden toString method that returns the concatenation of name and hourlyWage instance variables (separated by a space). A method named paycheck that takes an integer parameter (# of hours) and returns a double. The method should calculate and return the total wage (# of hours * hourlyWage). You can assume that the hourlyWage instance variable will always have a format of a dollar sign followed by at least one digit. Compile your Employee class. 3. Create a class named EmployeeTest that has a main method. The class should do the following: Create an Employee object and pass in "Fred" for name, "RR 205" for office, and "$38.50" for hourlyWage. You may use a reference variable name of your choice. Call the toString method and print the result. ● ● ● ● ● A constructor that takes a String parameter and sets the instance variable. A properly named getter for the instance variable. ● ● A String instance variable called office (e.g. "LWH 2222"). A String instance variable called hourlywage (e.g. "$45.15"). Call the paycheck method, pass in a value of 20 for the parameter; print the result. Create a Person object and pass in "Fred" for name. You may use a reference variable name of your choice. Call the equals method on the "Fred" Employee object and pass in the reference to the "Fred" Person object. Print out the result. Compile and run your Employee Test class. Your output should match the sample output below: Fred $38.50 770.0 false

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question
100%
1. Create a properly encapsulated class named Person that has the following:
A String instance variable called name.
A constructor that takes a String parameter and sets the instance variable.
A properly named getter for the instance variable.
A correctly overrided equals method which returns true if the name instance variable of
the parameter and the reference variable calling the method are equal. (Do not forget the
null and class type checks!)
Compile your Person class.
2. Create a properly encapsulated class named Employee that inherits from Person and has the
following:
●
●
● A String instance variable called office (e.g. "LWH 2222").
A String instance variable called hourlywage (e.g. "$45.15").
A constructor that takes three Strings as parameters for name, office, and hourlyWage
and sets the instance variables of both the parent class and the Employee class.
An overridden toString method that returns the concatenation of name and hourlyWage
instance variables (separated by a space).
A method named paycheck that takes an integer parameter (# of hours) and returns a
double. The method should calculate and return the total wage (# of hours *
hourlyWage). You can assume that the hourlywage instance variable will always have a
format of a dollar sign followed by at least one digit.
Compile your Employee class.
3. Create a class named EmployeeTest that has a main method. The class should do the following:
Create an Employee object and pass in "Fred" for name, "RR 205" for office, and
"$38.50" for hourlyWage. You may use a reference variable name of your choice.
Call the toString method and print the result.
Call the paycheck method, pass in a value of 20 for the parameter; print the result.
Create a Person object and pass in "Fred" for name. You may use a reference variable
name of your choice.
●
●
●
●
Call the equals method on the "Fred" Employee object and pass in the reference to the
"Fred" Person object. Print out the result.
Compile and run your Employee Test class. Your output should match the sample output
below:
Fred $38.50
770.0
false
Transcribed Image Text:1. Create a properly encapsulated class named Person that has the following: A String instance variable called name. A constructor that takes a String parameter and sets the instance variable. A properly named getter for the instance variable. A correctly overrided equals method which returns true if the name instance variable of the parameter and the reference variable calling the method are equal. (Do not forget the null and class type checks!) Compile your Person class. 2. Create a properly encapsulated class named Employee that inherits from Person and has the following: ● ● ● A String instance variable called office (e.g. "LWH 2222"). A String instance variable called hourlywage (e.g. "$45.15"). A constructor that takes three Strings as parameters for name, office, and hourlyWage and sets the instance variables of both the parent class and the Employee class. An overridden toString method that returns the concatenation of name and hourlyWage instance variables (separated by a space). A method named paycheck that takes an integer parameter (# of hours) and returns a double. The method should calculate and return the total wage (# of hours * hourlyWage). You can assume that the hourlywage instance variable will always have a format of a dollar sign followed by at least one digit. Compile your Employee class. 3. Create a class named EmployeeTest that has a main method. The class should do the following: Create an Employee object and pass in "Fred" for name, "RR 205" for office, and "$38.50" for hourlyWage. You may use a reference variable name of your choice. Call the toString method and print the result. Call the paycheck method, pass in a value of 20 for the parameter; print the result. Create a Person object and pass in "Fred" for name. You may use a reference variable name of your choice. ● ● ● ● Call the equals method on the "Fred" Employee object and pass in the reference to the "Fred" Person object. Print out the result. Compile and run your Employee Test class. Your output should match the sample output below: Fred $38.50 770.0 false
Expert Solution
Step 1

Here's the code for each class:

  1. Person class:

public class Person {
    private String name;
    
    public Person(String name) {
        this.name = name;
    }
    
    public String getName() {
        return name;
    }
    
    @Override
    public boolean equals(Object obj) {
        if (this == obj) return true;
        if (obj == null || getClass() != obj.getClass()) return false;
        Person person = (Person) obj;
        return name.equals(person.name);
    }
}

trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps

Blurred answer
Knowledge Booster
void method
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education