Question

In: Computer Science

JAVA, this is practice to better understand java. //Please note throughout if possible looking to better...

JAVA, this is practice to better understand java.
//Please note throughout if possible looking to better understand the process.

Write the following class: Person.
Define Class Person
Write the class header

Class Variables
Class Person is to have the following data members: firstName of type String, lastName of type String representing a person’s first and last names and ssn of type int representing a social security number. Each data member has an access specifier of type private.

Constructors
Class Person is to have two constructors with the following specifications:
1. a no-arg constructor that initializes each String to an empty String and the integer data member to zero;
2. a constructor that takes three arguments, each representing one of the class data members. The arguments are to be listed in the order of (firstName, lastName, ssn);

Get and Set Methods
Class Person is to have standard get/set methods for each data member.

Method Overrides
Class Person is to override the Object equals( ) method to do the following:

1. test to see if the parameter represents an object;
2. test to see if the parameter object is of the same class type as the calling object;
3. determine if the calling object and the parameter object store identical data values for the corresponding data members.

Class Person is to override the Object toString( ) method to display the following information in the format presented:
1. First Name: display firstName data
2. Last Name: display lastName data
3. SSN: display ssn data

Solutions

Expert Solution

Please find the class definition below:

class Person {
        private String firstName;
        private String lastName;
        private int ssn;

        public Person() {
                this.firstName = "";
                this.lastName = "";
                this.ssn = 0;
        }

        public Person(String firstName, String lastName, int ssn) {
                super();
                this.firstName = firstName;
                this.lastName = lastName;
                this.ssn = ssn;
        }

        public String getFirstName() {
                return firstName;
        }

        public void setFirstName(String firstName) {
                this.firstName = firstName;
        }

        public String getLastName() {
                return lastName;
        }

        public void setLastName(String lastName) {
                this.lastName = lastName;
        }

        public int getSsn() {
                return ssn;
        }

        public void setSsn(int ssn) {
                this.ssn = ssn;
        }

        @Override
        public String toString() {
                return "Person [firstName=" + firstName + ", lastName=" + lastName + ", ssn=" + ssn + "]";
        }

        @Override
        public boolean equals(Object o) {
                if (o == this) {
                        return true;
                }


                if (!(o instanceof Person)) {
                        return false;
                }

                Person p = (Person) o;

                // Compare the data members and return accordingly
                if (p.getFirstName().equals(this.getFirstName()) && p.getLastName().equals(this.getLastName())
                                && p.getSsn() == this.getSsn()) {
                        return true;
                } else {
                        return false;
                }
        }

}

Related Solutions

JAVA, this is practice to better understand java. //Please note throughout if possible looking to better...
JAVA, this is practice to better understand java. //Please note throughout if possible looking to better understand the process. Write the following class: TV. Define Class TV Write the class header Class Variables Class TV is to have the following instance variables: 1.channel of type int 2. volumeLevel of type int 3. isOn of type boolean Each data member is to have an access specifier of private. Constructor Class TV is to have a single, no-arg constructor that initializes the...
JAVA, trying to better learn and use JAVA //Please note throughout if possible looking to better...
JAVA, trying to better learn and use JAVA //Please note throughout if possible looking to better understand the process. Write the following class: Box Define Class Box Write the class header Class Variables Class Box is to have the following private data members: height of type double width of type double length of type double Constructors Class Box is to have two constructors with the following specifications: a no-arg constructor that initializes each double data member to zero a constructor...
To better understand if it was possible to consider opening more locations, Robert wanted to know...
To better understand if it was possible to consider opening more locations, Robert wanted to know how much equity he had in his business and used the following totals to help in his calculations: Beginning capital = $35,000 Drawings = $4,000 Net income = $18,000 Investment by owner = $9,000 __________ was the ending owner’s equity that Robert calculated.
Note: I need a step by step answer to the following problem to better understand how...
Note: I need a step by step answer to the following problem to better understand how this works. Hot Coffee Manufacturing produces and sells oak tables. The budgeted   manufacturing costs per table are as follows: Direct costs                 Oak top                48 square feet at $10 per sq. ft.                 Table legs                 4 legs at $5 per leg Direct labor is 3 hours and 24 minutes per table at $15 per hour. The variable overhead rate is $6 per...
on C++ language please and if you can also put note on it to better undertand...
on C++ language please and if you can also put note on it to better undertand it. Write a program that reads data from a data file, the value of which is provided at the end of the problem. Your program is to incorporate the following requirements: Data to the program is input from a file of an unspecified length; that is, the program does not know in advance how many numbers are in the file. Save the output of...
Please read the article “A better way to understand internal rate of return” of McKinsey, November...
Please read the article “A better way to understand internal rate of return” of McKinsey, November 2015. As we have already learnt how to calculate IRR and main assumption about this project evaluation criteria do you see the way we should approach IRR suggested by McKinsey a useful recommendation? What are additional criteria on top of those we learnt in the class we can use?
This is an Intro to java question. Please provide code and pseudocode for better understanding. Problem...
This is an Intro to java question. Please provide code and pseudocode for better understanding. Problem 4: Player Move Overworld (10 points) (Game Development) You're the lead programmer for an indie game studio making a retro-style game called Zeldar. You've been tasked to implement the player movement. The game is top-down, with the overworld modeled as a 2d grid. The player's location is tracked by x,y values correlating to its row and column positions within that grid. Given the current...
Please show full work if possible, would like to be able to understand the problem and...
Please show full work if possible, would like to be able to understand the problem and solution. Leo company is considering a new venture in office equipment. It expects the cost of acquisition of land and building to be $100,000. Leo company expects cash flows to be $40,000 the first year and $45,000 for the next 4 years. It will discontinue the furniture operation upon the completions of the 5th year. Assume no salvage value. The company’s WACC is 10%....
Please show full work if possible, would like to be able to understand the problem and...
Please show full work if possible, would like to be able to understand the problem and solution. Lion Inc. recently hire you as a consultant to estimate the company’s WACC. You have obtained the following information. (1) The firm’s noncallable bonds mature in 20 years, have an 8% annual coupon, a par value of $1,000, and a market price of $1,050. (2) The company’s tax rate is 40%. (3) The risk-free rate is 4.50% and the market risk premium is...
20.1: Checking on the Drought [(JAVA, ECLIPSE), Please keep the program as short as possible] The...
20.1: Checking on the Drought [(JAVA, ECLIPSE), Please keep the program as short as possible] The California drought is a topic that is weighing heavily on the minds of many people in this state. With all the rain we have gotten this year, we are all hoping the drought is over Let's examine some rainfall data for Silicon Valley to get a sense of how this year's rainfall compares to the average rainfall. For this assignment, you will be practicing...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT