Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Microsoft Visual Basic 2008 Comprehensive Concepts And Techniques

Authors: Gary B. Shelly, Corinne Hoisington

1st Edition

1423927168, 978-1423927167

More Books

Students also viewed these Databases questions

Question

7.12 Identify causal factors in bipolar disorders.

Answered: 1 week ago