Question: JAVA Program Use this class to create Person objects for each of the names below, Sam Smith Charlie Black Betty Brown Jessica Stewart John Friday

JAVA Program

Use this class to create Person objects for each of the names below,

Sam Smith

Charlie Black

Betty Brown

Jessica Stewart

John Friday

Frank Foley

Do not change the person class (Hint: Research the TreeSet class for alternate constructors.) What code needs to be added or modified?

Use the following Person class and PersonRunner class for this problem:

public class Person

{

private String firstName;

private String lastName;

public Person(String firstName, String lastName)

{

this.firstName = firstName;

this.lastName = lastName;

}

public String getFirstName() { return firstName; }

public String getLastName() { return lastName; }

public String toString()

{

return "Name: " + firstName + " " + lastName;

}

}

-----------------------------------------------------------------------------

import java.util.TreeSet;

public class PersonRunner

{

public static void main(String[] args)

{

TreeSet mySet = new TreeSet();

mySet.add(new Person("Sally", "Brown"));

mySet.add(new Person("Fred", "Kelly"));

mySet.add(new Person("Bill", "Akins"));

mySet.add(new Person("Julie","Wilkins"));

mySet.add(new Person("James", "Langdon"));

for (Person p : mySet)

{

System.out.println(p);

}

}

}

Execute the PersonRunner class. What causes the run-time error? Fix the problem by changing the Person class and then run the PersonRunner class again. Do the Person objects appear in the correct sequence after you have modified Person?

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!