Question: Please help with Java? Create a class called Person. Inside of your Person class add two class variables, one for first and one for last
Please help with Java?
- Create a class called "Person." Inside of your Person class add two class variables, one for first and one for last name.
- Create a default (no parameters) constructor method that sets their first name to "Bob and last name to Smith.
- Create an overloaded constructor method that takes in two parameters and sets their names to them. One parameter will be their first name and the second will be their last name.
- Create a getter/accessor method and setter/mutator method for both their first and last names.
- Lastly, create an overriden toString method that will return the persons first then last name.
- Hint: The method header would be:
@Override
public String toString()
- In your main method, create an object/instance of your Person class using the default constructor.
- Create another Person using the overloaded constructor. Have the values that are passed in as arguments come from user input (Scanners nextLine).
- Directly print out both peoples values using the toString method.
- Hint: The toString method is automatically called when an object/instance is placed into a WriteLine method call.
- Now change one persons first name to Aly and the other persons last name to Sanchez.
- Hint: Use the setters/mutators to do so. Please do not create two entirely new objects.
- Finally, print out both names for both people using the getters/accessors.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
