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.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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started