Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Csc help Write a class called TelDirectory that implements the comparable interf

ID: 3671746 • Letter: C

Question

Csc help Write a class called TelDirectory that implements the comparable interface. The class should contain tow fields name (String) and phone number (String). Write the necessary constructors, accessors, mutors and other methods. Write client class that creates an ArrayList of 10 TelDirectory objects called list. -Point the list. -Call Collections.sort(list), to sort the elements according to the name. If the names are the same the sort the list using the phone number. -Print the sorted list.

Explanation / Answer

I have written the java code for both the problem.

working java code compiled on ideone:

/* package whatever; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
class Ideone
{
  
   String name;
   String phone_num;
   public String getname()
   {
       return name;
   }
   public String getphone()
   {
       return phone_num;
   }
   public void setname(String n)
   {
       name=n;
   }
   public void setphone(String p)
   {
       phone_num=p;
   }
  
   public class NameComparator implements Comparator<Ideone>
{
public int compare(Ideone o1, Ideone o2)
{
return o1.getname().compareTo(o2.getname());
}
}

   public class PhoneComparator implements Comparator<Ideone>
{
public int compare(Ideone o1, Ideone o2)
{
return o1.getphone().compareTo(o2.getphone());
}
}
  
   public static void main (String[] args) throws java.lang.Exception
   {
       Ideone[] a = new Ideone[10];
      
       // your code goes here
   }
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote