1. -List Inheritance
A 'List' is a dynamic array.
Convert a static array to a
dynamic list. Implement the
following classes:
1. The InvalidStringException
class should inherit the
inbuilt Exception class. It
should also implement the
following methods:
• InvalidStringException(String
& message): calls the
constructor of the parent
class.
2. The ArrayToList class
should implement the
interface MyList. It should
have one class variable of
type ArrayList<String>,
arrayToList. It should also implement the following
methods:
• ArrayToList ( ): initializes the
empty list arrayToList
• void convert(String [] a):
adds the strings in the array
a, to the list arrayToList.
Also prints "I have added
the string: {string} at the
index: {index}". For example
if the string "abcd" is added
at the index 0, it should
print "I have added the
string: abcd at index: 0".
• void replace(int idx):
replaces the string at the
index idx of arrayTolist,
with an empty string, Also
prints "I have replaced the
string: {string} with a null
string”. For example if the
string "abcd" is replaced
with the empty string, it
should print "I have
replaced the string: abcd
with a null string".
• ArrayList<String>
compact(): It should remove
all the empty string from
the list and return the
resulting list.
Note: Please take a look at
the locked stub code to
better understand how
your implementation of
the required classes will be
validated. The locked stub
code in the editor provides
the definition of the
interface MyList. It also
validates the
implementation of
InvalidStringException and
ArrayToList classes.
Constraints
- 1 ≤ n  ≤ 100
-1  ≤ length(a[i] ) ≤5

Code:
//// <<<<<======== Click here to expand the locked stub code
import java.util.*;


interface MyList{
 void convert(String[] a);
 void replace(int idx); 
 ArrayList<String> compact();
}
/*
This is here only for visibility. Please do not take the code below out of the comments. 
import java.util.*;


interface MyList{
 void convert(String[] a);
 void replace(int idx);    
 ArrayList<String> compact();
}


This is here only for visibility. Please do not take the code above out of the comments.
*/


// ================ PLEASE WRITE CODE HERE =============


//Write your implementation of the InvalidStringException and the ArrayToList classes below
    
class InvalidStringException{
    
  
}


class ArrayToList {
    
}


    
 
    
 


// <<<<<======== Click here to expand the locked stub. Please take a look at the locked stub code to better understand how your implementation of the required classes will be validated. 
//PlEASE DO NOT ATTEMPT TO MODIFY THE CODE BELOW !!!!!!. 
public class Solution{
  
  public static void main(String[] args){
  
  Scanner sc = new Scanner(System.in);
  Random rand = new Random(0);


  int n = Integer.parseInt(sc.nextLine());
  String[] a = new String[n];


  for(int i = 0; i < n; i++)
    a[i] = sc.nextLine();
  
  MyList obj = new ArrayToList();


  obj.convert(a);
  int x = rand.nextInt(n);
  for(int i = 0; i < x; i++)
    obj.replace(rand.nextInt(n));




  ArrayList<String> s = obj.compact();
  




  for (int i = 0; i < s.size(); i++){
    if(s.get(i).charAt(0) >= 97 && s.get(i).charAt(0) <= 122){
     try{
       throw new InvalidStringException("This is an invalid string");
     }
     catch(InvalidStringException e){System.out.println(e.getMessage());}   
    }
  }




}
}