Defined the class person to store the name of a person

Assignment Help JAVA Programming
Reference no: EM13941553

Example 1-1: Two common attributes of a person are the person's first name and last name. The typical operations on a person's name are to set the name and print the name. The following statements define a class with these properties.

public class Person
{

private String firstName; //store the first name
private String lastName; //store the last name

//Default constructor;
//Initialize firstName and lastName to empty string.
//Postcondition: firstName = ""; lastName = " ";
public Person ()
{
firstName = "";
lastName = "";

}

//Constructor with parameter
//Set firstName and lastName according to the parameters.
//Postcondition: firstName = first; lastName = last;
public Person (String first, String last)
{
setName (first, last);
}

//Method to output the first name and last name
//in the form firstName lastName
public String toString ()
{
return (firstName + " " + lastName);
}

//Method to set firstName and lastName according to
//the parameters
//Postcondition: firstName = first; lastName = last;
public void setName (String first, String last)
{
firstName = first;
lastName = last;
}
//Method to return the firstName
//Postcondition: the value of firstName is returned
public String getFirstName ()
{
return firstName;
}

//Method to return the lastName
//Postcondition: the value of lastName is returned
public String getLastName ()
{
return lastName;
}
}

The following program tests the class Person:

public class TestProgPerson
{
public static void main (String[ ] args)
{
Person name = new Person (); //Line 1

Person emp = new Person ("Donald", "Jackson"); //Line 2

System.out.println ("Line 3: name: " +name); //Line 3

name.setName ("Ashley", "Blair"); //Line 4
System.out.println ("Line 5: name: " +name); //Line 5

System.out.println ("Line 6: emp: " + emp); //Line 6

emp.setName ("Sandy", "Smith"); //Line 7
Sytem.out.println ("Line 8: emp: " + emp); //Line 8
}//end main
}

Question #1: Develop and execute a program for this exercise.

a) Example 1-1 above defined the class Person to store the name of a person. The methods that we included merely set the name and print the name of a person. Redefine the class Person so that, in addition to what the existing class does, you can:

i. Set the last name only.

ii. Set the first name only.

iii. Set the middle namde.

iv. Check whether a given last name is the same as the last name of this person.

v. Check whether a given first name is the same as the first name of this person.

vi. Check whether a given middle name is the same as the middle name of this person.

b) Add the method equals that returns true if two objects contain the same first, middle, and last name.

c) Add the method makeCopy that copies the instance variable of a Person object into another Person object.

d) Add the method getCopy that creates and returns the address of the object, which is a copy of another Person object.

e) Add the copy constructor.

f) Write the definitions of the methods of the class Person to implement the operations for this class.

g) Write a program that tests various operations of the class Person.

Reference no: EM13941553

Questions Cloud

Problem regarding the urban tourism destination : The assessment for the module is 100% field report research into an aspect of Urban Tourism. Write an essay on Urban Tourism. What do you know about the city and as an urban tourism destination? Which Tourism literature area will be most central t..
Considering two independent projects : You are considering two independent (not mutually exclusive) projects both of which have been assigned a discount rate of 15%. Based on the profitability index, what is your recommendation concerning these projects?
Description the function of the team : In your journal describe how your personal and team goals reflect your job description the function of the team and any organizational requirements.
Based on the profitability index rule : Based on the profitability index rule, should a project with the following cash flows be accepted if the discount rate is 14%? Why or why not?
Defined the class person to store the name of a person : The methods that we included merely set the name and print the name of a person. Redefine the class Person so that, in addition to what the existing class does
Markets and its competitive advantage : A brief description of your organisation. Concentrate on details that are relevant to your subsequent discussion, but you must include areas such as its products, its structure, its markets and its competitive advantage.
Considering the two mutually exclusive projects : You are considering the following two mutually exclusive projects. The required rate of return is 14.5% for project A and 13.7% for project B. Which project should you accept and why?
Identify the steps in the development of an activity based : Identify the steps in the development of an activity-based costing system. Differentiate between value-added and non value-added activities.
How to communicate the issue to the company : Provide a fully developed suggestion on how to proceed. This may entail suggesting how to communicate the issue to the company or providing a rewording the problematic advertising line (100% hypoallergenic). The suggestion is completely up to you

Reviews

Write a Review

JAVA Programming Questions & Answers

  Write a program that allows a user to enter a line of text

write a program that allows a user to enter a line of text counts number of words and number of vowels in the sentence

  Validation and event handling in javascrip

To complete this project you will write and submit one HTML file containing embedded CSS and JavaScript. The file will be called lab2.html. This file contains a registration form, which can be styled any way you like subject to the requirements be..

  Where the computer stores the list of exceptions

The call stack is where the computer stores the list of exceptions. Overloaded methods have the same name and parameter lists

  Write a bluej project- birthday paradox

The birthday paradox states that if there are 23 people in a room then there is a slightly more than 50:50 chance that at least two of them will have the same birthday.

  Program designs used in developing java applications

program designs used in developing Java applications

  Write a generic class

Write a generic class (using Java generics) called Pair that stores two values of the generic type.  It should have a constructor to set them, two methods getfirst() and getsecond() to retrieve them.

  Create java application-input miles driven and gallons used

Create Java application which will input miles driven and gallons used (both as integers) for each tankful. Program must compute and display miles per gallon obtained for each tankful.

  Write a program that prompts the user to enter the mass

Write a program that prompts the user to enter the mass of a person in kilograms and outputs theequivalent weight in pounds. Output both the mass and the weight rounded to two decimalplaces. (Note that for standard Earth gravity, 1 kilogram = 2.2 pou..

  Special car rental code from the license plate

When you rent a car from an agency, the key ring has several pieces of information: license plate, make and year of car, and usually a special code. This code could be used for some data processing within the company's computers. This lab will practi..

  Create a class called student

Java Create a class called Student that contains: - A field to store the name - A field to store their average numerical grade

  Design a java program that has two parallel arrays

Design a java program that has two parallel arrays: a string array named people that is initialized with the names of seven of your friends, and a string array named phoneNumbers that is initialized with your friends phone numbers.

  Build a very straightforward and fully functional machine

Build a very straightforward and fully functional machine learning classifier with the K-Nearest Neighbor (KNN) algorithm. The KNN model will read a set of data specified by the user, decide the appropriate class of the new instance, and finally o..

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd