AdvJava Day2Assignments
AdvJava Day2Assignments
Collections
Concepts: Collections
1. Write a program to add list of student names to ArrayList and it should find a particular name whether
it exists or not in the list.
SOLUTION
package advjavaass2;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;
2. Create a Product class with Product Id & Product Name. Write a program to accept information of 10
products and store that in Hash Table. Search a particular product in the Hash Table. Remove a
particular product id and product name from the Hash Table.
The product list is as follows:
SOLUTION
package advjavaass2;
import java.util.Hashtable;
import java.util.Scanner;
public class Product {
Note : addInput( ) and display( ) should not be member functions of Employee class.
SOLUTION
package advjavaass2;
}
package advjavaass2;
import java.util.Vector;
public class TestEmployeeCollection {
Vector<Employee> v =addInput();
display(v);
}
public static Vector<Employee> addInput()
{
Employee e1=new Employee(101,"deepika","uran");
Employee e2=new Employee(101,"bharat","patna");
Employee e3=new Employee(103,"sana","thane");
Vector<Employee> v = new Vector<Employee>();
v.add(e1);
v.add(e2);
v.add(e3);
return v;
}
public static void display(Vector<Employee>v)
{
for(Employee e:v)
{
System.out.println(e.getEmpid()+"\t"+e.getEname()+"\t"+e.getAddress());
}
Option A should accept First Name and SurName from command prompt
and save that to Vector object
Option B it has to display how many names entered in the vector object
package advjavaass2;
import java.util.Scanner;
import java.util.Vector;
if(choice==1)
{
v1.add(new Name(sc.next(),sc.next()));
}
}
System.out.println("enter the choice:");
System.out.println("\n1.Add new phone book entry \n2.Search Phone Number
\n3.Quit.");
choice=sc.nextInt();
if(choice==2)
{
System.out.println("number of entry:"+v1.size());
}
System.out.println("thank you");