Ask Question
2 June, 08:43

a. Student class extends Person class. Person class has data member Name, and methods to set and get Name. b. Create an ArrayList for storing Students attending the course. There are 10 students enrolled. c. Append another student to the list. d. Insert another student at the beginning of a list. e. Find the number of students in the list. f. Remove a given student from the list. g. Retrieve a student at a specified index from the list. h. Check whether a student is in the list. i. Print the list of students. j. Clear the list of students.

+4
Answers (1)
  1. 2 June, 09:05
    0
    See explaination for the program code.

    Explanation:

    Replace the student names with names of your choice I used dummy names in the following program

    Solution:

    import java. util. ArrayList;

    public class Test {

    public static void main (String[] args) {

    Student st=new Student ();

    st. setOfActivites ();

    }

    }

    class Person

    {

    //data member as specified in the question

    String name;

    //Below are methods specified in the question

    void setName (String name)

    {

    this. name=name;

    }

    String getName ()

    {

    return this. name;

    }

    }

    class Student extends Person

    {

    void setOfActivites ()

    {

    ArrayList students=new ArrayList ();

    //b) in the question i. e. enrolling 10 students

    students. add ("a");

    students. add ("b");

    students. add ("c");

    students. add ("d");

    students. add ("e");

    students. add ("f");

    students. add ("g");

    students. add ("h");

    students. add ("i");

    students. add ("j");

    //c) Appending another student

    students. add ("z");

    //d) Inserting student at beginning of the list

    students. add (0, "x");

    //e) Finding number of students

    int n=students. size ();

    System. out. println ("Number of students at present"+n);

    //f) Removing a given student replace the index with your value of choice

    int index=4;

    students. remove (index);

    //g) Retrieving student from a particular index

    index=5;

    System. out. println ("Student at "+index+" is "+students. get (index));

    //h) Checking for a student

    boolean b=students. contains ("a");

    if (b)

    System. out. println ("Given student exists");

    else

    System. out. println ("Given student does not exist");

    //i) Printing the list of students

    System. out. println ("List of students is");

    System. out. println (students);

    //j) Clearing the list of students

    students. clear ();

    }

    }
Know the Answer?
Not Sure About the Answer?
Find an answer to your question ✅ “a. Student class extends Person class. Person class has data member Name, and methods to set and get Name. b. Create an ArrayList for ...” in 📘 Computers and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers