public class PhoneList { public static void main (String[] args) { Contact[] friends = new Contact [8]; friends [0] = new Contact ("John", "Smith", "610-555-7384"); friends [1] = new Contact ("Sarah", "Barnes", "215-555-3827"); friends [2] = new Contact ("Mark", "Riley", "733-555-2969"); friends [3] = new Contact ("Laura", "Getz", "663-555-3984"); friends [4] = new Contact ("Larry", "Smith", "464-555-3489"); friends [5] = new Contact ("Frank", "Phelps" "322-555-2284"); friends [6] = new Contact ("Mario", "Guzman", "804-555-9066"); friends [7] = new Contact ("Marsha", "Grant", "243-555-2837"); Sorting.selectionSort (friends); for (Contact friend friends) System.out.println (friend); I
public class PhoneList { public static void main (String[] args) { Contact[] friends = new Contact [8]; friends [0] = new Contact ("John", "Smith", "610-555-7384"); friends [1] = new Contact ("Sarah", "Barnes", "215-555-3827"); friends [2] = new Contact ("Mark", "Riley", "733-555-2969"); friends [3] = new Contact ("Laura", "Getz", "663-555-3984"); friends [4] = new Contact ("Larry", "Smith", "464-555-3489"); friends [5] = new Contact ("Frank", "Phelps" "322-555-2284"); friends [6] = new Contact ("Mario", "Guzman", "804-555-9066"); friends [7] = new Contact ("Marsha", "Grant", "243-555-2837"); Sorting.selectionSort (friends); for (Contact friend friends) System.out.println (friend); I
Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
Related questions
Question
Modify the Contact class in Chapter 10 so that the sorting methods invoked in PhoneList.java keeps the Contact objects sorted by phone number.
Expert Solution
Step 1
To compare two String objects, use the compareTo method on a String object For example The function compareTo compares "apple" and "cat" alphabetically and outputs the result as an integer.
- If "apple" appears before "cat" in the alphabet, the compareTo method returns a negative number as a result.
- If "apple" and "cat" are the same in alphabetical order, the compareTo function returns zero.
- If "apple" follows "cat" alphabetically, the compareTo function gives a positive number.
Trending now
This is a popular solution!
Step by step
Solved in 4 steps with 1 images
Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Recommended textbooks for you
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education