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 displaying a text file

Write a program displaying a text file that is in a text area - The user enters a file name in a text field and clicks the view button; the file is then displayed in the text area. Do not use BufferedInputStream.

  Design an application for pizza order process

Create an application to take and procedure a pizza order. The user should be able to make pizza order choices from listboxes, and the application should show the order price.

  Find the smallest complex number

Given a "Complex" class with all the standard methods for complex numbers, design the static method below to find and return the smallest complex number.

  Implements the queue interface

Element from an ArrayList is slow because of all the shifting. For this question, you should modify the poll()method so that it runs in constant time - implementations as well as correct/fast implementations. In the former case, your functions may..

  Write a java program in a netbeans project

Write a Java program in a NetBeans project

  Values that occur just once

This list has some values that occur just once (1, 3, 4, 11, 13, 18), some values that occur twice (9, 16), some values that occur three times (14, 19) and a single value that occurs four times (7). Therefore, the call of list.maxCount() should re..

  Correctness of the above written method

Write a Java Tester to test the correctness of the above written method.

  Using a linked implementation of graph write a method

Write a method that takes two nodes as input and returns true if joining an edge between these two nodes, forms a duplicate path to one of the input nodes within the graph.

  Implement a class quiz

Implement a class Quiz that implements the Measurable interface.

  Determine the example of a javascriptr framework in the

what is an example of a javascriptr framework? in the framework you have described what is an example of an application

  Calculates the cost of a mortgage

Write a class called Mortgage that calculates the cost of a mortgage. Prompt the user to enter the principal amount, the term in years, and the interest rate per year.

  Write down a program which determines the bonus that must

write a program that determines the bonus that should be paid to employees. bonuses are determined based on the years

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