Friday 20 April 2018

HashSet code


package javaapplication37;

import java.util.HashSet;
import java.util.Scanner;

class employee
{
int id,salary;
String name;

public employee(String name,int id,int salary)
{

    this.id=id;
    this.name=name;
    this.salary=salary;
}



}





public class JavaApplication37

{

   
    public static void main(String[] args)
    {
        char c='y',c2='y';
        String n;
        int id=10231,salary,op;
        Scanner sc=new Scanner(System.in);
        HashSet<employee> li=new HashSet<employee>();
       
       
        while(c!='n' && c!='N')
        {
            System.out.println("Enter the Name of Employee ");
            n=sc.next();
            System.out.println("Enter the Salary: ");
            salary=sc.nextInt();
            li.add(new employee(n,id,salary));
            id++;
            System.out.println("Data Successfully inserted......\nDo you want to continue (y/n) ? ");
           c= sc.next().charAt(0);
           
        }
       
       
        while(c2!='n' && c2!='N' )
       {
     
        System.out.println("Enter the no to select any operation:");
        System.out.println("Press 1 to Delete a Record");
        System.out.println("Press 2 to view all Record");
        System.out.println("Press 3 to Delete all Record");
        System.out.println("Press 4 to Add new Record");
       
        op=sc.nextInt();
       
        switch(op)
        {
         case 1:
                 System.out.println("Enter the id of Employee:");
                  id =sc.nextInt();
                 li.remove(id-1);
                System.out.println("Record deleted.....");
                break;
               
              case 2:
                boolean b=li.isEmpty();
                  if (b==true)
                  {
                      System.out.println("There is no record in the list........");   
                  }
                  else  {
                  for(employee obj:li)
                  {
                      System.out.println("Student id: "+obj.id);
                      System.out.println("name of sutdent is : "+obj.name);
                      System.out.println("Marks of sutdent is : "+obj.salary);
                      System.out.println("----------------------------------------");
                     
                 
                  }
                 
                  }
                 
                break;
               
             case 3:
                 li.removeAll(li);
                 System.out.println("All records deleted.......");
                break;
               
               
             case 4:
                 c='y';
                   while(c!='n' && c!='N')
        {
            System.out.println("Enter the Name of Employee ");
            n=sc.next();
            System.out.println("Enter the Salary: ");
            salary=sc.nextInt();
            li.add(new employee(n,id,salary));
            id++;
            System.out.println("Data Successfully inserted......\nDo you want to continue (y/n) ? ");
           c= sc.next().charAt(0);
           
        }
               
               
                 break;
               
              default:
                  break;
     
       
        }
       
        }
       
       
       
        for(employee e:li)
        {
            System.out.println("Id is: "+e.id);
            System.out.println("Name is: "+e.name);
            System.out.println("Salary is :"+e.salary);
        }
     
    }
   
}

Pass Dynamically Added Html Table Records List To Controller In Asp.net MVC

Controller Code: using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Mvc; using ...