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

  Recursive factorial program

Write a class Array that encapsulates an array and provides bounds-checked access. Create a recursive factorial program that prompts the user for an integer N and writes out a series of equations representing the calculation of N!.

  Hunt the wumpus game

Reprot on Hunt the Wumpus Game has Source Code listing, screen captures and UML design here and also, may include Javadoc source here.

  Create a gui interface

Create GUI Interface in java programing with these function: Sort by last name and print all employees info, Sort by job title and print all employees info, Sort by weekly salary and print all employees info, search by job title and print that emp..

  Plot pois on a graph

Write a JAVA program that would get the locations of all the POIs from the file and plot them on a map.

  Write a university grading system in java

University grading system maintains number of tables to store, retrieve and manipulate student marks. Write a JAVA program that would simulate a number of cars.

  Wolves and sheep: design a game

This project is designed a game in java. you choose whether you'd like to write a wolf or a sheep agent. Then, you are assigned to either a "sheep" or a "wolf" team.

  Build a graphical user interface for displaying the image

Build a graphical user interface for displaying the image groups (= cluster) in JMJRST. Design and implement using a Swing interface.

  Determine the day of the week for new year''s day

This assignment contains a java project. Project evaluates the day of the week for New Year's Day.

  Write a java windowed application

Write a Java windowed application to do online quiz on general knowledge and the application also displays the quiz result.

  Input pairs of natural numbers

Java program to input pairs of natural numbers.

  Create classes implement java interface

Interface that contains a generic type. Create two classes that implement this interface.

  Java class, array, link list , generic class

These 14 questions covers java class, Array, link list , generic class.

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