Rewrite the Sorting class so that both sorting algorithms put the values in descending order. 2. Modify the Contact class in Chapter 10 so that it the sorting methods invoked in PhoneList.java keeps the Contact objects sorted by phone number.

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
icon
Related questions
Question

1. Rewrite the Sorting class so that both sorting algorithms put the values in descending order.

2. Modify the Contact class in Chapter 10 so that it the sorting methods invoked in PhoneList.java keeps the Contact objects sorted by phone number. 

 

public class Contact implements Comparable // Has method compare To
{
}
private String firstName, lastName, phone;
// --
// Constructor: Sets up this contact with the specified data.
//-
public Contact (String first, String last, String telephone)
{
}
firstName = first;
lastName= last;
phone telephone;
// Returns a description of this contact as a string.
//-
public String toString()
{
return lastName + ", "+firstName + "\t" + phone;
}
// Returns a description of this contact as a string.
//---
public boolean equals (Object other)
{
return (lastName.equals(((Contact) other).getLastName()) &&
firstName.equals(((Contact) other).getFirstName()));
// Use String equals
// Uses both last and first names to determine ordering.
//-
publ
public int compareTo (Object other)
int result;
String other First = ((Contact)other).getFirstName();
String other Last = ((Contact)other).getLastName();
if (lastName.equals (other Last))
result = firstName.compareTo (other First); // String compare To
else
result lastName.compareTo (other Last); // String compare To
return result;
// First name accessor.
11-
public String getFirstName ()
{
return firstName;
}
// -
// Last name accessor.
//-
public String getLastName ()
{
return lastName;
Transcribed Image Text:public class Contact implements Comparable // Has method compare To { } private String firstName, lastName, phone; // -- // Constructor: Sets up this contact with the specified data. //- public Contact (String first, String last, String telephone) { } firstName = first; lastName= last; phone telephone; // Returns a description of this contact as a string. //- public String toString() { return lastName + ", "+firstName + "\t" + phone; } // Returns a description of this contact as a string. //--- public boolean equals (Object other) { return (lastName.equals(((Contact) other).getLastName()) && firstName.equals(((Contact) other).getFirstName())); // Use String equals // Uses both last and first names to determine ordering. //- publ public int compareTo (Object other) int result; String other First = ((Contact)other).getFirstName(); String other Last = ((Contact)other).getLastName(); if (lastName.equals (other Last)) result = firstName.compareTo (other First); // String compare To else result lastName.compareTo (other Last); // String compare To return result; // First name accessor. 11- public String getFirstName () { return firstName; } // - // Last name accessor. //- public String getLastName () { return lastName;
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);
Transcribed Image Text: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);
Expert Solution
steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Arrays
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.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
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)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education