AEQUALIS Software Solutions – Fresher Interview Questions & Answers – Part 1

AEQUALIS Software Solutions – Fresher Interview Questions & Answers – Part 1

This blog explains about AEQUALIS Software Solutions – Fresher Interview Questions & Answers – Part 1 and is given below : 

1. Write a Java console program using collections to manage the student details.

a. Use below class for following methods(b.c.d.e) to use in main method

Public class Student{

private Long id;

private String name;

 private String std:

 private String address;

 //assume that there are getters and setters for the array

}

#include <iostream>

#include <stdlib.h>

#include <time.h>

#include <algorithm>

#include <ctime>

#include <cmath>

#include <string>

#include <cstdlib>

using namespace std;

 

class Student

{

private:

        int ID;

        string name;

 

public:

        Student();

        Student(int ID, string name);

        void setStudent(int ID, string name);

        int getID();

        string getName();

        void print();

};

Student::Student()

{

        ID = 0;

        name = “”;

}

Student::Student(int ID, string name)

{

        this->ID = ID;

        this->name = name;

}

 

void Student::setStudent(int ID, string name)

{

        this->ID = ID;

        this->name = name;

}

 

int Student::getID()

{

        return ID;

}

 

string Student::getName()

{

        return name;

}

 

 

void Student::print()

{

        cout << “ID : ” << ID << endl;

        cout << “Name : ” << name << endl;

}

int main()

{

        Student s;

        int ID;

        string name;

 

        cout << “Enter ID “;

        cin >> ID;

        cout << “Enter name “;

        cin >> name;

        s.setStudent(ID, name);

        s.print();

        return 0;

}

int const size = 1000;

        int i = 0;

        char x[size];

        cout << “enter your courses”;

        cin.getline(x, size);

        while (x[i] != ‘/0’) {

               cout << x[i];

                       i++;

        }

        cout << endl;

*/

Edit & Run

b. Write a function to add student details to List or array . How to add elements to an ArrayList?

We add elements to an ArrayList by using add() method, this method has couple of variations, which we can use based on the requirement. For example: If we want to add the element at the end of the List then simply do it like this:

  1. add(“Steve”); //This will add “Steve” at the end of List
  2. To add the element at the specified location in ArrayList, we can specify the index in the add method like this:
  3. add(3, “Steve”); //This will add “Steve” at the fourth position
  4. Lets write the complete code:
  5. importutil.*;
  6. class JavaExample{
  7. public static void main(String args[]){ 
  8. ArrayList<String> alist=new ArrayList<String>(); 
  9. add(“Steve”);
  10. add(“Tim”);
  11. add(“Lucy”);
  12. add(“Pat”);
  13. add(“Angela”);
  14. add(“Tom”);
  15. //displaying elements
  16. System.out.println(alist);
  17. //Adding “Steve” at the fourth position
  18. add(3, “Steve”);
  19. //displaying elements
  20. System.out.println(alist);
  21. }
  22. }
  23. Output:

  24. [Steve, Tim, Lucy, Pat, Angela, Tom]
  25. [Steve, Tim, Lucy, Steve, Pat, Angela, Tom]

    c. Write a function to get list of student details from list or array

// Java program to illustrate customArraylist in Java

import java.util.ArrayList;

 

class CustomArrayList

{

    // custom class which has data type

    // class has defined the type of data ArrayList

    // size of input 4

    int n=4;

 

    // the custom datatype class

    class Data

    {

        // global variables of the class

        int roll;

        String name;

        int marks;

        long phone;

 

        // constructor has type of data that is required

        Data(int roll, String name, int marks, long phone)

        {

            // initialize the input variable from main

            // function to the global variable of the class

            this.roll = roll;

            this.name = name;

            this.marks = marks;

            this.phone = phone;

        }

    }

 

    public static void main(String args[])

    {

        // suppose the custom input data

        int roll[] = {1, 2, 3, 4};

        String name[] = {“Shubham”, “Atul”, “Ayush”, “Rupesh”};

        int marks[] = {100, 99, 93, 94};

        long phone[] = {8762357381L, 8762357382L, 8762357383L,

                        8762357384L

                       };

 

        // Create an object of the class

        CustomArrayList custom = new CustomArrayList();

 

        // and call the function to add the values to the arraylist

        custom.addValues(roll, name, marks, phone);

    }

 

    public void addValues(int roll[], String name[], int marks[],

                          long phone[])

    {

        // local custom arraylist of data type

        // Data having (int, String, int, long) type

        // from the class

        ArrayList<Data> list=new ArrayList<>();

 

        for (int i = 0; i < n; i++)

        {

            // create an object and send values to the

            // constructor to be saved in the Data class

            list.add(new Data(roll[i], name[i], marks[i],

                                              phone[i]));

        }

 

        // after adding values printing the values to test

        // the custom arraylist

        printValues(list);

    }

 

    public void printValues(ArrayList<Data> list)

    {

        // list- the custom arraylist is sent from

        // previous function

 

        for (int i = 0; i < n; i++)

        {

            // the data received from arraylist is of Data type

            // which is custom (int, String, int, long)

            // based on class Data

 

            Data data = list.get(i);

 

            // data variable of type Data has four primitive datatypes

            // roll -int

            // name- String

            // marks- int

            // phone- long

            System.out.println(data.roll+” “+data.name+” “

                               +data.marks+” “+data.phone);

        }

    }

}

Output:

1 Shubham 100 8762357381

2 Atul 99 8762357382

3 Ayush 93 8762357383

4 Rupesh 94 8762357384

d. Write a function to remove student details by id from List or array

We use remove() method to remove elements from an ArrayList, Same as add() method, this method also has few variations.

For example:

import java.util.*;

class JavaExample{

   public static void main(String args[]){

      ArrayList<String> alist=new ArrayList<String>();

      alist.add(“Steve”);

      alist.add(“Tim”);

      alist.add(“Lucy”);

      alist.add(“Pat”);

      alist.add(“Angela”);

      alist.add(“Tom”);

       //displaying elements

      System.out.println(alist);

       //Removing “Steve” and “Angela”

      alist.remove(“Steve”);

      alist.remove(“Angela”);

       //displaying elements

      System.out.println(alist);

       //Removing 3rd element

      alist.remove(2);

       //displaying elements

      System.out.println(alist);

   }

}

Output:

[Steve, Tim, Lucy, Pat, Angela, Tom]

[Tim, Lucy, Pat, Tom]

[Tim, Lucy, Tom]

e.Write a function to modify student details by id in List or array

This section is about the methods transforming or reordering the array.

map

The arr.map method is one of the most useful and often used.

The syntax is:

let result = arr.map(function(item, index, array) {

  // returns the new value instead of item

})

It calls the function for each element of the array and returns the array of results.

For instance, here we transform each element into its length:

let lengths = [“Bilbo”, “Gandalf”, “Nazgul”].map(item => item.length);

alert(lengths); // 5,7,6

REFERENCES :

https://www.geeksforgeeks.org/custom-arraylist-java/

https://www.geeksforgeeks.org/student-data-management-c/