diff --git a/Day 12/EnumDemo/bin/com/demo/beans/Person.class b/Day 12/EnumDemo/bin/com/demo/beans/Person.class new file mode 100644 index 0000000..89a4024 Binary files /dev/null and b/Day 12/EnumDemo/bin/com/demo/beans/Person.class differ diff --git a/Day 12/EnumDemo/bin/com/demo/enums/Coffee.class b/Day 12/EnumDemo/bin/com/demo/enums/Coffee.class new file mode 100644 index 0000000..28efb91 Binary files /dev/null and b/Day 12/EnumDemo/bin/com/demo/enums/Coffee.class differ diff --git a/Day 12/EnumDemo/bin/com/demo/enums/Gender.class b/Day 12/EnumDemo/bin/com/demo/enums/Gender.class new file mode 100644 index 0000000..c469f19 Binary files /dev/null and b/Day 12/EnumDemo/bin/com/demo/enums/Gender.class differ diff --git a/Day 12/EnumDemo/bin/com/demo/test/TestCoffee.class b/Day 12/EnumDemo/bin/com/demo/test/TestCoffee.class new file mode 100644 index 0000000..4e3c731 Binary files /dev/null and b/Day 12/EnumDemo/bin/com/demo/test/TestCoffee.class differ diff --git a/Day 12/EnumDemo/bin/com/demo/test/TestPerson.class b/Day 12/EnumDemo/bin/com/demo/test/TestPerson.class new file mode 100644 index 0000000..8068d56 Binary files /dev/null and b/Day 12/EnumDemo/bin/com/demo/test/TestPerson.class differ diff --git a/Day 12/EnumDemo/src/com/demo/beans/Person.java b/Day 12/EnumDemo/src/com/demo/beans/Person.java new file mode 100644 index 0000000..eb48280 --- /dev/null +++ b/Day 12/EnumDemo/src/com/demo/beans/Person.java @@ -0,0 +1,44 @@ +package com.demo.beans; + +import com.demo.enums.Gender; + +public class Person { + private int pid; + private String pname; + private Gender gender; +public Person() { + super(); +} +public Person(int pid, String pname, Gender gender) { + super(); + this.pid = pid; + this.pname = pname; + this.gender = gender; +} +public int getPid() { + return pid; +} +public void setPid(int pid) { + this.pid = pid; +} +public String getPname() { + return pname; +} +public void setPname(String pname) { + this.pname = pname; +} + +public Gender getGender() { + return gender; +} + +public void setGender(Gender gender) { + this.gender = gender; +} +@Override +public String toString() { + return "Person [pid=" + pid + ", pname=" + pname + ", gender=" + gender + "]"; +} + + +} diff --git a/Day 12/EnumDemo/src/com/demo/enums/Coffee.java b/Day 12/EnumDemo/src/com/demo/enums/Coffee.java new file mode 100644 index 0000000..cd6e641 --- /dev/null +++ b/Day 12/EnumDemo/src/com/demo/enums/Coffee.java @@ -0,0 +1,21 @@ +package com.demo.enums; + +public enum Coffee { + small(150,150.00),medium(200,250.00),large(300,350.00); + private int size; + private double price; + private Coffee(int size,double price) { + System.out.println("in Coffee constructor "+size+"---"+price); + this.size=size; + this.price=price; + } + public int getSize() { + return size; + } + + public double getPrice() { + return price; + } + + +} diff --git a/Day 12/EnumDemo/src/com/demo/enums/Gender.java b/Day 12/EnumDemo/src/com/demo/enums/Gender.java new file mode 100644 index 0000000..06fda6b --- /dev/null +++ b/Day 12/EnumDemo/src/com/demo/enums/Gender.java @@ -0,0 +1,6 @@ +package com.demo.enums; + +public enum Gender { + male,female; + +} diff --git a/Day 12/EnumDemo/src/com/demo/test/TestCoffee.java b/Day 12/EnumDemo/src/com/demo/test/TestCoffee.java new file mode 100644 index 0000000..2b241e2 --- /dev/null +++ b/Day 12/EnumDemo/src/com/demo/test/TestCoffee.java @@ -0,0 +1,25 @@ +package com.demo.test; + +import com.demo.enums.Coffee; + +public class TestCoffee { + + public static void main(String[] args) { + Coffee c=Coffee.small; + switch(c) { + case small->{ + System.out.println("Small selected "+ c.getSize()+"---->"+c.getPrice()); + } + case medium->{ + System.out.println("Medium selected"+ c.getSize()+"---->"+c.getPrice()); + } + case large->{ + System.out.println("Large selected"+ c.getSize()+"---->"+c.getPrice()); + } + } + + } + + + +} diff --git a/Day 12/EnumDemo/src/com/demo/test/TestPerson.java b/Day 12/EnumDemo/src/com/demo/test/TestPerson.java new file mode 100644 index 0000000..c31011d --- /dev/null +++ b/Day 12/EnumDemo/src/com/demo/test/TestPerson.java @@ -0,0 +1,28 @@ +package com.demo.test; + +import java.util.Scanner; + +import com.demo.beans.Person; +import com.demo.enums.Gender; + +public class TestPerson { +public static void main(String[] args) { + Person p=new Person(11,"Shalini",Gender.female); + System.out.println(p); + for(Gender g:Gender.values()) { + System.out.println(g); + } + Scanner sc=new Scanner(System.in); + System.out.println("enetr id"); + int pid=sc.nextInt(); + System.out.println("enter name"); + String nm=sc.next(); + System.out.println("enetr gender"); + String g=sc.next(); + Gender g1=Gender.valueOf(g); + Person p2=new Person(pid,nm,g1); + System.out.println(p2); + System.out.println(Gender.valueOf(g)); + +} +} diff --git a/Day 12/Java 8 Features.pdf b/Day 12/Java 8 Features.pdf new file mode 100644 index 0000000..9d88db0 Binary files /dev/null and b/Day 12/Java 8 Features.pdf differ diff --git a/Day 12/Java8Features/bin/com/demo/test/TestClass.class b/Day 12/Java8Features/bin/com/demo/test/TestClass.class new file mode 100644 index 0000000..445e190 Binary files /dev/null and b/Day 12/Java8Features/bin/com/demo/test/TestClass.class differ diff --git a/Day 12/Java8Features/src/com/demo/test/TestClass.java b/Day 12/Java8Features/src/com/demo/test/TestClass.java new file mode 100644 index 0000000..fdc6ca8 --- /dev/null +++ b/Day 12/Java8Features/src/com/demo/test/TestClass.java @@ -0,0 +1,13 @@ +package com.demo.test; + +import java.util.List; + +public class TestClass { + + public static void main(String[] args) { + List lst=List.of(3,2,4,15,26,33,7,4,5); + lst.stream().filter(e->e>10).forEach(System.out::println); + + } + +} diff --git a/Day 12/OrderManagementSystem/bin/com/demo/beans/Customer.class b/Day 12/OrderManagementSystem/bin/com/demo/beans/Customer.class new file mode 100644 index 0000000..3f9be08 Binary files /dev/null and b/Day 12/OrderManagementSystem/bin/com/demo/beans/Customer.class differ diff --git a/Day 12/OrderManagementSystem/bin/com/demo/beans/Item.class b/Day 12/OrderManagementSystem/bin/com/demo/beans/Item.class new file mode 100644 index 0000000..608960c Binary files /dev/null and b/Day 12/OrderManagementSystem/bin/com/demo/beans/Item.class differ diff --git a/Day 12/OrderManagementSystem/bin/com/demo/dao/OrderDao.class b/Day 12/OrderManagementSystem/bin/com/demo/dao/OrderDao.class new file mode 100644 index 0000000..e204a36 Binary files /dev/null and b/Day 12/OrderManagementSystem/bin/com/demo/dao/OrderDao.class differ diff --git a/Day 12/OrderManagementSystem/bin/com/demo/dao/OrderDaoImpl.class b/Day 12/OrderManagementSystem/bin/com/demo/dao/OrderDaoImpl.class new file mode 100644 index 0000000..0cf62e7 Binary files /dev/null and b/Day 12/OrderManagementSystem/bin/com/demo/dao/OrderDaoImpl.class differ diff --git a/Day 12/OrderManagementSystem/bin/com/demo/service/OrderService.class b/Day 12/OrderManagementSystem/bin/com/demo/service/OrderService.class new file mode 100644 index 0000000..621201f Binary files /dev/null and b/Day 12/OrderManagementSystem/bin/com/demo/service/OrderService.class differ diff --git a/Day 12/OrderManagementSystem/bin/com/demo/service/OrderServiceImpl.class b/Day 12/OrderManagementSystem/bin/com/demo/service/OrderServiceImpl.class new file mode 100644 index 0000000..a4b0c88 Binary files /dev/null and b/Day 12/OrderManagementSystem/bin/com/demo/service/OrderServiceImpl.class differ diff --git a/Day 12/OrderManagementSystem/bin/com/demo/test/TestBackedCollection.class b/Day 12/OrderManagementSystem/bin/com/demo/test/TestBackedCollection.class new file mode 100644 index 0000000..a8ffbbc Binary files /dev/null and b/Day 12/OrderManagementSystem/bin/com/demo/test/TestBackedCollection.class differ diff --git a/Day 12/OrderManagementSystem/bin/com/demo/test/TestCollections.class b/Day 12/OrderManagementSystem/bin/com/demo/test/TestCollections.class new file mode 100644 index 0000000..f64acc0 Binary files /dev/null and b/Day 12/OrderManagementSystem/bin/com/demo/test/TestCollections.class differ diff --git a/Day 12/OrderManagementSystem/bin/com/demo/test/TestOrdemgntSystem.class b/Day 12/OrderManagementSystem/bin/com/demo/test/TestOrdemgntSystem.class new file mode 100644 index 0000000..27df139 Binary files /dev/null and b/Day 12/OrderManagementSystem/bin/com/demo/test/TestOrdemgntSystem.class differ diff --git a/Day 12/OrderManagementSystem/src/com/demo/beans/Customer.java b/Day 12/OrderManagementSystem/src/com/demo/beans/Customer.java new file mode 100644 index 0000000..caa7498 --- /dev/null +++ b/Day 12/OrderManagementSystem/src/com/demo/beans/Customer.java @@ -0,0 +1,57 @@ +package com.demo.beans; + +public class Customer { + private int cid; + private String cname; + private String mob; + public Customer() { + super(); + } + public Customer(int cid, String cname, String mob) { + super(); + this.cid = cid; + this.cname = cname; + this.mob = mob; + } + + + public Customer(int cid) { + super(); + this.cid = cid; + } + + @Override + public int hashCode() { + System.out.println("in hashcode "+cid); + return cid; ///+cname.hashCode(); + } + @Override + public boolean equals(Object obj) { + System.out.println("in equals method "+this.cid+"-----"+((Customer)obj).cid); + return this.cid==((Customer)obj).cid; + } + public int getCid() { + return cid; + } + public void setCid(int cid) { + this.cid = cid; + } + public String getCname() { + return cname; + } + public void setCname(String cname) { + this.cname = cname; + } + public String getMob() { + return mob; + } + public void setMob(String mob) { + this.mob = mob; + } + @Override + public String toString() { + return "Customer [cid=" + cid + ", cname=" + cname + ", mob=" + mob + "]"; + } + + +} diff --git a/Day 12/OrderManagementSystem/src/com/demo/beans/Item.java b/Day 12/OrderManagementSystem/src/com/demo/beans/Item.java new file mode 100644 index 0000000..0ec805f --- /dev/null +++ b/Day 12/OrderManagementSystem/src/com/demo/beans/Item.java @@ -0,0 +1,61 @@ +package com.demo.beans; + +public class Item { + private int iid; + private String iname; + private int qty; + private double price; +public Item() { + super(); +} +public Item(int iid, String iname, int qty, double price) { + super(); + this.iid = iid; + this.iname = iname; + this.qty = qty; + this.price = price; +} + + +public Item(int iid) { + super(); + this.iid = iid; +} + + +@Override +public boolean equals(Object obj) { + System.out.println("in item equals method"+this.iid+"----"+((Item)obj).iid); + return this.iid==((Item)obj).iid; +} + +public int getIid() { + return iid; +} +public void setIid(int iid) { + this.iid = iid; +} +public String getIname() { + return iname; +} +public void setIname(String iname) { + this.iname = iname; +} +public int getQty() { + return qty; +} +public void setQty(int qty) { + this.qty = qty; +} +public double getPrice() { + return price; +} +public void setPrice(double price) { + this.price = price; +} +@Override +public String toString() { + return "Item [iid=" + iid + ", iname=" + iname + ", qty=" + qty + ", price=" + price + "]"; +} + +} diff --git a/Day 12/OrderManagementSystem/src/com/demo/dao/OrderDao.java b/Day 12/OrderManagementSystem/src/com/demo/dao/OrderDao.java new file mode 100644 index 0000000..faf22dc --- /dev/null +++ b/Day 12/OrderManagementSystem/src/com/demo/dao/OrderDao.java @@ -0,0 +1,24 @@ +package com.demo.dao; + +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; + +import com.demo.beans.Customer; +import com.demo.beans.Item; + +public interface OrderDao { + + boolean save(Customer c, List lst); + + Map> findAll(); + + Entry> findById(int cid); + + boolean removeById(int cid); + + boolean addNewItem(int cid, Item item); + + boolean deleteById(int cid, int iid); + +} diff --git a/Day 12/OrderManagementSystem/src/com/demo/dao/OrderDaoImpl.java b/Day 12/OrderManagementSystem/src/com/demo/dao/OrderDaoImpl.java new file mode 100644 index 0000000..cb0086f --- /dev/null +++ b/Day 12/OrderManagementSystem/src/com/demo/dao/OrderDaoImpl.java @@ -0,0 +1,75 @@ +package com.demo.dao; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; +import java.util.Set; + +import com.demo.beans.Customer; +import com.demo.beans.Item; + +public class OrderDaoImpl implements OrderDao{ + static Map> hm; + static { + hm=new HashMap<>(); + Customer c1=new Customer(10,"Sushrut","33333"); + List lst=new ArrayList<>(); + lst.add(new Item(1001,"Chair",34,5678)); + lst.add(new Item(1002,"Table",30,7678)); + hm.put(c1, lst); + Customer c2=new Customer(11,"Pranav","4444"); + List lst1=new ArrayList<>(); + lst1.add(new Item(1001,"Shelf",40,2678)); + lst1.add(new Item(1002,"drawer",20,5678)); + hm.put(c2, lst1); + } +@Override +public boolean save(Customer c, List lst) { + if(!hm.containsKey(c)) { + hm.put(c,lst); + return true; + } + return false; +} +@Override +public Map> findAll() { + return hm; +} +@Override +public Entry> findById(int cid) { + Set>> cset=hm.entrySet(); + for(Map.Entry> e:cset) { + if(e.getKey().getCid()==cid) + return e; + } + return null; + +} +@Override +public boolean removeById(int cid) { + List lst= hm.remove(new Customer(cid)); + return lst!=null; +} +@Override +public boolean addNewItem(int cid, Item item) { + List lst=hm.get(new Customer(cid)); + if(lst!=null) { + lst.add(item); + return true; + } + return false; +} +@Override +public boolean deleteById(int cid, int iid) { + List lst=hm.get(new Customer(cid)); + if(lst!=null) { + //add equals method in Item class + //also add constructor with only id in Item class + return lst.remove(new Item(iid)); + + } + return false; +} +} diff --git a/Day 12/OrderManagementSystem/src/com/demo/service/OrderService.java b/Day 12/OrderManagementSystem/src/com/demo/service/OrderService.java new file mode 100644 index 0000000..f86934f --- /dev/null +++ b/Day 12/OrderManagementSystem/src/com/demo/service/OrderService.java @@ -0,0 +1,24 @@ +package com.demo.service; + +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; + +import com.demo.beans.Customer; +import com.demo.beans.Item; + +public interface OrderService { + + boolean addNewCustomer(); + + Map> displayAll(); + + Entry> findByCustomer(int cid); + + boolean deleteById(int cid); + + boolean addNewItem(int cid, Item item); + + boolean removeItemById(int cid, int iid); + +} diff --git a/Day 12/OrderManagementSystem/src/com/demo/service/OrderServiceImpl.java b/Day 12/OrderManagementSystem/src/com/demo/service/OrderServiceImpl.java new file mode 100644 index 0000000..8918006 --- /dev/null +++ b/Day 12/OrderManagementSystem/src/com/demo/service/OrderServiceImpl.java @@ -0,0 +1,80 @@ +package com.demo.service; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; +import java.util.Scanner; + +import com.demo.beans.Customer; +import com.demo.beans.Item; +import com.demo.dao.OrderDao; +import com.demo.dao.OrderDaoImpl; + +public class OrderServiceImpl implements OrderService{ + private OrderDao odao; + + public OrderServiceImpl() { + super(); + odao=new OrderDaoImpl(); + } + + @Override + public boolean addNewCustomer() { + Scanner sc=new Scanner(System.in); + //accept customer details + System.out.println("Enter id"); + int cid=sc.nextInt(); + System.out.println("Enter name"); + String nm=sc.next(); + System.out.println("Enter mobile"); + String mob=sc.next(); + Customer c=new Customer(cid,nm,mob); + //accept list of items + List lst=new ArrayList<>(); + String ans=null; + do { + System.out.println("enter item id"); + int id=sc.nextInt(); + System.out.println("enter item name"); + String inm=sc.next(); + System.out.println("enter item qty"); + int qty=sc.nextInt(); + System.out.println("enter item price"); + double price=sc.nextDouble(); + Item item=new Item(id,inm,qty,price); + lst.add(item); + System.out.println("Do you want to continue(y/n)?"); + ans=sc.next(); + }while(ans.equals("y")); + return odao.save(c,lst); + + + } + + @Override + public Map> displayAll() { + return odao.findAll(); + } + + @Override + public Entry> findByCustomer(int cid) { + return odao.findById(cid); + } + + @Override + public boolean deleteById(int cid) { + return odao.removeById(cid); + } + + @Override + public boolean addNewItem(int cid, Item item) { + return odao.addNewItem(cid,item); + } + + @Override + public boolean removeItemById(int cid, int iid) { + return odao.deleteById(cid,iid); + } + +} diff --git a/Day 12/OrderManagementSystem/src/com/demo/test/TestBackedCollection.java b/Day 12/OrderManagementSystem/src/com/demo/test/TestBackedCollection.java new file mode 100644 index 0000000..f00b88d --- /dev/null +++ b/Day 12/OrderManagementSystem/src/com/demo/test/TestBackedCollection.java @@ -0,0 +1,28 @@ +package com.demo.test; + +import java.util.Set; +import java.util.SortedSet; +import java.util.TreeSet; + +public class TestBackedCollection { + + public static void main(String[] args) { + Set cset=new TreeSet<>(); + for(int i=1;i<=10;i++) { + cset.add(i+20); + } + cset.forEach(System.out::println); + SortedSet hs=((SortedSet) cset).headSet(25); + System.out.println(hs); + SortedSet ts=((SortedSet) cset).tailSet(25); + System.out.println(ts); + cset.add(15); + cset.add(36); + System.out.println(hs); + System.out.println(ts); + + + + } + +} diff --git a/Day 12/OrderManagementSystem/src/com/demo/test/TestCollections.java b/Day 12/OrderManagementSystem/src/com/demo/test/TestCollections.java new file mode 100644 index 0000000..3063953 --- /dev/null +++ b/Day 12/OrderManagementSystem/src/com/demo/test/TestCollections.java @@ -0,0 +1,30 @@ +package com.demo.test; + +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +import java.util.Map; + +public class TestCollections { + + public static void main(String[] args) { + List lst=Arrays.asList(12,23,45,67,89,12,13); + //Collections.sort(lst); + System.out.println(lst); + System.out.println("Maximum: "+Collections.max(lst)); + System.out.println("Minimum: "+Collections.min(lst)); + Collections.shuffle(lst); + System.out.println(lst); + //shuffles the order of list + Collections.shuffle(lst); + System.out.println(lst); + + List lst1=List.of(12,11,45,23,56); + System.out.println(lst1); + Map cmap=Map.of(1,"a",2,"b",3,"c",4,"d"); + System.out.println(cmap); + + + } + +} diff --git a/Day 12/OrderManagementSystem/src/com/demo/test/TestOrdemgntSystem.java b/Day 12/OrderManagementSystem/src/com/demo/test/TestOrdemgntSystem.java new file mode 100644 index 0000000..543b972 --- /dev/null +++ b/Day 12/OrderManagementSystem/src/com/demo/test/TestOrdemgntSystem.java @@ -0,0 +1,109 @@ +package com.demo.test; + +import java.util.List; +import java.util.Map; +import java.util.Scanner; +import java.util.Set; + +import com.demo.beans.Customer; +import com.demo.beans.Item; +import com.demo.service.OrderService; +import com.demo.service.OrderServiceImpl; + +public class TestOrdemgntSystem { + + public static void main(String[] args) { + Scanner sc=new Scanner(System.in); + OrderService oservice=new OrderServiceImpl(); + int choice=0; + do { + System.out.println("1. add new customer\n2. display all\n3. display by customer"); + System.out.println("4. delete customer\n5. add a new item in existing order"); + System.out.println("6. delete item from existing order\n7.exit\n choice:"); + choice=sc.nextInt(); + switch(choice) { + case 1->{ + boolean status=oservice.addNewCustomer(); + if(status) { + System.out.println("Added successfully"); + + }else { + System.out.println("Not added"); + } + } + case 2->{ + Map> omap=oservice.displayAll(); + Set keys=omap.keySet(); + keys.forEach(c->System.out.println(c+"---->"+omap.get(c))); + + } + case 3->{ + System.out.println("enter customer id"); + int cid=sc.nextInt(); + Map.Entry> data=oservice.findByCustomer(cid); + if(data!=null) { + System.out.println(data.getKey()+"------>"+data.getValue()); + + } + else { + System.out.println("Not found"); + } + } + case 4->{ + System.out.println("enter customer id"); + int cid=sc.nextInt(); + boolean status=oservice.deleteById(cid); + if(status) { + System.out.println("deleted successfully"); + }else { + System.out.println("not found"); + } + } + case 5->{ + System.out.println("enter customer id"); + int cid=sc.nextInt(); + System.out.println("enter Item id"); + int iid=sc.nextInt(); + System.out.println("enter item name"); + String inm=sc.next(); + System.out.println("enter qty"); + int qty=sc.nextInt(); + System.out.println("enter Item price"); + double price=sc.nextDouble(); + boolean status=oservice.addNewItem(cid,new Item(iid,inm,qty,price)); + if(status){ + System.out.println("added successfully"); + }else { + System.out.println("not found"); + } + } + case 6->{ + System.out.println("enter customer id"); + int cid=sc.nextInt(); + System.out.println("enter Item id"); + int iid=sc.nextInt(); + boolean status=oservice.removeItemById(cid,iid); + if(status){ + System.out.println("deleted successfully"); + }else { + System.out.println("not found"); + } + } + case 7->{ + sc.close(); + System.out.println("Thank you for visiting....."); + } + default->{ + System.out.println("Wrong choice"); + } + + + + + + + } + }while(choice!=7); + } + +} diff --git a/Day 12/ReflectionDemo/bin/com/demo/beans/MyClass.class b/Day 12/ReflectionDemo/bin/com/demo/beans/MyClass.class new file mode 100644 index 0000000..b228694 Binary files /dev/null and b/Day 12/ReflectionDemo/bin/com/demo/beans/MyClass.class differ diff --git a/Day 12/ReflectionDemo/bin/com/demo/test/TestMyClass.class b/Day 12/ReflectionDemo/bin/com/demo/test/TestMyClass.class new file mode 100644 index 0000000..e81a8f1 Binary files /dev/null and b/Day 12/ReflectionDemo/bin/com/demo/test/TestMyClass.class differ diff --git a/Day 12/ReflectionDemo/src/com/demo/beans/MyClass.java b/Day 12/ReflectionDemo/src/com/demo/beans/MyClass.java new file mode 100644 index 0000000..d0ff139 --- /dev/null +++ b/Day 12/ReflectionDemo/src/com/demo/beans/MyClass.java @@ -0,0 +1,43 @@ +package com.demo.beans; + +public class MyClass { + private int n1; + private int n2; + + public MyClass() { + super(); + } + + public MyClass(int n1, int n2) { + super(); + this.n1 = n1; + this.n2 = n2; + } + + public int getN1() { + return n1; + } + + public void setN1(int n1) { + this.n1 = n1; + } + + public int getN2() { + return n2; + } + + public void setN2(int n2) { + this.n2 = n2; + } + + @Override + public String toString() { + return "MyClass [n1=" + n1 + ", n2=" + n2 + "]"; + } + + public void m1(int x) { + System.out.println("in m1 method"); + } + + +} diff --git a/Day 12/ReflectionDemo/src/com/demo/test/TestMyClass.java b/Day 12/ReflectionDemo/src/com/demo/test/TestMyClass.java new file mode 100644 index 0000000..f44ab90 --- /dev/null +++ b/Day 12/ReflectionDemo/src/com/demo/test/TestMyClass.java @@ -0,0 +1,68 @@ +package com.demo.test; + +import java.lang.reflect.Constructor; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.lang.reflect.Field; +import com.demo.beans.MyClass; + + +public class TestMyClass { + + public static void main(String[] args) { + MyClass ob=new MyClass(12,100); + Class cls=ob.getClass(); + Constructor[] carr=cls.getConstructors(); + for(Constructor c:carr) { + System.out.println(c.getName()); + System.out.println(c.getParameters()); + } + + Method[] marr=cls.getMethods(); + for(Method m:marr) { + System.out.println(m.getName()); + if(m.getName().equals("m1")) { + try { + m.invoke(ob, 12); + } catch (IllegalAccessException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (InvocationTargetException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + } + + Field[] farr=cls.getDeclaredFields(); + for(Field f:farr) { + if(f.getName().equals("n1")) + f.setAccessible(true); + System.out.println(f.getName()); + } + + //to change value of private member in the class + try { + Field f=cls.getDeclaredField("n1"); + System.out.println("before changing"); + System.out.println(ob); + f.setAccessible(true); + f.set(ob,100);//ob.setN1(100) + System.out.println("After changing"); + System.out.println(ob); + } catch (NoSuchFieldException | SecurityException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IllegalArgumentException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IllegalAccessException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + + + } + +} diff --git a/Day 13/Exception handling.pdf b/Day 13/Exception handling.pdf new file mode 100644 index 0000000..a36c277 Binary files /dev/null and b/Day 13/Exception handling.pdf differ diff --git a/Day 13/ExceptionDemo/bin/TestExceptiondemo3.class b/Day 13/ExceptionDemo/bin/TestExceptiondemo3.class new file mode 100644 index 0000000..ca77bec Binary files /dev/null and b/Day 13/ExceptionDemo/bin/TestExceptiondemo3.class differ diff --git a/Day 13/ExceptionDemo/bin/com/demo/beans/Employee.class b/Day 13/ExceptionDemo/bin/com/demo/beans/Employee.class new file mode 100644 index 0000000..0e171ae Binary files /dev/null and b/Day 13/ExceptionDemo/bin/com/demo/beans/Employee.class differ diff --git a/Day 13/ExceptionDemo/bin/com/demo/exceptions/NegativeSalaryException.class b/Day 13/ExceptionDemo/bin/com/demo/exceptions/NegativeSalaryException.class new file mode 100644 index 0000000..3655251 Binary files /dev/null and b/Day 13/ExceptionDemo/bin/com/demo/exceptions/NegativeSalaryException.class differ diff --git a/Day 13/ExceptionDemo/bin/com/demo/exceptions/WrongNumberException.class b/Day 13/ExceptionDemo/bin/com/demo/exceptions/WrongNumberException.class new file mode 100644 index 0000000..c2e6c1e Binary files /dev/null and b/Day 13/ExceptionDemo/bin/com/demo/exceptions/WrongNumberException.class differ diff --git a/Day 13/ExceptionDemo/bin/com/demo/service/MyService.class b/Day 13/ExceptionDemo/bin/com/demo/service/MyService.class new file mode 100644 index 0000000..3b80c02 Binary files /dev/null and b/Day 13/ExceptionDemo/bin/com/demo/service/MyService.class differ diff --git a/Day 13/ExceptionDemo/bin/com/demo/test/TestException.class b/Day 13/ExceptionDemo/bin/com/demo/test/TestException.class new file mode 100644 index 0000000..f5fcfe7 Binary files /dev/null and b/Day 13/ExceptionDemo/bin/com/demo/test/TestException.class differ diff --git a/Day 13/ExceptionDemo/bin/com/demo/test/TestException1.class b/Day 13/ExceptionDemo/bin/com/demo/test/TestException1.class new file mode 100644 index 0000000..e4c2f75 Binary files /dev/null and b/Day 13/ExceptionDemo/bin/com/demo/test/TestException1.class differ diff --git a/Day 13/ExceptionDemo/bin/com/demo/test/TestGuessNumber.class b/Day 13/ExceptionDemo/bin/com/demo/test/TestGuessNumber.class new file mode 100644 index 0000000..f7c5f65 Binary files /dev/null and b/Day 13/ExceptionDemo/bin/com/demo/test/TestGuessNumber.class differ diff --git a/Day 13/ExceptionDemo/src/TestExceptiondemo3.java b/Day 13/ExceptionDemo/src/TestExceptiondemo3.java new file mode 100644 index 0000000..0a61446 --- /dev/null +++ b/Day 13/ExceptionDemo/src/TestExceptiondemo3.java @@ -0,0 +1,17 @@ +import com.demo.exceptions.NegativeSalaryException; +import com.demo.service.MyService; + +public class TestExceptiondemo3 { + + public static void main(String[] args) { + MyService ms=new MyService(); + try { + ms.acceptData(); + } catch (NegativeSalaryException e) { + // TODO Auto-generated catch block + System.out.println(e.getMessage()); + } + + } + +} diff --git a/Day 13/ExceptionDemo/src/com/demo/beans/Employee.java b/Day 13/ExceptionDemo/src/com/demo/beans/Employee.java new file mode 100644 index 0000000..22e6753 --- /dev/null +++ b/Day 13/ExceptionDemo/src/com/demo/beans/Employee.java @@ -0,0 +1,44 @@ +package com.demo.beans; +import com.demo.exceptions.NegativeSalaryException; + +public class Employee { + private int eid; + private String ename; + private double sal; +public Employee() { + super(); +} +public Employee(int eid, String ename, double sal) { + super(); + this.eid = eid; + this.ename = ename; + this.sal = sal; +} +public int getEid() { + return eid; +} +public void setEid(int eid) { + this.eid = eid; +} +public String getEname() { + return ename; +} +public void setEname(String ename) { + this.ename = ename; +} +public double getSal() { + return sal; +} +public void setSal(double sal) throws NegativeSalaryException { + if(sal<0) + throw new NegativeSalaryException("Salary cannot be -ve"); + else if (sal <2000) + throw new NegativeSalaryException("salary cannot be < 2000"); + this.sal = sal; +} +@Override +public String toString() { + return "Employee [eid=" + eid + ", ename=" + ename + ", sal=" + sal + "]"; +} + +} diff --git a/Day 13/ExceptionDemo/src/com/demo/exceptions/NegativeSalaryException.java b/Day 13/ExceptionDemo/src/com/demo/exceptions/NegativeSalaryException.java new file mode 100644 index 0000000..8c76c7d --- /dev/null +++ b/Day 13/ExceptionDemo/src/com/demo/exceptions/NegativeSalaryException.java @@ -0,0 +1,8 @@ +package com.demo.exceptions; + +public class NegativeSalaryException extends Exception{ + public NegativeSalaryException(String msg) { + super(msg); + } + +} diff --git a/Day 13/ExceptionDemo/src/com/demo/exceptions/WrongNumberException.java b/Day 13/ExceptionDemo/src/com/demo/exceptions/WrongNumberException.java new file mode 100644 index 0000000..7047e1a --- /dev/null +++ b/Day 13/ExceptionDemo/src/com/demo/exceptions/WrongNumberException.java @@ -0,0 +1,8 @@ +package com.demo.exceptions; + +public class WrongNumberException extends Exception{ + public WrongNumberException(String msg) { + super(msg); + } + +} diff --git a/Day 13/ExceptionDemo/src/com/demo/service/MyService.java b/Day 13/ExceptionDemo/src/com/demo/service/MyService.java new file mode 100644 index 0000000..a68ac0c --- /dev/null +++ b/Day 13/ExceptionDemo/src/com/demo/service/MyService.java @@ -0,0 +1,17 @@ +package com.demo.service; + +import java.util.Scanner; + +import com.demo.beans.Employee; +import com.demo.exceptions.NegativeSalaryException; + +public class MyService { + + public void acceptData() throws NegativeSalaryException{ + Scanner sc=new Scanner(System.in); + Employee emp=new Employee(12,"xxx",45677); + emp.setSal(-2000); + + } + +} diff --git a/Day 13/ExceptionDemo/src/com/demo/test/TestException.java b/Day 13/ExceptionDemo/src/com/demo/test/TestException.java new file mode 100644 index 0000000..43db3a4 --- /dev/null +++ b/Day 13/ExceptionDemo/src/com/demo/test/TestException.java @@ -0,0 +1,42 @@ +package com.demo.test; + +import java.util.InputMismatchException; +import java.util.Scanner; + +public class TestException { + private static int divide(int x, int y) { + return x/y; + } + public static void main(String[] args) { + Scanner sc=new Scanner(System.in); + try { + System.out.println("Enter a number"); + int num=sc.nextInt(); + System.out.println("Enter a number"); + int num1=sc.nextInt(); + //try { + int ans=divide(num,num1); + System.out.println("Division : "+ans); + //}catch(ArithmeticException e) { + // System.out.println(e.getMessage()); + //} + System.out.println("At the end of outer try block"); + }catch(InputMismatchException e) { + System.out.println("Pls enter number"); + //e.printStackTrace(); + //sSystem.out.println(e.getMessage()); + }catch(ArithmeticException|ArrayIndexOutOfBoundsException e){ + System.out.println(e.getMessage()); + }catch(Exception e) { + System.out.println("Error occured"); + System.out.println(e.getMessage()); + } + finally{ + System.out.println("in finally block"); + } + + } + + + +} diff --git a/Day 13/ExceptionDemo/src/com/demo/test/TestException1.java b/Day 13/ExceptionDemo/src/com/demo/test/TestException1.java new file mode 100644 index 0000000..66f46f8 --- /dev/null +++ b/Day 13/ExceptionDemo/src/com/demo/test/TestException1.java @@ -0,0 +1,31 @@ +package com.demo.test; + +import java.util.Scanner; + +import com.demo.exceptions.NegativeSalaryException; + +public class TestException1 { + + public static void main(String[] args) { + Scanner sc =new Scanner(System.in); + for(int i=0;i<3;i++) { + try { + System.out.println("enter salary"); + double sal=sc.nextDouble(); + if(sal<0) { + throw new NegativeSalaryException("Salary cannot be -ve"); + } + System.out.println("Salary "+sal); + break; + }catch(NullPointerException e) { + System.out.println(e.getMessage()); + } catch (NegativeSalaryException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + + } + +} diff --git a/Day 13/ExceptionDemo/src/com/demo/test/TestGuessNumber.java b/Day 13/ExceptionDemo/src/com/demo/test/TestGuessNumber.java new file mode 100644 index 0000000..5663108 --- /dev/null +++ b/Day 13/ExceptionDemo/src/com/demo/test/TestGuessNumber.java @@ -0,0 +1,34 @@ +package com.demo.test; + +import java.util.Scanner; + +import com.demo.exceptions.WrongNumberException; + +public class TestGuessNumber { + + public static void main(String[] args) { + int num=45; + Scanner sc=new Scanner(System.in); + while(true) { + try { + System.out.println("enter a number"); + int num1=sc.nextInt(); + if(num==num1) { + System.out.println("Yepee, You guess it right"); + break; + }else { + if(num1 lst=List.of(3,2,4,15,26,33,7,4,5); + Predicate p1=e->e>10; + lst.stream().filter(p1).forEach(System.out::println); + + + Supplier s=()->{String[] str={"Hello","Welcome","greet"}; + int x=(int) Math.random()*2+1; // it always generates value<3 + + return str[x]; + }; + System.out.println(s.get()); + System.out.println(s.get()); + + + } + +} diff --git a/Day 13/Java8Features/src/com/demo/test/TestStreamFunctions.java b/Day 13/Java8Features/src/com/demo/test/TestStreamFunctions.java new file mode 100644 index 0000000..eb683e8 --- /dev/null +++ b/Day 13/Java8Features/src/com/demo/test/TestStreamFunctions.java @@ -0,0 +1,70 @@ +package com.demo.test; + +import java.util.List; +import java.util.Optional; +import java.util.stream.Collectors; + +public class TestStreamFunctions { + + public static void main(String[] args) { + List lst=List.of(23,17,45,67,34,11,34); + //find maximum number + Optional maxnum=lst.stream().max(Integer::compare); + System.out.println(maxnum.get()); + + ////find minimum number + Optional minnum=lst.stream().min(Integer::compare); + System.out.println(minnum.get()); + + //find maximum odd number + maxnum=lst.stream().filter(e->e%2!=0).max(Integer::compare); + System.out.println(maxnum.get()); + + //find 1 st number > 5 + Optional op=lst.stream().filter(e->e>5).findFirst(); + if(op.isPresent()) { + System.out.println(op.get()); + } + + + //to find list of squares of all numbers + List lst1=lst.stream().map(e->e*e).collect(Collectors.toList()); + System.out.println(lst1); + + List lstr=List.of("Hello","Welcome","Test","Check"); + + Optional op1=lstr.stream().reduce((acc,s)->acc.length()>s.length()?acc:s); + System.out.println(op1.get()); + + //all match returns true if all elements satisfy the condition + //if it find one value which does not satisfy the condition, + //then it stops and return false + boolean status=lst.stream().allMatch(e->{ + System.out.println("in all match "+e); + return e>15;}); + System.out.println(status); + + //noneMatch returns true if all elements does not satisfy the condition + //if it find one value which satisfy the condition, + //then it stops and return false + status=lst.stream().noneMatch(e->{ + System.out.println("in None match "+e); + return e>15;}); + System.out.println(status); + + //anyMatch returns true if any one elements satisfy the condition + //if it find one value which satisfy the condition, + //then it stops and return true + status=lst.stream().anyMatch(e->{ + System.out.println("in any match "+e); + return e>15;}); + System.out.println(status); + + + + + + + } + +} diff --git a/Day10/Day 9 notes.pdf b/Day10/Day 9 notes.pdf new file mode 100644 index 0000000..a5860de Binary files /dev/null and b/Day10/Day 9 notes.pdf differ diff --git a/Day10/SetCollectionDemo/bin/com/demo/beans/Employee.class b/Day10/SetCollectionDemo/bin/com/demo/beans/Employee.class new file mode 100644 index 0000000..e677787 Binary files /dev/null and b/Day10/SetCollectionDemo/bin/com/demo/beans/Employee.class differ diff --git a/Day10/SetCollectionDemo/bin/com/demo/dao/EmployeeDao.class b/Day10/SetCollectionDemo/bin/com/demo/dao/EmployeeDao.class new file mode 100644 index 0000000..a5addb9 Binary files /dev/null and b/Day10/SetCollectionDemo/bin/com/demo/dao/EmployeeDao.class differ diff --git a/Day10/SetCollectionDemo/bin/com/demo/dao/EmployeeDaoImpl.class b/Day10/SetCollectionDemo/bin/com/demo/dao/EmployeeDaoImpl.class new file mode 100644 index 0000000..8ba8930 Binary files /dev/null and b/Day10/SetCollectionDemo/bin/com/demo/dao/EmployeeDaoImpl.class differ diff --git a/Day10/SetCollectionDemo/bin/com/demo/service/EmployeeService.class b/Day10/SetCollectionDemo/bin/com/demo/service/EmployeeService.class new file mode 100644 index 0000000..cbed8ca Binary files /dev/null and b/Day10/SetCollectionDemo/bin/com/demo/service/EmployeeService.class differ diff --git a/Day10/SetCollectionDemo/bin/com/demo/service/EmployeeServiceImpl.class b/Day10/SetCollectionDemo/bin/com/demo/service/EmployeeServiceImpl.class new file mode 100644 index 0000000..e6a8b2a Binary files /dev/null and b/Day10/SetCollectionDemo/bin/com/demo/service/EmployeeServiceImpl.class differ diff --git a/Day10/SetCollectionDemo/bin/com/demo/test/TestEmployeeSetDetails.class b/Day10/SetCollectionDemo/bin/com/demo/test/TestEmployeeSetDetails.class new file mode 100644 index 0000000..449c1d2 Binary files /dev/null and b/Day10/SetCollectionDemo/bin/com/demo/test/TestEmployeeSetDetails.class differ diff --git a/Day10/SetCollectionDemo/bin/com/demo/test/TestHashSet.class b/Day10/SetCollectionDemo/bin/com/demo/test/TestHashSet.class new file mode 100644 index 0000000..2011d6c Binary files /dev/null and b/Day10/SetCollectionDemo/bin/com/demo/test/TestHashSet.class differ diff --git a/Day10/SetCollectionDemo/bin/com/demo/test/TestTreeSet.class b/Day10/SetCollectionDemo/bin/com/demo/test/TestTreeSet.class new file mode 100644 index 0000000..e2f507b Binary files /dev/null and b/Day10/SetCollectionDemo/bin/com/demo/test/TestTreeSet.class differ diff --git a/Day10/SetCollectionDemo/src/com/demo/beans/Employee.java b/Day10/SetCollectionDemo/src/com/demo/beans/Employee.java new file mode 100644 index 0000000..5ceb620 --- /dev/null +++ b/Day10/SetCollectionDemo/src/com/demo/beans/Employee.java @@ -0,0 +1,75 @@ +package com.demo.beans; + +import java.time.LocalDate; + +public class Employee implements Comparable{ + private int empid; + private String ename; + private double sal; + private LocalDate jdt; + + + +public Employee() { + super(); +} +public Employee(int empid, String ename, double sal, LocalDate jdt) { + super(); + this.empid = empid; + this.ename = ename; + this.sal = sal; + this.jdt = jdt; +} + + +public Employee(int empid) { + super(); + this.empid = empid; +} +@Override +public int hashCode() { + System.out.println("In hashcode method "+empid); + return empid; +} +@Override +public boolean equals(Object obj) { + System.out.println("In Equals method"+this.empid+"----"+((Employee)obj).empid); + return this.empid==((Employee)obj).empid; +} +public int getEmpid() { + return empid; +} +public void setEmpid(int empid) { + this.empid = empid; +} +public String getEname() { + return ename; +} +public void setEname(String ename) { + this.ename = ename; +} +public double getSal() { + return sal; +} +public void setSal(double sal) { + this.sal = sal; +} +public LocalDate getJdt() { + return jdt; +} +public void setJdt(LocalDate jdt) { + this.jdt = jdt; +} +@Override +public String toString() { + return "Employee [empid=" + empid + ", ename=" + ename + ", sal=" + sal + ", jdt=" + jdt + "]"; +} +@Override +public int compareTo(Employee o) { + System.out.println("in compareTo method "+this.empid+"-----"+o.empid); + //return o.empid-this.empid; //descending order + return this.empid-o.empid; //asc ending order +} + + +} diff --git a/Day10/SetCollectionDemo/src/com/demo/dao/EmployeeDao.java b/Day10/SetCollectionDemo/src/com/demo/dao/EmployeeDao.java new file mode 100644 index 0000000..a15c834 --- /dev/null +++ b/Day10/SetCollectionDemo/src/com/demo/dao/EmployeeDao.java @@ -0,0 +1,30 @@ +package com.demo.dao; + +import java.util.List; +import java.util.Set; + +import com.demo.beans.Employee; + +public interface EmployeeDao { + + boolean save(Employee e); + + Set findAll(); + + Employee findById(int id); + + Set findByName(String nm); + + boolean removeBySal(double sal); + + boolean removeById(int id); + + boolean updateBySal(int id, double sal); + + Set sortById(); + + List sortByName(); + + List sortBySal(); + +} diff --git a/Day10/SetCollectionDemo/src/com/demo/dao/EmployeeDaoImpl.java b/Day10/SetCollectionDemo/src/com/demo/dao/EmployeeDaoImpl.java new file mode 100644 index 0000000..cca3527 --- /dev/null +++ b/Day10/SetCollectionDemo/src/com/demo/dao/EmployeeDaoImpl.java @@ -0,0 +1,128 @@ +package com.demo.dao; + +import java.time.LocalDate; +import java.util.ArrayList; +import java.util.Comparator; +import java.util.HashSet; +import java.util.List; +import java.util.Optional; +import java.util.Set; +import java.util.TreeSet; +import java.util.stream.Collectors; + +import com.demo.beans.Employee; + +public class EmployeeDaoImpl implements EmployeeDao{ + static Set eset; + static{eset=new HashSet<>(); + eset.add(new Employee(105,"Amit",57565,LocalDate.of(2023,11,02))); + eset.add(new Employee(106,"Ajay",56565,LocalDate.of(2023,11,02))); + eset.add(new Employee(100,"Arti",56565,LocalDate.of(2024,02,02))); + eset.add(new Employee(101,"Anita",46565,LocalDate.of(2024,02,02))); + eset.add(new Employee(103,"Ajay",56565,LocalDate.of(2023,11,02))); + eset.add(new Employee(104,"Ajay",56565,LocalDate.of(2023,11,02))); + } + @Override + public boolean save(Employee e) { + + return eset.add(e); + } + @Override + public Set findAll() { + + return eset; + } + @Override + public Employee findById(int id) { +// for(Employee e : eset) { +// if(e.getEmpid()==id) { +// return e; +// } +// } + + Optional ob= eset.stream().filter(e->e.getEmpid()==id).findFirst(); + if(ob.isPresent()) { + return ob.get(); + } + return null; + } + @Override + public Set findByName(String nm) { +// Set es = new HashSet<>(); +// for(Employee e : eset) { +// if(e.getEname().equals(nm)) { +// es.add(e); +// } +// } + Set es = eset.stream().filter(e->e.getEname().equals(nm)).collect(Collectors.toSet()); + + if(es.size()>0) { + return es; + } + return null; + } + @Override + public boolean removeBySal(double sal) { + // TODO Auto-generated method stub + return eset.removeIf(e->e.getSal()>sal); + + } + + @Override + public boolean removeById(int id) { + return eset.remove(new Employee(id)); + } + + @Override + public boolean updateBySal(int id, double sal) { + // TODO Auto-generated method stub + Employee e = findById(id); + if(e != null) { + e.setSal(sal); + return true; + } + return false; + } + + @Override + public Set sortById() { + Set tset=new TreeSet<>(); + for(Employee e:eset) { + tset.add(e); + } + return tset; + + } + @Override + public List sortByName() { + Comparator c=(o1,o2)->{ + System.out.println("in name comparator "+o1.getEname()+"-----"+o2.getEname()); + return o1.getEname().compareTo(o2.getEname()); + }; + //duplicate names will not be considered + //Set tset=new TreeSet<>(c); + List elist=new ArrayList<>(); + for(Employee e:eset) { + elist.add(e); + } + elist.sort(c); + return elist; + } + @Override + public List sortBySal() { + Comparator csal=(o1,o2)->{ + System.out.println("in sal comparator "+o1.getSal()+"-----"+o2.getSal()); + return (int)(o1.getSal()-o2.getSal()); + }; + List elist=new ArrayList<>(); + for(Employee e:eset) { + elist.add(e); + } + elist.sort(csal); + return elist; + + } + + + +} diff --git a/Day10/SetCollectionDemo/src/com/demo/service/EmployeeService.java b/Day10/SetCollectionDemo/src/com/demo/service/EmployeeService.java new file mode 100644 index 0000000..0cab8ee --- /dev/null +++ b/Day10/SetCollectionDemo/src/com/demo/service/EmployeeService.java @@ -0,0 +1,30 @@ +package com.demo.service; + +import java.util.List; +import java.util.Set; + +import com.demo.beans.Employee; + +public interface EmployeeService { + + boolean addNewEmployee(); + + Set displayAll(); + + Employee displayById(int id); + + Set displayByName(String nm); + + boolean deleteBySal(double sal); + + boolean deleteById(int id); + + boolean updateBySal(int id, double sal); + + List sortBySal(); + + Set sortById(); + + List sortByName(); + +} diff --git a/Day10/SetCollectionDemo/src/com/demo/service/EmployeeServiceImpl.java b/Day10/SetCollectionDemo/src/com/demo/service/EmployeeServiceImpl.java new file mode 100644 index 0000000..cc7b198 --- /dev/null +++ b/Day10/SetCollectionDemo/src/com/demo/service/EmployeeServiceImpl.java @@ -0,0 +1,89 @@ +package com.demo.service; + +import java.time.LocalDate; +import java.time.format.DateTimeFormatter; +import java.util.List; +import java.util.Scanner; +import java.util.Set; + +import com.demo.beans.Employee; +import com.demo.dao.EmployeeDao; +import com.demo.dao.EmployeeDaoImpl; + + +public class EmployeeServiceImpl implements EmployeeService { + private EmployeeDao edao; + +public EmployeeServiceImpl() { + super(); + this.edao = new EmployeeDaoImpl(); +} + +@Override +public boolean addNewEmployee() { + Scanner sc = new Scanner(System.in); + System.out.println("Enter id"); + int id =sc.nextInt(); + System.out.println("Enter name "); + String nm=sc.next(); + System.out.println("Enter Salary"); + double sal=sc.nextDouble(); + System.out.println("Enter Date (dd/mm/yyyy)"); + String dt=sc.next(); + LocalDate ldt=LocalDate.parse(dt,DateTimeFormatter.ofPattern("dd/MM/yyyy")); + Employee e=new Employee(id,nm,sal,ldt); + + return edao.save(e); +} + +@Override +public Set displayAll() { + + return edao.findAll(); +} + +@Override +public Employee displayById(int id) { + return edao.findById(id); +} + +@Override +public Set displayByName(String nm) { + return edao.findByName(nm); +} + +@Override +public boolean deleteBySal(double sal) { + + return edao.removeBySal(sal); +} + +@Override +public boolean deleteById(int id) { + // TODO Auto-generated method stub + return edao.removeById(id); +} + +@Override +public boolean updateBySal(int id, double sal) { + // TODO Auto-generated method stub + return edao.updateBySal(id,sal); +} + +@Override +public List sortBySal() { + return edao.sortBySal(); +} + +@Override +public Set sortById() { + return edao.sortById(); +} + +@Override +public List sortByName() { + return edao.sortByName(); +} + + +} diff --git a/Day10/SetCollectionDemo/src/com/demo/test/TestEmployeeSetDetails.java b/Day10/SetCollectionDemo/src/com/demo/test/TestEmployeeSetDetails.java new file mode 100644 index 0000000..8f13e37 --- /dev/null +++ b/Day10/SetCollectionDemo/src/com/demo/test/TestEmployeeSetDetails.java @@ -0,0 +1,133 @@ +package com.demo.test; + +import java.util.List; +import java.util.Scanner; +import java.util.Set; + +import com.demo.beans.Employee; +import com.demo.service.EmployeeService; +import com.demo.service.EmployeeServiceImpl; + + + + + + + +public class TestEmployeeSetDetails { + public static void main(String[] args) { + Scanner sc=new Scanner(System.in); + EmployeeService eservice=new EmployeeServiceImpl(); + int choice=0; + do { + System.out.println("1. add new employee\n 2. display all\n3. search by id"); + System.out.println("4. Search by name\n 5. update sal\n6. delete by id\n7. delete by salary\n"); + System.out.println("8. search by salary \n 9. sort by salary\n10. Sort By name\n 11. Sort By id\n12. exit\n choice: "); + choice=sc.nextInt(); + switch(choice) { + case 1->{ + boolean status=eservice.addNewEmployee(); + if(status) { + System.out.println("added succesfully"); + }else{ + System.out.println("duplicate id ,not Added"); + } + } + case 2->{ + Set eset=eservice.displayAll(); + eset.forEach(System.out::println); + + } + case 3->{ + System.out.println("enter id"); + int id=sc.nextInt(); + Employee e=eservice.displayById(id); + if(e!=null) { + System.out.println(e); + }else { + System.out.println("not found"); + } + } + case 4->{ + System.out.println("enter name"); + String nm=sc.next(); + Set eset=eservice.displayByName(nm); + if(eset!=null) { + eset.forEach(System.out::println); + }else { + System.out.println("not found"); + } + } + case 5->{ + System.out.println("enter id"); + int id=sc.nextInt(); + + System.out.println("enter sal"); + double sal =sc.nextDouble(); + + boolean status = eservice.updateBySal(id,sal); + if(status) { + System.out.println("Updated successfully"); + + } + else { + System.out.println("Not found"); + } + + + } + case 6->{ + System.out.println("Enter id to Delete"); + int id = sc.nextInt(); + boolean status =eservice.deleteById(id); + if(status) { + System.out.println("Deleted successfully"); + + } + else { + System.out.println("Not found"); + } + + } + case 7->{ + System.out.println("enter Salary"); + double sal =sc.nextDouble(); + boolean status =eservice.deleteBySal(sal); + if(status) { + System.out.println("Deleted successfully"); + + } + else { + System.out.println("Not found"); + } + + } + case 8->{ + + } + case 9->{ + List elist=eservice.sortBySal(); + elist.forEach(System.out::println); + + } + case 10->{ + List elist=eservice.sortByName(); + elist.forEach(System.out::println); + } + case 11->{ + Set eset=eservice.sortById(); + eset.forEach(System.out::println); + } + case 12->{ + sc.close(); + System.out.println("Thank you for visiting....."); + } + default->{ + System.out.println("wrong choice"); + } + } + }while(choice!=12); + + +} +} diff --git a/Day10/SetCollectionDemo/src/com/demo/test/TestHashSet.java b/Day10/SetCollectionDemo/src/com/demo/test/TestHashSet.java new file mode 100644 index 0000000..e169b32 --- /dev/null +++ b/Day10/SetCollectionDemo/src/com/demo/test/TestHashSet.java @@ -0,0 +1,45 @@ +package com.demo.test; + +import java.util.HashSet; +import java.util.Iterator; +import java.util.Set; + +public class TestHashSet { + + public static void main(String[] args) { + Set hset=new HashSet<>(); + hset.add(20); + hset.add(10); + hset.add(5); + hset.add(1000); + hset.add(200); + System.out.println(hset.add(20)); + hset.add(10); + System.out.println(hset); + hset.remove(5); + System.out.println(hset); + //when foreach loop starts execution, + //then donot change the length of the collection + for(Integer num:hset) { + System.out.println(num); + } + + Iterator it=hset.iterator(); + while(it.hasNext()) { + Integer ob=it.next(); + System.out.println(ob); + + } + + hset.forEach(System.out::println); + + + + + + + + + } + +} diff --git a/Day10/SetCollectionDemo/src/com/demo/test/TestTreeSet.java b/Day10/SetCollectionDemo/src/com/demo/test/TestTreeSet.java new file mode 100644 index 0000000..884d965 --- /dev/null +++ b/Day10/SetCollectionDemo/src/com/demo/test/TestTreeSet.java @@ -0,0 +1,35 @@ +package com.demo.test; + +import java.util.Iterator; +import java.util.Set; +import java.util.TreeSet; + +public class TestTreeSet { + + public static void main(String[] args) { + Set tset=new TreeSet<>(); + tset.add(45); + tset.add(56); + tset.add(20); + System.out.println(tset); + + for(Integer num:tset) { + System.out.println(num); + + } + + Iterator it=tset.iterator(); + while(it.hasNext()) { + Integer num=it.next(); + if(num==56) { + System.out.println("56 deleted successfully"); + it.remove(); + } + System.out.println(num); + } + + tset.forEach(System.out::print); + + } + +} diff --git a/Day10/day 8 notes.pdf b/Day10/day 8 notes.pdf new file mode 100644 index 0000000..27492c0 Binary files /dev/null and b/Day10/day 8 notes.pdf differ diff --git a/Day11/MapCollectionDemo/bin/com/demo/dao/CourseDao.class b/Day11/MapCollectionDemo/bin/com/demo/dao/CourseDao.class new file mode 100644 index 0000000..78b6bf2 Binary files /dev/null and b/Day11/MapCollectionDemo/bin/com/demo/dao/CourseDao.class differ diff --git a/Day11/MapCollectionDemo/bin/com/demo/dao/CourseDaoImpl.class b/Day11/MapCollectionDemo/bin/com/demo/dao/CourseDaoImpl.class new file mode 100644 index 0000000..d0dd359 Binary files /dev/null and b/Day11/MapCollectionDemo/bin/com/demo/dao/CourseDaoImpl.class differ diff --git a/Day11/MapCollectionDemo/bin/com/demo/service/CourseService.class b/Day11/MapCollectionDemo/bin/com/demo/service/CourseService.class new file mode 100644 index 0000000..461d786 Binary files /dev/null and b/Day11/MapCollectionDemo/bin/com/demo/service/CourseService.class differ diff --git a/Day11/MapCollectionDemo/bin/com/demo/service/CourseServiceImpl.class b/Day11/MapCollectionDemo/bin/com/demo/service/CourseServiceImpl.class new file mode 100644 index 0000000..7e09a50 Binary files /dev/null and b/Day11/MapCollectionDemo/bin/com/demo/service/CourseServiceImpl.class differ diff --git a/Day11/MapCollectionDemo/bin/com/demo/test/TestCourseMap.class b/Day11/MapCollectionDemo/bin/com/demo/test/TestCourseMap.class new file mode 100644 index 0000000..e35652c Binary files /dev/null and b/Day11/MapCollectionDemo/bin/com/demo/test/TestCourseMap.class differ diff --git a/Day11/MapCollectionDemo/bin/com/demo/test/TestCourseMgntSystem.class b/Day11/MapCollectionDemo/bin/com/demo/test/TestCourseMgntSystem.class new file mode 100644 index 0000000..488641c Binary files /dev/null and b/Day11/MapCollectionDemo/bin/com/demo/test/TestCourseMgntSystem.class differ diff --git a/Day11/MapCollectionDemo/src/com/demo/dao/CourseDao.java b/Day11/MapCollectionDemo/src/com/demo/dao/CourseDao.java new file mode 100644 index 0000000..9c029e4 --- /dev/null +++ b/Day11/MapCollectionDemo/src/com/demo/dao/CourseDao.java @@ -0,0 +1,30 @@ +package com.demo.dao; + +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; +import java.util.Set; + +public interface CourseDao { + + boolean save(String cname, int capacity); + + Map findAll(); + + int findByName(String cname); + + boolean updateByName(String cname, Integer newcap); + + Set findByCapacity(int capacity); + + boolean updateCourseName(String oname, String nname); + + boolean removeByName(String cname); + + boolean removeByCapacity(int capacity); + + Map sortByName(); + + Set> sorByCapacity(); + +} diff --git a/Day11/MapCollectionDemo/src/com/demo/dao/CourseDaoImpl.java b/Day11/MapCollectionDemo/src/com/demo/dao/CourseDaoImpl.java new file mode 100644 index 0000000..73dac65 --- /dev/null +++ b/Day11/MapCollectionDemo/src/com/demo/dao/CourseDaoImpl.java @@ -0,0 +1,122 @@ +package com.demo.dao; + +import java.util.Comparator; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; +import java.util.Set; +import java.util.TreeMap; +import java.util.TreeSet; + +public class CourseDaoImpl implements CourseDao{ + static Map hm; + static { + hm=new HashMap<>(); + hm.put("DAC", 240); + hm.put("DBDA",65); + hm.put("DTISS",60); + } + @Override + public boolean save(String cname, int capacity) { + if(hm.containsKey(cname)) + return false; + hm.put(cname, capacity); + return true; + } + @Override + public Map findAll() { + return hm; + } + @Override + public int findByName(String cname) { + if(hm.containsKey(cname)) + return hm.get(cname); + else + return -1; + } + @Override + public boolean updateByName(String cname, Integer newcap) { + if(hm.containsKey(cname)) { + hm.put(cname, newcap); + return true; + } + return false; + } + @Override + public Set findByCapacity(int capacity) { + Set keys=hm.keySet(); + Set cnames=new HashSet(); + for(String s:keys) { + //if capacity is greater the add in the set + if(hm.get(s)>capacity) { + cnames.add(s); + } + } + if(cnames.size()>0) { + return cnames; + } + return null; + } + @Override + public boolean updateCourseName(String oname, String nname) { + if(hm.containsKey(oname)) { + int c=hm.remove(oname); + hm.put(nname, c); + return true; + } + return false; + } + @Override + public boolean removeByName(String cname) { + Integer val=hm.remove(cname); + return val!=null; + } + @Override + public boolean removeByCapacity(int capacity) { + int cnt=0; + Set keys=hm.keySet(); + Iterator it=keys.iterator(); + while(it.hasNext()) { + String s=it.next(); + if(hm.get(s)==capacity) { + it.remove(); + cnt++; + } + } + + return cnt>0; + } + @Override + public Map sortByName() { + Map tmap=new TreeMap<>(); + Set keys=hm.keySet(); + for(String s:keys) { + tmap.put(s,hm.get(s)); + } + return tmap; + + } + @Override + public Set> sorByCapacity() { + Set> es=hm.entrySet(); + //comparator to sort on values + Comparator> c=(o1,o2)->{ + return o1.getValue()-o2.getValue(); + }; + Set> tset=new TreeSet<>(c); + //copy data into TreeSet + for(Map.Entry e:es) { + tset.add(e); + } + return tset; + + } + + + + + +} diff --git a/Day11/MapCollectionDemo/src/com/demo/service/CourseService.java b/Day11/MapCollectionDemo/src/com/demo/service/CourseService.java new file mode 100644 index 0000000..1dec3a9 --- /dev/null +++ b/Day11/MapCollectionDemo/src/com/demo/service/CourseService.java @@ -0,0 +1,30 @@ +package com.demo.service; + +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; +import java.util.Set; + +public interface CourseService { + + boolean addNewCourse(); + + Map displayAll(); + + int searchByName(String cname); + + boolean modifyByName(String cname, Integer newcap); + + Set displayByCapacity(int capacity); + + boolean modifyCourseName(String oname, String nname); + + boolean deleteByName(String cname); + + boolean deleteByCapacity(int capacity); + + Map sortByName(); + + Set> sortByCapacity(); + +} diff --git a/Day11/MapCollectionDemo/src/com/demo/service/CourseServiceImpl.java b/Day11/MapCollectionDemo/src/com/demo/service/CourseServiceImpl.java new file mode 100644 index 0000000..0d7ba20 --- /dev/null +++ b/Day11/MapCollectionDemo/src/com/demo/service/CourseServiceImpl.java @@ -0,0 +1,76 @@ +package com.demo.service; + +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; +import java.util.Scanner; +import java.util.Set; + +import com.demo.dao.CourseDao; +import com.demo.dao.CourseDaoImpl; + +public class CourseServiceImpl implements CourseService{ + private CourseDao cdao; + + public CourseServiceImpl() { + super(); + this.cdao = new CourseDaoImpl(); + } + + @Override + public boolean addNewCourse() { + Scanner sc=new Scanner(System.in); + System.out.println("enetr course name"); + String cname=sc.next(); + System.out.println("enter capacity"); + int capacity=sc.nextInt(); + return cdao.save(cname,capacity); + } + + @Override + public Map displayAll() { + return cdao.findAll(); + } + + @Override + public int searchByName(String cname) { + return cdao.findByName(cname); + } + + @Override + public boolean modifyByName(String cname, Integer newcap) { + return cdao.updateByName(cname,newcap); + + } + + @Override + public Set displayByCapacity(int capacity) { + return cdao.findByCapacity(capacity); + } + + @Override + public boolean modifyCourseName(String oname, String nname) { + return cdao.updateCourseName(oname,nname); + } + + @Override + public boolean deleteByName(String cname) { + return cdao.removeByName(cname); + } + + @Override + public boolean deleteByCapacity(int capacity) { + return cdao.removeByCapacity(capacity); + } + + @Override + public Map sortByName() { + return cdao.sortByName(); + } + + @Override + public Set> sortByCapacity() { + return cdao.sorByCapacity(); + } + +} diff --git a/Day11/MapCollectionDemo/src/com/demo/test/TestCourseMap.java b/Day11/MapCollectionDemo/src/com/demo/test/TestCourseMap.java new file mode 100644 index 0000000..85cab9f --- /dev/null +++ b/Day11/MapCollectionDemo/src/com/demo/test/TestCourseMap.java @@ -0,0 +1,31 @@ +package com.demo.test; + +import java.util.HashMap; +import java.util.Hashtable; +import java.util.Map; +import java.util.Set; + +public class TestCourseMap { + + public static void main(String[] args) { + Map hm=new Hashtable<>(); + hm.put("DAC", 240); + hm.put("DBDA", 65); + hm.put("DTISS", 60); + hm.put("DBDA", 70); + hm.put(null,null); + Set kset=hm.keySet(); + kset.forEach(k->System.out.println(k+"---->"+hm.get(k))); + Set> ms=hm.entrySet(); + //{(DAC,240),(DBDA,65),(DTISS,70)} + ms.forEach(e->System.out.println(e.getKey()+"---->"+e.getValue())); + + } + +} + + + + + + diff --git a/Day11/MapCollectionDemo/src/com/demo/test/TestCourseMgntSystem.java b/Day11/MapCollectionDemo/src/com/demo/test/TestCourseMgntSystem.java new file mode 100644 index 0000000..aaf71e3 --- /dev/null +++ b/Day11/MapCollectionDemo/src/com/demo/test/TestCourseMgntSystem.java @@ -0,0 +1,130 @@ +package com.demo.test; + +import java.util.List; +import java.util.Map; +import java.util.Scanner; +import java.util.Set; + +import com.demo.service.CourseService; +import com.demo.service.CourseServiceImpl; + +public class TestCourseMgntSystem { + + public static void main(String[] args) { + Scanner sc=new Scanner(System.in); + CourseService cservice=new CourseServiceImpl(); + int choice=0; + do { + System.out.println("1. Add new Course\n 2. display all\n3. find by course name\n"); + System.out.println("4. modify course capacity\n 5. find by course capacity\n6. modify course name\n"); + System.out.println("7. display in sorted order of key\n 8. display in sorted order of value\n"); + System.out.println("9. delete by course name\n10. delete by capacity\n 11.exit\n choice: "); + choice=sc.nextInt(); + switch(choice) { + case 1->{ + boolean status=cservice.addNewCourse(); + if(status) { + System.out.println("new course added"); + }else{ + System.out.println("duplicate name"); + } + } + case 2->{ + Map cmap=cservice.displayAll(); + Set keys=cmap.keySet(); + keys.forEach(e->System.out.println(e+"---->"+cmap.get(e))); + } + case 3->{ + System.out.println("enter course name"); + String cname=sc.next(); + int capacity=cservice.searchByName(cname); + if(capacity!=-1) { + System.out.println("CourseName : "+cname+"Capacity: "+capacity); + + }else { + System.out.println("Not Found"); + } + } + case 4->{ + System.out.println("enter course name"); + String cname=sc.next(); + System.out.println("enter course new capacity"); + int newcap=sc.nextInt(); + boolean status=cservice.modifyByName(cname,newcap); + if(status) { + System.out.println("modification done"); + + }else { + System.out.println("Not Found"); + } + } + case 5->{ + System.out.println("enter capacity"); + int capacity=sc.nextInt(); + Set cset=cservice.displayByCapacity(capacity); + if(cset!=null) { + cset.forEach(System.out::println); + }else{ + System.out.println("Not found"); + } + + + + } + case 6->{ + System.out.println("enetr old course name"); + String oname=sc.next(); + System.out.println("enetr new course name"); + String nname=sc.next(); + boolean status=cservice.modifyCourseName(oname,nname); + if(status) { + System.out.println("modification done"); + }else { + System.out.println("not found"); + } + + } + case 7->{ + Map cmap=cservice.sortByName(); + Set keys=cmap.keySet(); + keys.forEach(e->System.out.println(e+"--->"+cmap.get(e))); + } + case 8->{ + Set> eset=cservice.sortByCapacity(); + eset.forEach(e->System.out.println(e.getKey()+"--->"+e.getValue())); + } + case 9->{ + System.out.println("Enter course name"); + String cname=sc.next(); + boolean status=cservice.deleteByName(cname); + if(status) { + System.out.println("deleted succesfully"); + }else { + System.out.println("not found"); + } + + } + case 10->{ + System.out.println("Enter capacity"); + int capacity=sc.nextInt(); + boolean status=cservice.deleteByCapacity(capacity); + if(status) { + System.out.println("deleted succesfully"); + }else { + System.out.println("not found"); + } + } + case 11->{ + sc.close(); + System.out.println("Thank you for visiting..."); + } + default->{ + System.out.println("Wrong choice"); + } + } + }while(choice!=11); + + + } + +} diff --git a/Day11/OrderManagementSystem/bin/com/demo/beans/Customer.class b/Day11/OrderManagementSystem/bin/com/demo/beans/Customer.class new file mode 100644 index 0000000..f6e92dd Binary files /dev/null and b/Day11/OrderManagementSystem/bin/com/demo/beans/Customer.class differ diff --git a/Day11/OrderManagementSystem/bin/com/demo/beans/Item.class b/Day11/OrderManagementSystem/bin/com/demo/beans/Item.class new file mode 100644 index 0000000..0bc6aff Binary files /dev/null and b/Day11/OrderManagementSystem/bin/com/demo/beans/Item.class differ diff --git a/Day11/OrderManagementSystem/bin/com/demo/dao/OrderDao.class b/Day11/OrderManagementSystem/bin/com/demo/dao/OrderDao.class new file mode 100644 index 0000000..02b8988 Binary files /dev/null and b/Day11/OrderManagementSystem/bin/com/demo/dao/OrderDao.class differ diff --git a/Day11/OrderManagementSystem/bin/com/demo/dao/OrderDaoImpl.class b/Day11/OrderManagementSystem/bin/com/demo/dao/OrderDaoImpl.class new file mode 100644 index 0000000..8178781 Binary files /dev/null and b/Day11/OrderManagementSystem/bin/com/demo/dao/OrderDaoImpl.class differ diff --git a/Day11/OrderManagementSystem/bin/com/demo/service/OrderService.class b/Day11/OrderManagementSystem/bin/com/demo/service/OrderService.class new file mode 100644 index 0000000..5aee5ba Binary files /dev/null and b/Day11/OrderManagementSystem/bin/com/demo/service/OrderService.class differ diff --git a/Day11/OrderManagementSystem/bin/com/demo/service/OrderServiceImpl.class b/Day11/OrderManagementSystem/bin/com/demo/service/OrderServiceImpl.class new file mode 100644 index 0000000..e4810b7 Binary files /dev/null and b/Day11/OrderManagementSystem/bin/com/demo/service/OrderServiceImpl.class differ diff --git a/Day11/OrderManagementSystem/bin/com/demo/test/TestOrdemgntSystem.class b/Day11/OrderManagementSystem/bin/com/demo/test/TestOrdemgntSystem.class new file mode 100644 index 0000000..2881218 Binary files /dev/null and b/Day11/OrderManagementSystem/bin/com/demo/test/TestOrdemgntSystem.class differ diff --git a/Day11/OrderManagementSystem/src/com/demo/beans/Customer.java b/Day11/OrderManagementSystem/src/com/demo/beans/Customer.java new file mode 100644 index 0000000..3ee05e6 --- /dev/null +++ b/Day11/OrderManagementSystem/src/com/demo/beans/Customer.java @@ -0,0 +1,51 @@ +package com.demo.beans; + +public class Customer { + private int cid; + private String cname; + private String mob; + public Customer() { + super(); + } + public Customer(int cid, String cname, String mob) { + super(); + this.cid = cid; + this.cname = cname; + this.mob = mob; + } + + @Override + public int hashCode() { + System.out.println("in hashcode "+cid); + return cid; ///+cname.hashCode(); + } + @Override + public boolean equals(Object obj) { + System.out.println("in equals method "+this.cid+"-----"+((Customer)obj).cid); + return this.cid==((Customer)obj).cid; + } + public int getCid() { + return cid; + } + public void setCid(int cid) { + this.cid = cid; + } + public String getCname() { + return cname; + } + public void setCname(String cname) { + this.cname = cname; + } + public String getMob() { + return mob; + } + public void setMob(String mob) { + this.mob = mob; + } + @Override + public String toString() { + return "Customer [cid=" + cid + ", cname=" + cname + ", mob=" + mob + "]"; + } + + +} diff --git a/Day11/OrderManagementSystem/src/com/demo/beans/Item.java b/Day11/OrderManagementSystem/src/com/demo/beans/Item.java new file mode 100644 index 0000000..6f09d41 --- /dev/null +++ b/Day11/OrderManagementSystem/src/com/demo/beans/Item.java @@ -0,0 +1,47 @@ +package com.demo.beans; + +public class Item { + private int iid; + private String iname; + private int qty; + private double price; +public Item() { + super(); +} +public Item(int iid, String iname, int qty, double price) { + super(); + this.iid = iid; + this.iname = iname; + this.qty = qty; + this.price = price; +} +public int getIid() { + return iid; +} +public void setIid(int iid) { + this.iid = iid; +} +public String getIname() { + return iname; +} +public void setIname(String iname) { + this.iname = iname; +} +public int getQty() { + return qty; +} +public void setQty(int qty) { + this.qty = qty; +} +public double getPrice() { + return price; +} +public void setPrice(double price) { + this.price = price; +} +@Override +public String toString() { + return "Item [iid=" + iid + ", iname=" + iname + ", qty=" + qty + ", price=" + price + "]"; +} + +} diff --git a/Day11/OrderManagementSystem/src/com/demo/dao/OrderDao.java b/Day11/OrderManagementSystem/src/com/demo/dao/OrderDao.java new file mode 100644 index 0000000..3784992 --- /dev/null +++ b/Day11/OrderManagementSystem/src/com/demo/dao/OrderDao.java @@ -0,0 +1,15 @@ +package com.demo.dao; + +import java.util.List; +import java.util.Map; + +import com.demo.beans.Customer; +import com.demo.beans.Item; + +public interface OrderDao { + + boolean save(Customer c, List lst); + + Map> findAll(); + +} diff --git a/Day11/OrderManagementSystem/src/com/demo/dao/OrderDaoImpl.java b/Day11/OrderManagementSystem/src/com/demo/dao/OrderDaoImpl.java new file mode 100644 index 0000000..e6903da --- /dev/null +++ b/Day11/OrderManagementSystem/src/com/demo/dao/OrderDaoImpl.java @@ -0,0 +1,38 @@ +package com.demo.dao; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import com.demo.beans.Customer; +import com.demo.beans.Item; + +public class OrderDaoImpl implements OrderDao{ + static Map> hm; + static { + hm=new HashMap<>(); + Customer c1=new Customer(10,"Sushrut","33333"); + List lst=new ArrayList<>(); + lst.add(new Item(1001,"Chair",34,5678)); + lst.add(new Item(1002,"Table",30,7678)); + hm.put(c1, lst); + Customer c2=new Customer(11,"Pranav","4444"); + List lst1=new ArrayList<>(); + lst1.add(new Item(1001,"Shelf",40,2678)); + lst1.add(new Item(1002,"drawer",20,5678)); + hm.put(c2, lst1); + } +@Override +public boolean save(Customer c, List lst) { + if(!hm.containsKey(c)) { + hm.put(c,lst); + return true; + } + return false; +} +@Override +public Map> findAll() { + return hm; +} +} diff --git a/Day11/OrderManagementSystem/src/com/demo/service/OrderService.java b/Day11/OrderManagementSystem/src/com/demo/service/OrderService.java new file mode 100644 index 0000000..206f605 --- /dev/null +++ b/Day11/OrderManagementSystem/src/com/demo/service/OrderService.java @@ -0,0 +1,15 @@ +package com.demo.service; + +import java.util.List; +import java.util.Map; + +import com.demo.beans.Customer; +import com.demo.beans.Item; + +public interface OrderService { + + boolean addNewCustomer(); + + Map> displayAll(); + +} diff --git a/Day11/OrderManagementSystem/src/com/demo/service/OrderServiceImpl.java b/Day11/OrderManagementSystem/src/com/demo/service/OrderServiceImpl.java new file mode 100644 index 0000000..d752586 --- /dev/null +++ b/Day11/OrderManagementSystem/src/com/demo/service/OrderServiceImpl.java @@ -0,0 +1,59 @@ +package com.demo.service; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.Scanner; + +import com.demo.beans.Customer; +import com.demo.beans.Item; +import com.demo.dao.OrderDao; +import com.demo.dao.OrderDaoImpl; + +public class OrderServiceImpl implements OrderService{ + private OrderDao odao; + + public OrderServiceImpl() { + super(); + odao=new OrderDaoImpl(); + } + + @Override + public boolean addNewCustomer() { + Scanner sc=new Scanner(System.in); + //accept customer details + System.out.println("Enter id"); + int cid=sc.nextInt(); + System.out.println("Enter name"); + String nm=sc.next(); + System.out.println("Enter mobile"); + String mob=sc.next(); + Customer c=new Customer(cid,nm,mob); + //accept list of items + List lst=new ArrayList<>(); + String ans=null; + do { + System.out.println("enter item id"); + int id=sc.nextInt(); + System.out.println("enter item name"); + String inm=sc.next(); + System.out.println("enter item qty"); + int qty=sc.nextInt(); + System.out.println("enter item price"); + double price=sc.nextDouble(); + Item item=new Item(id,inm,qty,price); + lst.add(item); + System.out.println("Do you want to continue(y/n)?"); + ans=sc.next(); + }while(ans.equals("y")); + return odao.save(c,lst); + + + } + + @Override + public Map> displayAll() { + return odao.findAll(); + } + +} diff --git a/Day11/OrderManagementSystem/src/com/demo/test/TestOrdemgntSystem.java b/Day11/OrderManagementSystem/src/com/demo/test/TestOrdemgntSystem.java new file mode 100644 index 0000000..76a5b35 --- /dev/null +++ b/Day11/OrderManagementSystem/src/com/demo/test/TestOrdemgntSystem.java @@ -0,0 +1,61 @@ +package com.demo.test; + +import java.util.List; +import java.util.Map; +import java.util.Scanner; +import java.util.Set; + +import com.demo.beans.Customer; +import com.demo.beans.Item; +import com.demo.service.OrderService; +import com.demo.service.OrderServiceImpl; + +public class TestOrdemgntSystem { + + public static void main(String[] args) { + Scanner sc=new Scanner(System.in); + OrderService oservice=new OrderServiceImpl(); + int choice=0; + do { + System.out.println("1. add new customer\n2. display all\n3. display by customer"); + System.out.println("4. delete customer\n5. add a new item in existing order"); + System.out.println("6. delete item from existing order\n7.exit\n choice:"); + choice=sc.nextInt(); + switch(choice) { + case 1->{ + boolean status=oservice.addNewCustomer(); + if(status) { + System.out.println("Added successfully"); + + }else { + System.out.println("Not added"); + } + } + case 2->{ + Map> omap=oservice.displayAll(); + Set keys=omap.keySet(); + keys.forEach(c->System.out.println(c+"---->"+omap.get(c))); + + } + case 3->{} + case 4->{} + case 5->{} + case 6->{} + case 7->{ + sc.close(); + System.out.println("Thank you for visiting....."); + } + default->{ + System.out.println("Wrong choice"); + } + + + + + + + } + }while(choice!=7); + } + +} diff --git a/Day11/SetCollectionDemo/bin/com/demo/beans/Employee.class b/Day11/SetCollectionDemo/bin/com/demo/beans/Employee.class new file mode 100644 index 0000000..e677787 Binary files /dev/null and b/Day11/SetCollectionDemo/bin/com/demo/beans/Employee.class differ diff --git a/Day11/SetCollectionDemo/bin/com/demo/dao/EmployeeDao.class b/Day11/SetCollectionDemo/bin/com/demo/dao/EmployeeDao.class new file mode 100644 index 0000000..a5addb9 Binary files /dev/null and b/Day11/SetCollectionDemo/bin/com/demo/dao/EmployeeDao.class differ diff --git a/Day11/SetCollectionDemo/bin/com/demo/dao/EmployeeDaoImpl.class b/Day11/SetCollectionDemo/bin/com/demo/dao/EmployeeDaoImpl.class new file mode 100644 index 0000000..8ba8930 Binary files /dev/null and b/Day11/SetCollectionDemo/bin/com/demo/dao/EmployeeDaoImpl.class differ diff --git a/Day11/SetCollectionDemo/bin/com/demo/service/EmployeeService.class b/Day11/SetCollectionDemo/bin/com/demo/service/EmployeeService.class new file mode 100644 index 0000000..cbed8ca Binary files /dev/null and b/Day11/SetCollectionDemo/bin/com/demo/service/EmployeeService.class differ diff --git a/Day11/SetCollectionDemo/bin/com/demo/service/EmployeeServiceImpl.class b/Day11/SetCollectionDemo/bin/com/demo/service/EmployeeServiceImpl.class new file mode 100644 index 0000000..e6a8b2a Binary files /dev/null and b/Day11/SetCollectionDemo/bin/com/demo/service/EmployeeServiceImpl.class differ diff --git a/Day11/SetCollectionDemo/bin/com/demo/test/TestEmployeeSetDetails.class b/Day11/SetCollectionDemo/bin/com/demo/test/TestEmployeeSetDetails.class new file mode 100644 index 0000000..80d224e Binary files /dev/null and b/Day11/SetCollectionDemo/bin/com/demo/test/TestEmployeeSetDetails.class differ diff --git a/Day11/SetCollectionDemo/bin/com/demo/test/TestHashSet.class b/Day11/SetCollectionDemo/bin/com/demo/test/TestHashSet.class new file mode 100644 index 0000000..2011d6c Binary files /dev/null and b/Day11/SetCollectionDemo/bin/com/demo/test/TestHashSet.class differ diff --git a/Day11/SetCollectionDemo/bin/com/demo/test/TestPriorityQueue.class b/Day11/SetCollectionDemo/bin/com/demo/test/TestPriorityQueue.class new file mode 100644 index 0000000..ab7c6ee Binary files /dev/null and b/Day11/SetCollectionDemo/bin/com/demo/test/TestPriorityQueue.class differ diff --git a/Day11/SetCollectionDemo/bin/com/demo/test/TestTreeSet.class b/Day11/SetCollectionDemo/bin/com/demo/test/TestTreeSet.class new file mode 100644 index 0000000..e2f507b Binary files /dev/null and b/Day11/SetCollectionDemo/bin/com/demo/test/TestTreeSet.class differ diff --git a/Day11/SetCollectionDemo/bin/com/demo/test/TestTreeSet1.class b/Day11/SetCollectionDemo/bin/com/demo/test/TestTreeSet1.class new file mode 100644 index 0000000..46bdfe6 Binary files /dev/null and b/Day11/SetCollectionDemo/bin/com/demo/test/TestTreeSet1.class differ diff --git a/Day11/SetCollectionDemo/src/com/demo/beans/Employee.java b/Day11/SetCollectionDemo/src/com/demo/beans/Employee.java new file mode 100644 index 0000000..5ceb620 --- /dev/null +++ b/Day11/SetCollectionDemo/src/com/demo/beans/Employee.java @@ -0,0 +1,75 @@ +package com.demo.beans; + +import java.time.LocalDate; + +public class Employee implements Comparable{ + private int empid; + private String ename; + private double sal; + private LocalDate jdt; + + + +public Employee() { + super(); +} +public Employee(int empid, String ename, double sal, LocalDate jdt) { + super(); + this.empid = empid; + this.ename = ename; + this.sal = sal; + this.jdt = jdt; +} + + +public Employee(int empid) { + super(); + this.empid = empid; +} +@Override +public int hashCode() { + System.out.println("In hashcode method "+empid); + return empid; +} +@Override +public boolean equals(Object obj) { + System.out.println("In Equals method"+this.empid+"----"+((Employee)obj).empid); + return this.empid==((Employee)obj).empid; +} +public int getEmpid() { + return empid; +} +public void setEmpid(int empid) { + this.empid = empid; +} +public String getEname() { + return ename; +} +public void setEname(String ename) { + this.ename = ename; +} +public double getSal() { + return sal; +} +public void setSal(double sal) { + this.sal = sal; +} +public LocalDate getJdt() { + return jdt; +} +public void setJdt(LocalDate jdt) { + this.jdt = jdt; +} +@Override +public String toString() { + return "Employee [empid=" + empid + ", ename=" + ename + ", sal=" + sal + ", jdt=" + jdt + "]"; +} +@Override +public int compareTo(Employee o) { + System.out.println("in compareTo method "+this.empid+"-----"+o.empid); + //return o.empid-this.empid; //descending order + return this.empid-o.empid; //asc ending order +} + + +} diff --git a/Day11/SetCollectionDemo/src/com/demo/dao/EmployeeDao.java b/Day11/SetCollectionDemo/src/com/demo/dao/EmployeeDao.java new file mode 100644 index 0000000..a15c834 --- /dev/null +++ b/Day11/SetCollectionDemo/src/com/demo/dao/EmployeeDao.java @@ -0,0 +1,30 @@ +package com.demo.dao; + +import java.util.List; +import java.util.Set; + +import com.demo.beans.Employee; + +public interface EmployeeDao { + + boolean save(Employee e); + + Set findAll(); + + Employee findById(int id); + + Set findByName(String nm); + + boolean removeBySal(double sal); + + boolean removeById(int id); + + boolean updateBySal(int id, double sal); + + Set sortById(); + + List sortByName(); + + List sortBySal(); + +} diff --git a/Day11/SetCollectionDemo/src/com/demo/dao/EmployeeDaoImpl.java b/Day11/SetCollectionDemo/src/com/demo/dao/EmployeeDaoImpl.java new file mode 100644 index 0000000..cca3527 --- /dev/null +++ b/Day11/SetCollectionDemo/src/com/demo/dao/EmployeeDaoImpl.java @@ -0,0 +1,128 @@ +package com.demo.dao; + +import java.time.LocalDate; +import java.util.ArrayList; +import java.util.Comparator; +import java.util.HashSet; +import java.util.List; +import java.util.Optional; +import java.util.Set; +import java.util.TreeSet; +import java.util.stream.Collectors; + +import com.demo.beans.Employee; + +public class EmployeeDaoImpl implements EmployeeDao{ + static Set eset; + static{eset=new HashSet<>(); + eset.add(new Employee(105,"Amit",57565,LocalDate.of(2023,11,02))); + eset.add(new Employee(106,"Ajay",56565,LocalDate.of(2023,11,02))); + eset.add(new Employee(100,"Arti",56565,LocalDate.of(2024,02,02))); + eset.add(new Employee(101,"Anita",46565,LocalDate.of(2024,02,02))); + eset.add(new Employee(103,"Ajay",56565,LocalDate.of(2023,11,02))); + eset.add(new Employee(104,"Ajay",56565,LocalDate.of(2023,11,02))); + } + @Override + public boolean save(Employee e) { + + return eset.add(e); + } + @Override + public Set findAll() { + + return eset; + } + @Override + public Employee findById(int id) { +// for(Employee e : eset) { +// if(e.getEmpid()==id) { +// return e; +// } +// } + + Optional ob= eset.stream().filter(e->e.getEmpid()==id).findFirst(); + if(ob.isPresent()) { + return ob.get(); + } + return null; + } + @Override + public Set findByName(String nm) { +// Set es = new HashSet<>(); +// for(Employee e : eset) { +// if(e.getEname().equals(nm)) { +// es.add(e); +// } +// } + Set es = eset.stream().filter(e->e.getEname().equals(nm)).collect(Collectors.toSet()); + + if(es.size()>0) { + return es; + } + return null; + } + @Override + public boolean removeBySal(double sal) { + // TODO Auto-generated method stub + return eset.removeIf(e->e.getSal()>sal); + + } + + @Override + public boolean removeById(int id) { + return eset.remove(new Employee(id)); + } + + @Override + public boolean updateBySal(int id, double sal) { + // TODO Auto-generated method stub + Employee e = findById(id); + if(e != null) { + e.setSal(sal); + return true; + } + return false; + } + + @Override + public Set sortById() { + Set tset=new TreeSet<>(); + for(Employee e:eset) { + tset.add(e); + } + return tset; + + } + @Override + public List sortByName() { + Comparator c=(o1,o2)->{ + System.out.println("in name comparator "+o1.getEname()+"-----"+o2.getEname()); + return o1.getEname().compareTo(o2.getEname()); + }; + //duplicate names will not be considered + //Set tset=new TreeSet<>(c); + List elist=new ArrayList<>(); + for(Employee e:eset) { + elist.add(e); + } + elist.sort(c); + return elist; + } + @Override + public List sortBySal() { + Comparator csal=(o1,o2)->{ + System.out.println("in sal comparator "+o1.getSal()+"-----"+o2.getSal()); + return (int)(o1.getSal()-o2.getSal()); + }; + List elist=new ArrayList<>(); + for(Employee e:eset) { + elist.add(e); + } + elist.sort(csal); + return elist; + + } + + + +} diff --git a/Day11/SetCollectionDemo/src/com/demo/service/EmployeeService.java b/Day11/SetCollectionDemo/src/com/demo/service/EmployeeService.java new file mode 100644 index 0000000..0cab8ee --- /dev/null +++ b/Day11/SetCollectionDemo/src/com/demo/service/EmployeeService.java @@ -0,0 +1,30 @@ +package com.demo.service; + +import java.util.List; +import java.util.Set; + +import com.demo.beans.Employee; + +public interface EmployeeService { + + boolean addNewEmployee(); + + Set displayAll(); + + Employee displayById(int id); + + Set displayByName(String nm); + + boolean deleteBySal(double sal); + + boolean deleteById(int id); + + boolean updateBySal(int id, double sal); + + List sortBySal(); + + Set sortById(); + + List sortByName(); + +} diff --git a/Day11/SetCollectionDemo/src/com/demo/service/EmployeeServiceImpl.java b/Day11/SetCollectionDemo/src/com/demo/service/EmployeeServiceImpl.java new file mode 100644 index 0000000..cc7b198 --- /dev/null +++ b/Day11/SetCollectionDemo/src/com/demo/service/EmployeeServiceImpl.java @@ -0,0 +1,89 @@ +package com.demo.service; + +import java.time.LocalDate; +import java.time.format.DateTimeFormatter; +import java.util.List; +import java.util.Scanner; +import java.util.Set; + +import com.demo.beans.Employee; +import com.demo.dao.EmployeeDao; +import com.demo.dao.EmployeeDaoImpl; + + +public class EmployeeServiceImpl implements EmployeeService { + private EmployeeDao edao; + +public EmployeeServiceImpl() { + super(); + this.edao = new EmployeeDaoImpl(); +} + +@Override +public boolean addNewEmployee() { + Scanner sc = new Scanner(System.in); + System.out.println("Enter id"); + int id =sc.nextInt(); + System.out.println("Enter name "); + String nm=sc.next(); + System.out.println("Enter Salary"); + double sal=sc.nextDouble(); + System.out.println("Enter Date (dd/mm/yyyy)"); + String dt=sc.next(); + LocalDate ldt=LocalDate.parse(dt,DateTimeFormatter.ofPattern("dd/MM/yyyy")); + Employee e=new Employee(id,nm,sal,ldt); + + return edao.save(e); +} + +@Override +public Set displayAll() { + + return edao.findAll(); +} + +@Override +public Employee displayById(int id) { + return edao.findById(id); +} + +@Override +public Set displayByName(String nm) { + return edao.findByName(nm); +} + +@Override +public boolean deleteBySal(double sal) { + + return edao.removeBySal(sal); +} + +@Override +public boolean deleteById(int id) { + // TODO Auto-generated method stub + return edao.removeById(id); +} + +@Override +public boolean updateBySal(int id, double sal) { + // TODO Auto-generated method stub + return edao.updateBySal(id,sal); +} + +@Override +public List sortBySal() { + return edao.sortBySal(); +} + +@Override +public Set sortById() { + return edao.sortById(); +} + +@Override +public List sortByName() { + return edao.sortByName(); +} + + +} diff --git a/Day11/SetCollectionDemo/src/com/demo/test/TestEmployeeSetDetails.java b/Day11/SetCollectionDemo/src/com/demo/test/TestEmployeeSetDetails.java new file mode 100644 index 0000000..dd7644d --- /dev/null +++ b/Day11/SetCollectionDemo/src/com/demo/test/TestEmployeeSetDetails.java @@ -0,0 +1,134 @@ +package com.demo.test; + +import java.util.List; +import java.util.Scanner; +import java.util.Set; + +import com.demo.beans.Employee; +import com.demo.service.EmployeeService; +import com.demo.service.EmployeeServiceImpl; + + + + + + + +public class TestEmployeeSetDetails { + public static void main(String[] args) { + Scanner sc=new Scanner(System.in); + EmployeeService eservice=new EmployeeServiceImpl(); + int choice=0; + do { + System.out.println("1. add new employee\n 2. display all\n3. search by id"); + System.out.println("4. Search by name\n 5. update sal\n6. delete by id\n7. delete by salary\n"); + System.out.println("8. search by salary \n 9. sort by salary\n10. Sort By name\n 11. Sort By id\n12. exit\n choice: "); + choice=sc.nextInt(); + switch(choice) { + case 1->{ + boolean status=eservice.addNewEmployee(); + if(status) { + System.out.println("added succesfully"); + }else{ + System.out.println("duplicate id ,not Added"); + } + } + case 2->{ + Set eset=eservice.displayAll(); + eset.forEach(System.out::println); + + } + case 3->{ + System.out.println("enter id"); + int id=sc.nextInt(); + Employee e=eservice.displayById(id); + if(e!=null) { + System.out.println(e); + }else { + System.out.println("not found"); + } + } + case 4->{ + System.out.println("enter name"); + String nm=sc.next(); + Set eset=eservice.displayByName(nm); + if(eset!=null) { + eset.forEach(System.out::println); + }else { + System.out.println("not found"); + } + } + case 5->{ + System.out.println("enter id"); + int id=sc.nextInt(); + + System.out.println("enter sal"); + double sal =sc.nextDouble(); + + boolean status = eservice.updateBySal(id,sal); + if(status) { + System.out.println("Updated successfully"); + + } + else { + System.out.println("Not found"); + } + + + } + case 6->{ + System.out.println("Enter id to Delete"); + int id = sc.nextInt(); + boolean status =eservice.deleteById(id); + if(status) { + System.out.println("Deleted successfully"); + + } + else { + System.out.println("Not found"); + } + + } + case 7->{ + System.out.println("enter Salary"); + double sal =sc.nextDouble(); + boolean status =eservice.deleteBySal(sal); + if(status) { + System.out.println("Deleted successfully"); + + } + else { + System.out.println("Not found"); + } + + } + case 8->{ + + } + case 9->{ + List elist=eservice.sortBySal(); + elist.forEach(System.out::println); + + } + case 10->{ + List elist=eservice.sortByName(); + //elist.forEach(e->System.out.println(e)); + elist.forEach(System.out::println); + } + case 11->{ + Set eset=eservice.sortById(); + eset.forEach(System.out::println); + } + case 12->{ + sc.close(); + System.out.println("Thank you for visiting....."); + } + default->{ + System.out.println("wrong choice"); + } + } + }while(choice!=12); + + +} +} diff --git a/Day11/SetCollectionDemo/src/com/demo/test/TestHashSet.java b/Day11/SetCollectionDemo/src/com/demo/test/TestHashSet.java new file mode 100644 index 0000000..e169b32 --- /dev/null +++ b/Day11/SetCollectionDemo/src/com/demo/test/TestHashSet.java @@ -0,0 +1,45 @@ +package com.demo.test; + +import java.util.HashSet; +import java.util.Iterator; +import java.util.Set; + +public class TestHashSet { + + public static void main(String[] args) { + Set hset=new HashSet<>(); + hset.add(20); + hset.add(10); + hset.add(5); + hset.add(1000); + hset.add(200); + System.out.println(hset.add(20)); + hset.add(10); + System.out.println(hset); + hset.remove(5); + System.out.println(hset); + //when foreach loop starts execution, + //then donot change the length of the collection + for(Integer num:hset) { + System.out.println(num); + } + + Iterator it=hset.iterator(); + while(it.hasNext()) { + Integer ob=it.next(); + System.out.println(ob); + + } + + hset.forEach(System.out::println); + + + + + + + + + } + +} diff --git a/Day11/SetCollectionDemo/src/com/demo/test/TestPriorityQueue.java b/Day11/SetCollectionDemo/src/com/demo/test/TestPriorityQueue.java new file mode 100644 index 0000000..09be0f0 --- /dev/null +++ b/Day11/SetCollectionDemo/src/com/demo/test/TestPriorityQueue.java @@ -0,0 +1,24 @@ +package com.demo.test; + +import java.util.PriorityQueue; +import java.util.Queue; + +public class TestPriorityQueue { + + public static void main(String[] args) { + Queue que=new PriorityQueue<>(); + que.add(45); + que.add(34); + que.add(50); + que.add(34); + System.out.println(que); + //peek reads but does not remove + System.out.println(que.peek()); + while(!que.isEmpty()){ + //peek reads and remove + System.out.println(que.poll()); + } + + } + +} diff --git a/Day11/SetCollectionDemo/src/com/demo/test/TestTreeSet.java b/Day11/SetCollectionDemo/src/com/demo/test/TestTreeSet.java new file mode 100644 index 0000000..884d965 --- /dev/null +++ b/Day11/SetCollectionDemo/src/com/demo/test/TestTreeSet.java @@ -0,0 +1,35 @@ +package com.demo.test; + +import java.util.Iterator; +import java.util.Set; +import java.util.TreeSet; + +public class TestTreeSet { + + public static void main(String[] args) { + Set tset=new TreeSet<>(); + tset.add(45); + tset.add(56); + tset.add(20); + System.out.println(tset); + + for(Integer num:tset) { + System.out.println(num); + + } + + Iterator it=tset.iterator(); + while(it.hasNext()) { + Integer num=it.next(); + if(num==56) { + System.out.println("56 deleted successfully"); + it.remove(); + } + System.out.println(num); + } + + tset.forEach(System.out::print); + + } + +} diff --git a/Day11/SetCollectionDemo/src/com/demo/test/TestTreeSet1.java b/Day11/SetCollectionDemo/src/com/demo/test/TestTreeSet1.java new file mode 100644 index 0000000..c03b8e8 --- /dev/null +++ b/Day11/SetCollectionDemo/src/com/demo/test/TestTreeSet1.java @@ -0,0 +1,30 @@ +package com.demo.test; + +import java.time.LocalDate; +import java.util.Comparator; +import java.util.Set; +import java.util.TreeSet; + +import com.demo.beans.Employee; + +public class TestTreeSet1 { + + public static void main(String[] args) { + //to add data in sorted order of name in TreeSet + //if name is same then compare it on empid + Comparator c=(o1,o2)->{ + System.out.println("in name comparator "+ o1.getEname()+"---"+o2.getEname()); + if(o1.getEname().compareTo(o2.getEname())==0) { + return o1.getEmpid()-o2.getEmpid(); + } + return o1.getEname().compareTo(o2.getEname()); + }; + Set tset=new TreeSet<>(c); + tset.add(new Employee(107,"Rajan",45678,LocalDate.of(2020,11, 11))); + tset.add(new Employee(101,"Revati",55678,LocalDate.of(2020,11, 11))); + tset.add(new Employee(102,"Rajan",42678,LocalDate.of(2020,11, 11))); + tset.add(new Employee(100,"Rajan",45678,LocalDate.of(2020,11, 11))); + tset.forEach(System.out::println); + } + +} diff --git a/Day6/Day6/Has-A/bin/Player.class b/Day6/Day6/Has-A/bin/Player.class new file mode 100644 index 0000000..2aa4cdc Binary files /dev/null and b/Day6/Day6/Has-A/bin/Player.class differ diff --git a/Day6/Day6/Has-A/bin/Team.class b/Day6/Day6/Has-A/bin/Team.class new file mode 100644 index 0000000..574af2e Binary files /dev/null and b/Day6/Day6/Has-A/bin/Team.class differ diff --git a/Day6/Day6/Has-A/bin/TeamService.class b/Day6/Day6/Has-A/bin/TeamService.class new file mode 100644 index 0000000..4331018 Binary files /dev/null and b/Day6/Day6/Has-A/bin/TeamService.class differ diff --git a/Day6/Day6/Has-A/bin/TestTeam.class b/Day6/Day6/Has-A/bin/TestTeam.class new file mode 100644 index 0000000..5e649c2 Binary files /dev/null and b/Day6/Day6/Has-A/bin/TestTeam.class differ diff --git a/Day6/Day6/Has-A/bin/TestTeamArray.class b/Day6/Day6/Has-A/bin/TestTeamArray.class new file mode 100644 index 0000000..292c7c1 Binary files /dev/null and b/Day6/Day6/Has-A/bin/TestTeamArray.class differ diff --git a/Day6/Day6/Has-A/src/Player.java b/Day6/Day6/Has-A/src/Player.java new file mode 100644 index 0000000..3c30e86 --- /dev/null +++ b/Day6/Day6/Has-A/src/Player.java @@ -0,0 +1,38 @@ +public class Player { + private int pid; + private String pname; + private String speciality; + public Player() { + super(); + } + public Player(int pid, String pname, String speciality) { + super(); + this.pid = pid; + this.pname = pname; + this.speciality = speciality; + } + public int getPid() { + return pid; + } + public void setPid(int pid) { + this.pid = pid; + } + public String getPname() { + return pname; + } + public void setPname(String pname) { + this.pname = pname; + } + public String getSpeciality() { + return speciality; + } + public void setSpeciality(String speciality) { + this.speciality = speciality; + } + @Override + public String toString() { + return "Player [pid=" + pid + ", pname=" + pname + ", speciality=" + speciality + "]"; + } + + +} diff --git a/Day6/Day6/Has-A/src/Team.java b/Day6/Day6/Has-A/src/Team.java new file mode 100644 index 0000000..dca2fc9 --- /dev/null +++ b/Day6/Day6/Has-A/src/Team.java @@ -0,0 +1,61 @@ +import java.util.Arrays; + +public class Team { + private int tid; + private String tname; + private Player captain; + private Player[] plist; + private int size; + public Team() { + super(); + } + + public Team(int tid, String tname, Player captain, Player[] plist, int size) { + super(); + this.tid = tid; + this.tname = tname; + this.captain = captain; + this.plist = plist; + this.size = size; + } + + public int getTid() { + return tid; + } + public void setTid(int tid) { + this.tid = tid; + } + public String getTname() { + return tname; + } + public void setTname(String tname) { + this.tname = tname; + } + public Player getCaptain() { + return captain; + } + public void setCaptain(Player captain) { + this.captain = captain; + } + public Player[] getPlist() { + return plist; + } + public void setPlist(Player[] plist) { + this.plist = plist; + } + + public int getSize() { + return size; + } + + public void setSize(int size) { + this.size = size; + } + + @Override + public String toString() { + return "Team [tid=" + tid + ", tname=" + tname + ", captain=" + captain + ", plist=" + Arrays.toString(plist) + + "]"; + } + +} diff --git a/Day6/Day6/Has-A/src/TeamService.java b/Day6/Day6/Has-A/src/TeamService.java new file mode 100644 index 0000000..98a9a51 --- /dev/null +++ b/Day6/Day6/Has-A/src/TeamService.java @@ -0,0 +1,125 @@ +import java.util.Scanner; + +public class TeamService { + static Team[] tarr; + static int cnt; + static { + tarr=new Team[20]; + Player[] plst= new Player[15]; + plst[0]=new Player(11,"Virat Kohali","Batsman"); + plst[1]=new Player(12,"Rohit Sharma","Batsman"); + plst[2]=new Player(13,"Hardik Pandya","Allrounder"); + Player c=new Player(11,"Rohit Sharma","Batsman"); + tarr[0]=new Team(101,"MI",c,plst,3); + + Player[] plst1= new Player[15]; + plst1[0]=new Player(16,"Dravid","Batsman"); + plst1[1]=new Player(17,"Saurabh","Batsman"); + plst1[2]=new Player(18,"Sachin","Allrounder"); + Player c1=new Player(11,"Sachin","Allrounder"); + tarr[1]=new Team(100,"RCB",c1,plst1,3); + + cnt=2; + + } + public static boolean addNewTeam() { + Scanner sc=new Scanner(System.in); + if(cnt!=20) { + //team details + System.out.println("enter tid"); + int tid=sc.nextInt(); + System.out.println("enter team name"); + String tnm=sc.next(); + + //captain + System.out.println("enter captain player id"); + int pid=sc.nextInt(); + System.out.println("enter captain player name"); + String pnm=sc.next(); + System.out.println("enter captain player speciality"); + String sp=sc.next(); + Player c=new Player(pid,pnm,sp); + //loop for creating player list + Player[] plst=new Player[15]; + plst[0]=c; + int i=1; + String ans="y"; + do { + System.out.println("enter player id"); + pid=sc.nextInt(); + System.out.println("enter player name"); + pnm=sc.next(); + System.out.println("enter player speciality"); + sp=sc.next(); + plst[i]=new Player(pid,pnm,sp); + i++; + System.out.println("Do you want to add more(y/n)"); + ans=sc.next(); + }while(ans.equals("y")); + + //add team object in the tarr at cnt position + tarr[cnt]=new Team(tid,tnm,c,plst,i); + cnt++; + return true; + } + return false; + } + public static void displayAll() { + for(Team t:tarr) { + if (t!=null) + { + System.out.println(t); + }else { + break; + } + } + + } + public static Team findById(int tid) { + for(Team t:tarr) { + if(t!=null) { + if(t.getTid()==tid) + return t; + }else { + break; + } + } + return null; + } + + public static boolean addNewPlayer(int tid, int pid, String pnm, String sp) { + Team t=findById(tid); + if(t!=null) { + Player p=new Player(pid,pnm,sp); + int s=t.getSize(); + //adding player in player list of team + t.getPlist()[s]=p; + t.setSize(s+1); + return true; + + } + + return false; + } + public static Team findTeamByplayer(int pid) { + for(Team t:tarr) { + if(t!=null) { + //retrieve player array from team + Player[] plst=t.getPlist(); + for(Player p:plst) { + if(p!=null) { + if(p.getPid()==pid) { + return t; + } + }else { + break; + } + } + }else { + break; + } + } + return null; + } + +} diff --git a/Day6/Day6/Has-A/src/TestTeam.java b/Day6/Day6/Has-A/src/TestTeam.java new file mode 100644 index 0000000..bc7bcb0 --- /dev/null +++ b/Day6/Day6/Has-A/src/TestTeam.java @@ -0,0 +1,17 @@ + +public class TestTeam { + + public static void main(String[] args) { + Player[] plst= { + new Player(11,"Virat Kohali","Batsman"), + new Player(12,"Rohit Sharma","Batsman"), + new Player(13,"Hardik Pandya","Allrounder") + + }; + Player c=new Player(11,"Rohit Sharma","Batsman"); + Team t1=new Team(100,"Indian Team",c,plst,3); + System.out.println(t1); + + } + +} diff --git a/Day6/Day6/Has-A/src/TestTeamArray.java b/Day6/Day6/Has-A/src/TestTeamArray.java new file mode 100644 index 0000000..be2a10a --- /dev/null +++ b/Day6/Day6/Has-A/src/TestTeamArray.java @@ -0,0 +1,70 @@ +import java.util.Scanner; + +public class TestTeamArray { + + public static void main(String[] args) { + Scanner sc=new Scanner(System.in); + int choice=0; + do { + System.out.println("1. add new team\n2. Display all teams\n"); + System.out.println("3. search team by id\n4. Add new player\n"); + System.out.println("5. search a player\n6. exit\nChoice: "); + choice=sc.nextInt(); + switch(choice) { + case 1: + boolean status=TeamService.addNewTeam(); + if(status) + System.out.println("team added successfully"); + else + System.out.println("Error: Team not added"); + break; + case 2: + TeamService.displayAll(); + break; + case 3: + System.out.println("enter teamid to search"); + int tid=sc.nextInt(); + Team t=TeamService.findById(tid); + if(t!=null) { + System.out.println(t); + }else { + System.out.println("not found"); + } + break; + case 4: + System.out.println("enter teamid to add new player"); + tid=sc.nextInt(); + System.out.println("add new player id"); + int pid=sc.nextInt(); + System.out.println("enter player name"); + String pnm=sc.next(); + System.out.println("enter player speciality"); + String sp=sc.next(); + status=TeamService.addNewPlayer(tid,pid,pnm,sp); + if(status) + System.out.println("player added successfully"); + else + System.out.println("Error: Team not found"); + break; + case 5: + System.out.println("enter pid to search"); + pid=sc.nextInt(); + Team team=TeamService.findTeamByplayer(pid); + if(team!=null) { + System.out.println(team); + }else { + System.out.println("player not found"); + } + break; + case 6: + sc.close(); + System.out.println("Thank you for visiting......."); + break; + default: + System.out.println("Wrong choice"); + break; + } + }while(choice!=6); + } + +} diff --git a/Day6/Day6/Inheritance/bin/com/demo/Test/TestEmployee.class b/Day6/Day6/Inheritance/bin/com/demo/Test/TestEmployee.class new file mode 100644 index 0000000..2e7e173 Binary files /dev/null and b/Day6/Day6/Inheritance/bin/com/demo/Test/TestEmployee.class differ diff --git a/Day6/Day6/Inheritance/bin/com/demo/bean/Employee.class b/Day6/Day6/Inheritance/bin/com/demo/bean/Employee.class new file mode 100644 index 0000000..247399a Binary files /dev/null and b/Day6/Day6/Inheritance/bin/com/demo/bean/Employee.class differ diff --git a/Day6/Day6/Inheritance/bin/com/demo/bean/Person.class b/Day6/Day6/Inheritance/bin/com/demo/bean/Person.class new file mode 100644 index 0000000..c695eb2 Binary files /dev/null and b/Day6/Day6/Inheritance/bin/com/demo/bean/Person.class differ diff --git a/Day6/Day6/Inheritance/src/com/demo/Test/TestEmployee.java b/Day6/Day6/Inheritance/src/com/demo/Test/TestEmployee.java new file mode 100644 index 0000000..851fe40 --- /dev/null +++ b/Day6/Day6/Inheritance/src/com/demo/Test/TestEmployee.java @@ -0,0 +1,9 @@ +package com.demo.Test; + +public class TestEmployee { + + public static void main(String[] args) { + + } + +} diff --git a/Day6/Day6/Inheritance/src/com/demo/bean/Employee.java b/Day6/Day6/Inheritance/src/com/demo/bean/Employee.java new file mode 100644 index 0000000..980b137 --- /dev/null +++ b/Day6/Day6/Inheritance/src/com/demo/bean/Employee.java @@ -0,0 +1,33 @@ +package com.demo.bean; + +public class Employee extends Person { + private String dept; + private String desg; + public Employee() { + super(); + } + public Employee(String dept, String desg) { + super(); + this.dept = dept; + this.desg = desg; + } + public String getDept() { + return dept; + } + public void setDept(String dept) { + this.dept = dept; + } + public String getDesg() { + return desg; + } + public void setDesg(String desg) { + this.desg = desg; + } + @Override + public String toString() { + return "Employee [dept=" + dept + ", desg=" + desg + "]"; + } + + + +} \ No newline at end of file diff --git a/Day6/Day6/Inheritance/src/com/demo/bean/Person.java b/Day6/Day6/Inheritance/src/com/demo/bean/Person.java new file mode 100644 index 0000000..9eb1daf --- /dev/null +++ b/Day6/Day6/Inheritance/src/com/demo/bean/Person.java @@ -0,0 +1,8 @@ +package com.demo.bean; + +public class Person { + private int pid; + private String pname; + private String bdate; + +} diff --git a/Day6/Day6/InheritancePerson/bin/com/demo/bin/ContractEmp.class b/Day6/Day6/InheritancePerson/bin/com/demo/bin/ContractEmp.class new file mode 100644 index 0000000..2abdf3d Binary files /dev/null and b/Day6/Day6/InheritancePerson/bin/com/demo/bin/ContractEmp.class differ diff --git a/Day6/Day6/InheritancePerson/bin/com/demo/bin/Employee.class b/Day6/Day6/InheritancePerson/bin/com/demo/bin/Employee.class new file mode 100644 index 0000000..04ceb5e Binary files /dev/null and b/Day6/Day6/InheritancePerson/bin/com/demo/bin/Employee.class differ diff --git a/Day6/Day6/InheritancePerson/bin/com/demo/bin/EmpoyeeService.class b/Day6/Day6/InheritancePerson/bin/com/demo/bin/EmpoyeeService.class new file mode 100644 index 0000000..4ca5b21 Binary files /dev/null and b/Day6/Day6/InheritancePerson/bin/com/demo/bin/EmpoyeeService.class differ diff --git a/Day6/Day6/InheritancePerson/bin/com/demo/bin/Person.class b/Day6/Day6/InheritancePerson/bin/com/demo/bin/Person.class new file mode 100644 index 0000000..5c3a68b Binary files /dev/null and b/Day6/Day6/InheritancePerson/bin/com/demo/bin/Person.class differ diff --git a/Day6/Day6/InheritancePerson/bin/com/demo/bin/SalariedEmp.class b/Day6/Day6/InheritancePerson/bin/com/demo/bin/SalariedEmp.class new file mode 100644 index 0000000..15a5439 Binary files /dev/null and b/Day6/Day6/InheritancePerson/bin/com/demo/bin/SalariedEmp.class differ diff --git a/Day6/Day6/InheritancePerson/bin/com/demo/bin/Test/TestContaint.class b/Day6/Day6/InheritancePerson/bin/com/demo/bin/Test/TestContaint.class new file mode 100644 index 0000000..3debc04 Binary files /dev/null and b/Day6/Day6/InheritancePerson/bin/com/demo/bin/Test/TestContaint.class differ diff --git a/Day6/Day6/InheritancePerson/bin/com/demo/bin/Test/TestEmployee.class b/Day6/Day6/InheritancePerson/bin/com/demo/bin/Test/TestEmployee.class new file mode 100644 index 0000000..64275de Binary files /dev/null and b/Day6/Day6/InheritancePerson/bin/com/demo/bin/Test/TestEmployee.class differ diff --git a/Day6/Day6/InheritancePerson/bin/com/demo/bin/Test/TestPerson.class b/Day6/Day6/InheritancePerson/bin/com/demo/bin/Test/TestPerson.class new file mode 100644 index 0000000..ab91d71 Binary files /dev/null and b/Day6/Day6/InheritancePerson/bin/com/demo/bin/Test/TestPerson.class differ diff --git a/Day6/Day6/InheritancePerson/bin/com/demo/bin/Vendor.class b/Day6/Day6/InheritancePerson/bin/com/demo/bin/Vendor.class new file mode 100644 index 0000000..08e9d91 Binary files /dev/null and b/Day6/Day6/InheritancePerson/bin/com/demo/bin/Vendor.class differ diff --git a/Day6/Day6/InheritancePerson/src/com/demo/bin/ContractEmp.java b/Day6/Day6/InheritancePerson/src/com/demo/bin/ContractEmp.java new file mode 100644 index 0000000..2c72681 --- /dev/null +++ b/Day6/Day6/InheritancePerson/src/com/demo/bin/ContractEmp.java @@ -0,0 +1,56 @@ +package com.demo.bin; + +import java.util.Date; + +public class ContractEmp extends Employee{ + private double hrs; + private double hrscharge; + //Default-Constructor + public ContractEmp() { + super(); + } + + //Parameterized-Constructor + public ContractEmp(String pname, int pid, Date bdate,String dgn, String dpt,double hrs, double hrscharge) { + super(pname,pid,bdate,dgn,dpt); + this.hrs = hrs; + this.hrscharge = hrscharge; + } + + //Getter-Setter + public double getHrs() { + return hrs; + } + + public void setHrs(double hrs) { + this.hrs = hrs; + } + + public double getHrscharge() { + return hrscharge; + } + + public void setHrscharge(double hrscharge) { + this.hrscharge = hrscharge; + } + + //To-string Method + @Override + public String toString() { + return "ContractEmp [hrs=" + hrs + ", hrscharge=" + hrscharge + "]"; + } + + + public double calculatehrs() { + return hrs*hrscharge; + + } + @Override + public double calculateSal(){ + return hrs*hrscharge; + + } + + + +} diff --git a/Day6/Day6/InheritancePerson/src/com/demo/bin/Employee.java b/Day6/Day6/InheritancePerson/src/com/demo/bin/Employee.java new file mode 100644 index 0000000..73e43f1 --- /dev/null +++ b/Day6/Day6/InheritancePerson/src/com/demo/bin/Employee.java @@ -0,0 +1,56 @@ +package com.demo.bin; + +import java.util.Date; + +public abstract class Employee extends Person { + //private int empid; + private String dgn; + private String dpt; + + //constructor with super class + public Employee() { + super(); + } + //para-constructor + + public Employee(String pname, int pid, Date bdate,String dgn, String dpt) { + super(pname,pid,bdate); + this.dgn = dgn; + this.dpt = dpt; + } + + //getter and setter + public String getDgn() { + return dgn; + } + + public void setDgn(String dgn) { + this.dgn = dgn; + } + + public String getDpt() { + return dpt; + } + + public void setDpt(String dpt) { + this.dpt = dpt; + } + + //to string method + @Override + public String toString() { + return super.toString()+"Employee [dgn=" + dgn + ", dpt=" + dpt + "]"; + } + abstract public double calculateSal() ; + + abstract public double calculatehrs() ; + + + + + + + + + +} diff --git a/Day6/Day6/InheritancePerson/src/com/demo/bin/EmpoyeeService.java b/Day6/Day6/InheritancePerson/src/com/demo/bin/EmpoyeeService.java new file mode 100644 index 0000000..4212daa --- /dev/null +++ b/Day6/Day6/InheritancePerson/src/com/demo/bin/EmpoyeeService.java @@ -0,0 +1,61 @@ +package com.demo.bin; + +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.Scanner; + +public class EmpoyeeService { + + static Employee[] empArr; + + static int count; + + static { + empArr = new Employee[100]; + empArr[0] = new SalariedEmp("Aditya",30,new Date(2002,12,20),"Developer","Software",30000,10); + empArr[1] = new SalariedEmp("pratik",30,new Date(2002,11,2),"Developer","Software",31000,10); + empArr[2] = new SalariedEmp("arya",30,new Date(2011,10,5),"Developer","Software",32000,10); + empArr[3] = new SalariedEmp("kedar",30,new Date(2011,11,20),"Developer","Software",33000,10); + empArr[4] = new SalariedEmp("krishna",30,new Date(2003,12,25),"Developer","Software",34000,10); + count = 5; + } + + public static boolean addNewEmp(int ch) { + Scanner sc = new Scanner(System.in); + if(count "+this.sal+"----"+ob.sal); + /*if(this.sal elist; + static { + elist=new ArrayList<>(); + elist.add(new Employee(100,"Manjiri",45678,LocalDate.of(2024, 11, 12))); + elist.add(new Employee(101,"Gauri",55678,LocalDate.of(2023, 11, 12))); + elist.add(new Employee(103,"Kanchan",35678,LocalDate.of(2020, 11, 12))); + } + @Override + public boolean save(Employee e) { + elist.add(e); + return true; + + } + @Override + public List findAll() { + return elist; + } + @Override + public Employee findById(int empid) { + for(Employee e:elist) { + if(e.getEmpid() == (empid)) { + return e; + } + } + return null; + } + @Override + public Employee findByName(String ename) { + for (Employee e : elist) { + if (e.getEname().equals(ename)) { + return e; + } + } + return null; + } + @Override + public boolean delById(int empid) { + return elist.removeIf(e -> e.getEmpid() == empid); + } + @Override + public boolean delBySal(double sal) { + return elist.removeIf(e -> e.getSal() == sal); + } + @Override + public Employee findBySal(double sal) { + for(Employee e1 : elist) { + if(e1.getSal()==sal) { + return e1; + } + } + return null; + } + @Override + public List sortBySal() { + List lst = new ArrayList<>(elist); + // Sort by salary in ascending order using a Comparator + lst.sort((e1, e2) -> Double.compare(e1.getSal(), e2.getSal())); + return lst; + } + @Override + public boolean UpdatedSalary(int eid, double sal) { + int pos = elist.indexOf(new Employee(eid)); + if(pos!=-1) { + Employee e =elist.get(pos); + e.setSal(sal); + return true; + } + return false; + } + +} diff --git a/Day6/EmployeeProject/src/com/demo/dao/EmpDao.java b/Day6/EmployeeProject/src/com/demo/dao/EmpDao.java new file mode 100644 index 0000000..fa27e66 --- /dev/null +++ b/Day6/EmployeeProject/src/com/demo/dao/EmpDao.java @@ -0,0 +1,26 @@ +package com.demo.dao; + +import java.util.List; + +import com.demo.beans.Employee; + +public interface EmpDao { + boolean save(Employee e); + + List findAll(); + + Employee findById(int empid); + + Employee findByName(String ename); + + boolean delById(int eid); + + boolean delBySal(double sal); + + Employee findBySal(double sal); + + List sortBySal(); + + boolean UpdatedSalary(int eid, double sal); + +} diff --git a/Day6/EmployeeProject/src/com/demo/service/EmployeeService.java b/Day6/EmployeeProject/src/com/demo/service/EmployeeService.java new file mode 100644 index 0000000..2c4e1fb --- /dev/null +++ b/Day6/EmployeeProject/src/com/demo/service/EmployeeService.java @@ -0,0 +1,31 @@ +package com.demo.service; + +import java.util.List; + +import com.demo.beans.Employee; + +public interface EmployeeService { + + boolean AddNewEmployee(); + + List displayAll(); + + Employee searchById(int eid); + + Employee searchByName(String ename); + + //boolean deleteById(int eid); + + boolean deleteById(int empid); + + boolean deleteBySal(double sal); + + Employee searchBySal(double sal); + + + + List sortBySal(); + + boolean UpdateSal(int eid, double sal); + +} diff --git a/Day6/EmployeeProject/src/com/demo/service/EmployeeServiceImpl.java b/Day6/EmployeeProject/src/com/demo/service/EmployeeServiceImpl.java new file mode 100644 index 0000000..886b568 --- /dev/null +++ b/Day6/EmployeeProject/src/com/demo/service/EmployeeServiceImpl.java @@ -0,0 +1,97 @@ +package com.demo.service; +import java.time.LocalDate; +import java.time.format.DateTimeFormatter; +import java.util.List; +import java.util.Scanner; + +import com.demo.beans.Employee; +import com.demo.dao.DaoImplementation; +import com.demo.dao.EmpDao; + +public class EmployeeServiceImpl implements EmployeeService { + private EmpDao edao; + public EmployeeServiceImpl() { + + edao=new DaoImplementation(); + } + + + @Override + public boolean AddNewEmployee() { + + Scanner sc = new Scanner(System.in); + System.out.println("Enter Employee ID :"); + int empid = sc.nextInt(); + System.out.println("Enter Employee Name :"); + String ename = sc.next(); + System.out.println("Enter Employee Salary :"); + double sal = sc.nextDouble(); + System.out.println("Enter Employee Joining Date :"); + String dt= sc.next(); + LocalDate ldt = LocalDate.parse(dt,DateTimeFormatter.ofPattern(dt="dd/MM/yyyy")); + Employee e = new Employee(empid,ename,sal,ldt); + return edao.save(e); + + + } + + @Override + public List displayAll() { + return edao.findAll(); + } + + + @Override + public Employee searchById(int eid) { + return edao.findById(eid); + } + + + @Override + public Employee searchByName(String ename) { + // TODO Auto-generated method stub + return edao.findByName(ename); + } + + + @Override + public boolean deleteById(int empid) { + return edao.delById(empid); + } + + + @Override + public boolean deleteBySal(double sal) { + // TODO Auto-generated method stub + return edao.delBySal(sal); + } + + + @Override + public Employee searchBySal(double sal) { + // TODO Auto-generated method stub + return edao.findBySal(sal); + } + + @Override + public List sortBySal() { + + return edao.sortBySal(); + } + + + @Override + public boolean UpdateSal(int eid, double sal) { + // TODO Auto-generated method stub + return edao.UpdatedSalary(eid , sal); + } + + + + + + + + + +} diff --git a/Day6/EmployeeProject/src/com/demo/test/TestEmployeeManagementSystem.java b/Day6/EmployeeProject/src/com/demo/test/TestEmployeeManagementSystem.java new file mode 100644 index 0000000..5f8869a --- /dev/null +++ b/Day6/EmployeeProject/src/com/demo/test/TestEmployeeManagementSystem.java @@ -0,0 +1,117 @@ +package com.demo.test; + +import java.util.List; +import java.util.Scanner; +import com.demo.beans.Employee; +import com.demo.service.EmployeeService; +import com.demo.service.EmployeeServiceImpl; + +public class TestEmployeeManagementSystem { + + public static void main(String[] args) { + Scanner sc = new Scanner(System.in); + EmployeeService eservice = new EmployeeServiceImpl(); + int choice = 0; + do { + System.out.println("1.Add new Empolyee\n 2.Display All\n 3.Search By Id"); + System.out.println("4.Search By Name\n 5.Update Salary\n 6.Delete By Id\n 7.Delete By Salary\n"); + System.out.println("8.Search By Salary\n 9.sort By Salary\n 10.Exit\n choice:"); + choice = sc.nextInt(); + switch(choice) { + case 1 ->{ + boolean status = eservice.AddNewEmployee(); + if(status) { + System.out.println("Added Successfully"); + } + else { + System.out.println("Not Found"); + } + } + case 2 ->{ + List elist = eservice.displayAll(); + elist.forEach(System.out::println); + + } + case 3 ->{ + System.out.println("Enter ID to search :"); + int eid = sc.nextInt(); + Employee e = eservice.searchById(eid); + if(e!=null) { + System.out.println(e); + } + else { + System.out.println("Not Found"); + } + } + case 4 ->{ + System.out.println("Enter Name to Search"); + String ename = sc.next(); + Employee e1 = eservice.searchByName(ename); + if(e1!=null) { + System.out.println(e1); + } + else { + System.out.println("Not Found"); + } + } + case 5 ->{ + System.out.println("Enter Id to Select Salary :"); + int eid = sc.nextInt(); + System.out.println("Enter Salary :"); + double sal = sc.nextDouble(); + boolean status = eservice.UpdateSal(eid , sal); + if(status) { + System.out.println("Updated Successfully"); + } + else { + System.out.println("Not Found"); + } + } + case 6 ->{ + System.out.println("Delete by Id is : "); + int empid = sc.nextInt(); + boolean status = eservice.deleteById(empid); + if(status) { + System.out.println("Deleted Sucessfully"); + }else { + System.out.println("Not Found "); + } + + } + case 7 ->{ + System.out.println("Enter Salary to delete :"); + double sal = sc.nextDouble(); + boolean status = eservice.deleteBySal(sal); + if(status) { + System.out.println("Deleted Sucessfully"); + }else { + System.out.println("Not Found "); + } + } + case 8 ->{ + System.out.println("Enter salary to search :"); + double sal =sc.nextDouble(); + Employee e2 = eservice.searchBySal(sal); + if(e2!=null) { + System.out.println(e2); + } + else { + System.out.println("Not Found"); + } + } + case 9 ->{ + List lst=eservice.sortBySal(); + lst.forEach(System.out::println); + } + + case 10 ->{ + System.out.println("Thank you for visiting....."); + sc.close(); + } + } + } + while(choice!=10) ; + + } + +} diff --git a/Day6/Has-A/bin/Player.class b/Day6/Has-A/bin/Player.class new file mode 100644 index 0000000..2aa4cdc Binary files /dev/null and b/Day6/Has-A/bin/Player.class differ diff --git a/Day6/Has-A/bin/Team.class b/Day6/Has-A/bin/Team.class new file mode 100644 index 0000000..574af2e Binary files /dev/null and b/Day6/Has-A/bin/Team.class differ diff --git a/Day6/Has-A/bin/TeamService.class b/Day6/Has-A/bin/TeamService.class new file mode 100644 index 0000000..4331018 Binary files /dev/null and b/Day6/Has-A/bin/TeamService.class differ diff --git a/Day6/Has-A/bin/TestTeam.class b/Day6/Has-A/bin/TestTeam.class new file mode 100644 index 0000000..5e649c2 Binary files /dev/null and b/Day6/Has-A/bin/TestTeam.class differ diff --git a/Day6/Has-A/bin/TestTeamArray.class b/Day6/Has-A/bin/TestTeamArray.class new file mode 100644 index 0000000..292c7c1 Binary files /dev/null and b/Day6/Has-A/bin/TestTeamArray.class differ diff --git a/Day6/Has-A/src/Player.java b/Day6/Has-A/src/Player.java new file mode 100644 index 0000000..3c30e86 --- /dev/null +++ b/Day6/Has-A/src/Player.java @@ -0,0 +1,38 @@ +public class Player { + private int pid; + private String pname; + private String speciality; + public Player() { + super(); + } + public Player(int pid, String pname, String speciality) { + super(); + this.pid = pid; + this.pname = pname; + this.speciality = speciality; + } + public int getPid() { + return pid; + } + public void setPid(int pid) { + this.pid = pid; + } + public String getPname() { + return pname; + } + public void setPname(String pname) { + this.pname = pname; + } + public String getSpeciality() { + return speciality; + } + public void setSpeciality(String speciality) { + this.speciality = speciality; + } + @Override + public String toString() { + return "Player [pid=" + pid + ", pname=" + pname + ", speciality=" + speciality + "]"; + } + + +} diff --git a/Day6/Has-A/src/Team.java b/Day6/Has-A/src/Team.java new file mode 100644 index 0000000..dca2fc9 --- /dev/null +++ b/Day6/Has-A/src/Team.java @@ -0,0 +1,61 @@ +import java.util.Arrays; + +public class Team { + private int tid; + private String tname; + private Player captain; + private Player[] plist; + private int size; + public Team() { + super(); + } + + public Team(int tid, String tname, Player captain, Player[] plist, int size) { + super(); + this.tid = tid; + this.tname = tname; + this.captain = captain; + this.plist = plist; + this.size = size; + } + + public int getTid() { + return tid; + } + public void setTid(int tid) { + this.tid = tid; + } + public String getTname() { + return tname; + } + public void setTname(String tname) { + this.tname = tname; + } + public Player getCaptain() { + return captain; + } + public void setCaptain(Player captain) { + this.captain = captain; + } + public Player[] getPlist() { + return plist; + } + public void setPlist(Player[] plist) { + this.plist = plist; + } + + public int getSize() { + return size; + } + + public void setSize(int size) { + this.size = size; + } + + @Override + public String toString() { + return "Team [tid=" + tid + ", tname=" + tname + ", captain=" + captain + ", plist=" + Arrays.toString(plist) + + "]"; + } + +} diff --git a/Day6/Has-A/src/TeamService.java b/Day6/Has-A/src/TeamService.java new file mode 100644 index 0000000..98a9a51 --- /dev/null +++ b/Day6/Has-A/src/TeamService.java @@ -0,0 +1,125 @@ +import java.util.Scanner; + +public class TeamService { + static Team[] tarr; + static int cnt; + static { + tarr=new Team[20]; + Player[] plst= new Player[15]; + plst[0]=new Player(11,"Virat Kohali","Batsman"); + plst[1]=new Player(12,"Rohit Sharma","Batsman"); + plst[2]=new Player(13,"Hardik Pandya","Allrounder"); + Player c=new Player(11,"Rohit Sharma","Batsman"); + tarr[0]=new Team(101,"MI",c,plst,3); + + Player[] plst1= new Player[15]; + plst1[0]=new Player(16,"Dravid","Batsman"); + plst1[1]=new Player(17,"Saurabh","Batsman"); + plst1[2]=new Player(18,"Sachin","Allrounder"); + Player c1=new Player(11,"Sachin","Allrounder"); + tarr[1]=new Team(100,"RCB",c1,plst1,3); + + cnt=2; + + } + public static boolean addNewTeam() { + Scanner sc=new Scanner(System.in); + if(cnt!=20) { + //team details + System.out.println("enter tid"); + int tid=sc.nextInt(); + System.out.println("enter team name"); + String tnm=sc.next(); + + //captain + System.out.println("enter captain player id"); + int pid=sc.nextInt(); + System.out.println("enter captain player name"); + String pnm=sc.next(); + System.out.println("enter captain player speciality"); + String sp=sc.next(); + Player c=new Player(pid,pnm,sp); + //loop for creating player list + Player[] plst=new Player[15]; + plst[0]=c; + int i=1; + String ans="y"; + do { + System.out.println("enter player id"); + pid=sc.nextInt(); + System.out.println("enter player name"); + pnm=sc.next(); + System.out.println("enter player speciality"); + sp=sc.next(); + plst[i]=new Player(pid,pnm,sp); + i++; + System.out.println("Do you want to add more(y/n)"); + ans=sc.next(); + }while(ans.equals("y")); + + //add team object in the tarr at cnt position + tarr[cnt]=new Team(tid,tnm,c,plst,i); + cnt++; + return true; + } + return false; + } + public static void displayAll() { + for(Team t:tarr) { + if (t!=null) + { + System.out.println(t); + }else { + break; + } + } + + } + public static Team findById(int tid) { + for(Team t:tarr) { + if(t!=null) { + if(t.getTid()==tid) + return t; + }else { + break; + } + } + return null; + } + + public static boolean addNewPlayer(int tid, int pid, String pnm, String sp) { + Team t=findById(tid); + if(t!=null) { + Player p=new Player(pid,pnm,sp); + int s=t.getSize(); + //adding player in player list of team + t.getPlist()[s]=p; + t.setSize(s+1); + return true; + + } + + return false; + } + public static Team findTeamByplayer(int pid) { + for(Team t:tarr) { + if(t!=null) { + //retrieve player array from team + Player[] plst=t.getPlist(); + for(Player p:plst) { + if(p!=null) { + if(p.getPid()==pid) { + return t; + } + }else { + break; + } + } + }else { + break; + } + } + return null; + } + +} diff --git a/Day6/Has-A/src/TestTeam.java b/Day6/Has-A/src/TestTeam.java new file mode 100644 index 0000000..bc7bcb0 --- /dev/null +++ b/Day6/Has-A/src/TestTeam.java @@ -0,0 +1,17 @@ + +public class TestTeam { + + public static void main(String[] args) { + Player[] plst= { + new Player(11,"Virat Kohali","Batsman"), + new Player(12,"Rohit Sharma","Batsman"), + new Player(13,"Hardik Pandya","Allrounder") + + }; + Player c=new Player(11,"Rohit Sharma","Batsman"); + Team t1=new Team(100,"Indian Team",c,plst,3); + System.out.println(t1); + + } + +} diff --git a/Day6/Has-A/src/TestTeamArray.java b/Day6/Has-A/src/TestTeamArray.java new file mode 100644 index 0000000..be2a10a --- /dev/null +++ b/Day6/Has-A/src/TestTeamArray.java @@ -0,0 +1,70 @@ +import java.util.Scanner; + +public class TestTeamArray { + + public static void main(String[] args) { + Scanner sc=new Scanner(System.in); + int choice=0; + do { + System.out.println("1. add new team\n2. Display all teams\n"); + System.out.println("3. search team by id\n4. Add new player\n"); + System.out.println("5. search a player\n6. exit\nChoice: "); + choice=sc.nextInt(); + switch(choice) { + case 1: + boolean status=TeamService.addNewTeam(); + if(status) + System.out.println("team added successfully"); + else + System.out.println("Error: Team not added"); + break; + case 2: + TeamService.displayAll(); + break; + case 3: + System.out.println("enter teamid to search"); + int tid=sc.nextInt(); + Team t=TeamService.findById(tid); + if(t!=null) { + System.out.println(t); + }else { + System.out.println("not found"); + } + break; + case 4: + System.out.println("enter teamid to add new player"); + tid=sc.nextInt(); + System.out.println("add new player id"); + int pid=sc.nextInt(); + System.out.println("enter player name"); + String pnm=sc.next(); + System.out.println("enter player speciality"); + String sp=sc.next(); + status=TeamService.addNewPlayer(tid,pid,pnm,sp); + if(status) + System.out.println("player added successfully"); + else + System.out.println("Error: Team not found"); + break; + case 5: + System.out.println("enter pid to search"); + pid=sc.nextInt(); + Team team=TeamService.findTeamByplayer(pid); + if(team!=null) { + System.out.println(team); + }else { + System.out.println("player not found"); + } + break; + case 6: + sc.close(); + System.out.println("Thank you for visiting......."); + break; + default: + System.out.println("Wrong choice"); + break; + } + }while(choice!=6); + } + +} diff --git a/Day6/Inheritance/bin/com/demo/Test/TestEmployee.class b/Day6/Inheritance/bin/com/demo/Test/TestEmployee.class new file mode 100644 index 0000000..2e7e173 Binary files /dev/null and b/Day6/Inheritance/bin/com/demo/Test/TestEmployee.class differ diff --git a/Day6/Inheritance/bin/com/demo/bean/Employee.class b/Day6/Inheritance/bin/com/demo/bean/Employee.class new file mode 100644 index 0000000..247399a Binary files /dev/null and b/Day6/Inheritance/bin/com/demo/bean/Employee.class differ diff --git a/Day6/Inheritance/bin/com/demo/bean/Person.class b/Day6/Inheritance/bin/com/demo/bean/Person.class new file mode 100644 index 0000000..c695eb2 Binary files /dev/null and b/Day6/Inheritance/bin/com/demo/bean/Person.class differ diff --git a/Day6/Inheritance/src/com/demo/Test/TestEmployee.java b/Day6/Inheritance/src/com/demo/Test/TestEmployee.java new file mode 100644 index 0000000..851fe40 --- /dev/null +++ b/Day6/Inheritance/src/com/demo/Test/TestEmployee.java @@ -0,0 +1,9 @@ +package com.demo.Test; + +public class TestEmployee { + + public static void main(String[] args) { + + } + +} diff --git a/Day6/Inheritance/src/com/demo/bean/Employee.java b/Day6/Inheritance/src/com/demo/bean/Employee.java new file mode 100644 index 0000000..980b137 --- /dev/null +++ b/Day6/Inheritance/src/com/demo/bean/Employee.java @@ -0,0 +1,33 @@ +package com.demo.bean; + +public class Employee extends Person { + private String dept; + private String desg; + public Employee() { + super(); + } + public Employee(String dept, String desg) { + super(); + this.dept = dept; + this.desg = desg; + } + public String getDept() { + return dept; + } + public void setDept(String dept) { + this.dept = dept; + } + public String getDesg() { + return desg; + } + public void setDesg(String desg) { + this.desg = desg; + } + @Override + public String toString() { + return "Employee [dept=" + dept + ", desg=" + desg + "]"; + } + + + +} \ No newline at end of file diff --git a/Day6/Inheritance/src/com/demo/bean/Person.java b/Day6/Inheritance/src/com/demo/bean/Person.java new file mode 100644 index 0000000..9eb1daf --- /dev/null +++ b/Day6/Inheritance/src/com/demo/bean/Person.java @@ -0,0 +1,8 @@ +package com.demo.bean; + +public class Person { + private int pid; + private String pname; + private String bdate; + +} diff --git a/Day6/InheritancePerson/bin/com/demo/bin/ContractEmp.class b/Day6/InheritancePerson/bin/com/demo/bin/ContractEmp.class new file mode 100644 index 0000000..2abdf3d Binary files /dev/null and b/Day6/InheritancePerson/bin/com/demo/bin/ContractEmp.class differ diff --git a/Day6/InheritancePerson/bin/com/demo/bin/Employee.class b/Day6/InheritancePerson/bin/com/demo/bin/Employee.class new file mode 100644 index 0000000..04ceb5e Binary files /dev/null and b/Day6/InheritancePerson/bin/com/demo/bin/Employee.class differ diff --git a/Day6/InheritancePerson/bin/com/demo/bin/EmpoyeeService.class b/Day6/InheritancePerson/bin/com/demo/bin/EmpoyeeService.class new file mode 100644 index 0000000..4ca5b21 Binary files /dev/null and b/Day6/InheritancePerson/bin/com/demo/bin/EmpoyeeService.class differ diff --git a/Day6/InheritancePerson/bin/com/demo/bin/Person.class b/Day6/InheritancePerson/bin/com/demo/bin/Person.class new file mode 100644 index 0000000..5c3a68b Binary files /dev/null and b/Day6/InheritancePerson/bin/com/demo/bin/Person.class differ diff --git a/Day6/InheritancePerson/bin/com/demo/bin/SalariedEmp.class b/Day6/InheritancePerson/bin/com/demo/bin/SalariedEmp.class new file mode 100644 index 0000000..15a5439 Binary files /dev/null and b/Day6/InheritancePerson/bin/com/demo/bin/SalariedEmp.class differ diff --git a/Day6/InheritancePerson/bin/com/demo/bin/Test/TestContaint.class b/Day6/InheritancePerson/bin/com/demo/bin/Test/TestContaint.class new file mode 100644 index 0000000..3debc04 Binary files /dev/null and b/Day6/InheritancePerson/bin/com/demo/bin/Test/TestContaint.class differ diff --git a/Day6/InheritancePerson/bin/com/demo/bin/Test/TestEmployee.class b/Day6/InheritancePerson/bin/com/demo/bin/Test/TestEmployee.class new file mode 100644 index 0000000..64275de Binary files /dev/null and b/Day6/InheritancePerson/bin/com/demo/bin/Test/TestEmployee.class differ diff --git a/Day6/InheritancePerson/bin/com/demo/bin/Test/TestPerson.class b/Day6/InheritancePerson/bin/com/demo/bin/Test/TestPerson.class new file mode 100644 index 0000000..ab91d71 Binary files /dev/null and b/Day6/InheritancePerson/bin/com/demo/bin/Test/TestPerson.class differ diff --git a/Day6/InheritancePerson/bin/com/demo/bin/Vendor.class b/Day6/InheritancePerson/bin/com/demo/bin/Vendor.class new file mode 100644 index 0000000..08e9d91 Binary files /dev/null and b/Day6/InheritancePerson/bin/com/demo/bin/Vendor.class differ diff --git a/Day6/InheritancePerson/src/com/demo/bin/ContractEmp.java b/Day6/InheritancePerson/src/com/demo/bin/ContractEmp.java new file mode 100644 index 0000000..2c72681 --- /dev/null +++ b/Day6/InheritancePerson/src/com/demo/bin/ContractEmp.java @@ -0,0 +1,56 @@ +package com.demo.bin; + +import java.util.Date; + +public class ContractEmp extends Employee{ + private double hrs; + private double hrscharge; + //Default-Constructor + public ContractEmp() { + super(); + } + + //Parameterized-Constructor + public ContractEmp(String pname, int pid, Date bdate,String dgn, String dpt,double hrs, double hrscharge) { + super(pname,pid,bdate,dgn,dpt); + this.hrs = hrs; + this.hrscharge = hrscharge; + } + + //Getter-Setter + public double getHrs() { + return hrs; + } + + public void setHrs(double hrs) { + this.hrs = hrs; + } + + public double getHrscharge() { + return hrscharge; + } + + public void setHrscharge(double hrscharge) { + this.hrscharge = hrscharge; + } + + //To-string Method + @Override + public String toString() { + return "ContractEmp [hrs=" + hrs + ", hrscharge=" + hrscharge + "]"; + } + + + public double calculatehrs() { + return hrs*hrscharge; + + } + @Override + public double calculateSal(){ + return hrs*hrscharge; + + } + + + +} diff --git a/Day6/InheritancePerson/src/com/demo/bin/Employee.java b/Day6/InheritancePerson/src/com/demo/bin/Employee.java new file mode 100644 index 0000000..73e43f1 --- /dev/null +++ b/Day6/InheritancePerson/src/com/demo/bin/Employee.java @@ -0,0 +1,56 @@ +package com.demo.bin; + +import java.util.Date; + +public abstract class Employee extends Person { + //private int empid; + private String dgn; + private String dpt; + + //constructor with super class + public Employee() { + super(); + } + //para-constructor + + public Employee(String pname, int pid, Date bdate,String dgn, String dpt) { + super(pname,pid,bdate); + this.dgn = dgn; + this.dpt = dpt; + } + + //getter and setter + public String getDgn() { + return dgn; + } + + public void setDgn(String dgn) { + this.dgn = dgn; + } + + public String getDpt() { + return dpt; + } + + public void setDpt(String dpt) { + this.dpt = dpt; + } + + //to string method + @Override + public String toString() { + return super.toString()+"Employee [dgn=" + dgn + ", dpt=" + dpt + "]"; + } + abstract public double calculateSal() ; + + abstract public double calculatehrs() ; + + + + + + + + + +} diff --git a/Day6/InheritancePerson/src/com/demo/bin/EmpoyeeService.java b/Day6/InheritancePerson/src/com/demo/bin/EmpoyeeService.java new file mode 100644 index 0000000..4212daa --- /dev/null +++ b/Day6/InheritancePerson/src/com/demo/bin/EmpoyeeService.java @@ -0,0 +1,61 @@ +package com.demo.bin; + +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.Scanner; + +public class EmpoyeeService { + + static Employee[] empArr; + + static int count; + + static { + empArr = new Employee[100]; + empArr[0] = new SalariedEmp("Aditya",30,new Date(2002,12,20),"Developer","Software",30000,10); + empArr[1] = new SalariedEmp("pratik",30,new Date(2002,11,2),"Developer","Software",31000,10); + empArr[2] = new SalariedEmp("arya",30,new Date(2011,10,5),"Developer","Software",32000,10); + empArr[3] = new SalariedEmp("kedar",30,new Date(2011,11,20),"Developer","Software",33000,10); + empArr[4] = new SalariedEmp("krishna",30,new Date(2003,12,25),"Developer","Software",34000,10); + count = 5; + } + + public static boolean addNewEmp(int ch) { + Scanner sc = new Scanner(System.in); + if(county?x:y; + } + public int max(int x,int y,int z) { + + return x>y?(x>z?x:z):(y>z?y:z); + } + + public float max(float x,float y) { + return x>y?x:y; + } + + public String max(String x,String y) { + return x.length()>y.length()?x:y; + } + +} diff --git a/Day7/InterfaceDemo/src/com/demo/interfaces/I1.java b/Day7/InterfaceDemo/src/com/demo/interfaces/I1.java new file mode 100644 index 0000000..febb54e --- /dev/null +++ b/Day7/InterfaceDemo/src/com/demo/interfaces/I1.java @@ -0,0 +1,10 @@ +package com.demo.interfaces; + +public interface I1 { + void m1(); + void m2(int x); + int i=12; +// default void m4() { +// System.out.println("in m4 method in I1"); +// } +} diff --git a/Day7/InterfaceDemo/src/com/demo/interfaces/I2.java b/Day7/InterfaceDemo/src/com/demo/interfaces/I2.java new file mode 100644 index 0000000..92688c8 --- /dev/null +++ b/Day7/InterfaceDemo/src/com/demo/interfaces/I2.java @@ -0,0 +1,9 @@ +package com.demo.interfaces; + +public interface I2 { + void m2(int x); + void m3(); +// default void m4() { +// System.out.println("in m4 method in I2"); +// } +} diff --git a/Day7/InterfaceDemo/src/com/demo/interfaces/I3.java b/Day7/InterfaceDemo/src/com/demo/interfaces/I3.java new file mode 100644 index 0000000..e4e96e6 --- /dev/null +++ b/Day7/InterfaceDemo/src/com/demo/interfaces/I3.java @@ -0,0 +1,5 @@ +package com.demo.interfaces; + +public interface I3 extends I1,I2{ + +} diff --git a/Day7/InterfaceDemo/src/com/demo/interfaces/Inter1.java b/Day7/InterfaceDemo/src/com/demo/interfaces/Inter1.java new file mode 100644 index 0000000..45f4dec --- /dev/null +++ b/Day7/InterfaceDemo/src/com/demo/interfaces/Inter1.java @@ -0,0 +1,25 @@ +package com.demo.interfaces; + +public interface Inter1 { + //public and abstract + int m1(); + void m2(int i); + int i=12; //public static final + private void m5() { + System.out.println("same part of m3 and m4"); + } + default int m3() { + m5(); + System.out.println("in m3 method;"); + return 10; + } + default int m4() { + m5(); + System.out.println("in m4 method;"); + return 20; + } + public static void myfunct1() { + System.out.println("in myfunction1"); + } + +} diff --git a/Day7/InterfaceDemo/src/com/demo/interfaces/MyComparable.java b/Day7/InterfaceDemo/src/com/demo/interfaces/MyComparable.java new file mode 100644 index 0000000..9b4be33 --- /dev/null +++ b/Day7/InterfaceDemo/src/com/demo/interfaces/MyComparable.java @@ -0,0 +1,13 @@ +package com.demo.interfaces; + +@FunctionalInterface +public interface MyComparable { + int compare(int a,int b); + + public static void m3() { + System.out.println("in m3 static method"); + } + default int m1(){ + return 10; + } +} diff --git a/Day7/InterfaceDemo/src/com/demo/interfaces/MyGeneric2.java b/Day7/InterfaceDemo/src/com/demo/interfaces/MyGeneric2.java new file mode 100644 index 0000000..0165f2a --- /dev/null +++ b/Day7/InterfaceDemo/src/com/demo/interfaces/MyGeneric2.java @@ -0,0 +1,5 @@ +package com.demo.interfaces; + +public interface MyGeneric2 { + T m1(T x,T y); +} diff --git a/Day7/InterfaceDemo/src/com/demo/interfaces/MyGenericClass.java b/Day7/InterfaceDemo/src/com/demo/interfaces/MyGenericClass.java new file mode 100644 index 0000000..3eb2c50 --- /dev/null +++ b/Day7/InterfaceDemo/src/com/demo/interfaces/MyGenericClass.java @@ -0,0 +1,9 @@ +package com.demo.interfaces; + +//public interface MyGenericClass { +public interface MyGenericClass { + T compare(T x,T y); + //F m1(T x,F y); + +} + diff --git a/Day7/InterfaceDemo/src/com/demo/test/TestFunctionOverloading.java b/Day7/InterfaceDemo/src/com/demo/test/TestFunctionOverloading.java new file mode 100644 index 0000000..df0f2ce --- /dev/null +++ b/Day7/InterfaceDemo/src/com/demo/test/TestFunctionOverloading.java @@ -0,0 +1,17 @@ +package com.demo.test; + +import com.demo.beans.MyTestClass; + +public class TestFunctionOverloading { + + public static void main(String[] args) { + MyTestClass ob=new MyTestClass(); + System.out.println(ob.max(12,13,45)); + System.out.println(ob.max(13,45)); + System.out.println(ob.max(12.5f,13.7f)); + System.out.println(ob.max("hello", "Welcome")); + System.out.println(ob.add(12,34)); + System.out.println(ob.add(12,34,5,4,6,7,8)); + } + +} diff --git a/Day7/InterfaceDemo/src/com/demo/test/TestFunctionalInterface.java b/Day7/InterfaceDemo/src/com/demo/test/TestFunctionalInterface.java new file mode 100644 index 0000000..ad6b7e8 --- /dev/null +++ b/Day7/InterfaceDemo/src/com/demo/test/TestFunctionalInterface.java @@ -0,0 +1,49 @@ +package com.demo.test; + +import com.demo.beans.MyNewCompare; +import com.demo.interfaces.MyComparable; +import com.demo.interfaces.MyGeneric2; +import com.demo.interfaces.MyGenericClass; + +public class TestFunctionalInterface { + public static void main(String[] args) { + MyNewCompare ob=new MyNewCompare(); + ob.compare(10, 20); + + //using Annonymous class + MyComparable ob1=new MyComparable() { + + @Override + public int compare(int a, int b) { + System.out.println("in annonymous class compare "+a+", "+b); + return 0; + } + }; + int c=ob1.compare(110, 220); + + + MyComparable ob2=(x,y)->{ + System.out.println("in compare using lambda function "+x+", "+y); + return 0; + }; + int x=ob2.compare(100, 200); + + MyGenericClass ob3=(x1,y1)->{ + return x1+y1; + } ; + System.out.println(ob3.compare(23, 45)); + MyGenericClass ob4=(x1,y1)->{ + return x1+y1; + } ; + System.out.println(ob3.compare(23, 45)); + + MyGeneric2 mg2=(a,b)->{ + return a+b+20; + }; + //error +// MyGeneric2 mg3=(a,b)->{ +// return a+b+20; +// }; + } + +} diff --git a/Day7/InterfaceDemo/src/com/demo/test/TestMyClassInterfaces.java b/Day7/InterfaceDemo/src/com/demo/test/TestMyClassInterfaces.java new file mode 100644 index 0000000..bb74c74 --- /dev/null +++ b/Day7/InterfaceDemo/src/com/demo/test/TestMyClassInterfaces.java @@ -0,0 +1,18 @@ +package com.demo.test; + +import com.demo.beans.MyClass; +import com.demo.interfaces.I1; +import com.demo.interfaces.I2; + +public class TestMyClassInterfaces { + public static void main(String[] args) { + MyClass ob=new MyClass(); + ob.m2(10); + I1 ob2=new MyClass(); + ob2.m1(); + ((MyClass) ob2).m3(); + I2 ob3=new MyClass(); + ((MyClass)ob3).m1(); + + } +} diff --git a/Day7/InterfaceDemo/src/com/demo/test/TestStringData.java b/Day7/InterfaceDemo/src/com/demo/test/TestStringData.java new file mode 100644 index 0000000..88698ce --- /dev/null +++ b/Day7/InterfaceDemo/src/com/demo/test/TestStringData.java @@ -0,0 +1,32 @@ +package com.demo.test; + +public class TestStringData { + + public static void main(String[] args) { + String s1="Test"; + String s2="Test"; + String s3=s2; + String s4=new String("Test"); + System.out.println(" s2 == s3 "+(s2==s3)); //true + System.out.println(" s2 == s4 "+(s2==s4)); //false + System.out.println(" s2 .equals(s4) "+(s2.equals(s4))); //true + s1="welcome"; + System.out.println(" s2 == s1 "+(s2==s1)); //false + + //all the methods are synchronized, so they are thread safe + //useful in multithreaded program + StringBuffer sbf=new StringBuffer("Hello"); + System.out.println(sbf.append(" Everyone")); //Hello Everyone + + //useful in single threaded program, It is not thread safe + StringBuilder sbd=new StringBuilder("test"); + System.out.println(sbd.append(" data")); //test data + + String s6="xxx,yyy,zzz-rrrr"; + String[] arr=s6.split(","); + String str=String.join(":",arr); + System.out.println(str); + + } + +} diff --git a/Day7/day 7 notes.pdf b/Day7/day 7 notes.pdf new file mode 100644 index 0000000..1da8688 Binary files /dev/null and b/Day7/day 7 notes.pdf differ diff --git a/Day7/day 8 notes.pdf b/Day7/day 8 notes.pdf new file mode 100644 index 0000000..9889b0c Binary files /dev/null and b/Day7/day 8 notes.pdf differ diff --git a/Day7/day6 notes.pdf b/Day7/day6 notes.pdf new file mode 100644 index 0000000..160854a Binary files /dev/null and b/Day7/day6 notes.pdf differ diff --git a/Day8/Collection classes in Java.pdf b/Day8/Collection classes in Java.pdf new file mode 100644 index 0000000..2c76f22 Binary files /dev/null and b/Day8/Collection classes in Java.pdf differ diff --git a/Day8/CollectionDemo/bin/com/demo/beans/Employee.class b/Day8/CollectionDemo/bin/com/demo/beans/Employee.class new file mode 100644 index 0000000..f15cb9a Binary files /dev/null and b/Day8/CollectionDemo/bin/com/demo/beans/Employee.class differ diff --git a/Day8/CollectionDemo/bin/com/demo/dao/EmployeeDao.class b/Day8/CollectionDemo/bin/com/demo/dao/EmployeeDao.class new file mode 100644 index 0000000..449ec8a Binary files /dev/null and b/Day8/CollectionDemo/bin/com/demo/dao/EmployeeDao.class differ diff --git a/Day8/CollectionDemo/bin/com/demo/dao/EmployeeDaoImpl.class b/Day8/CollectionDemo/bin/com/demo/dao/EmployeeDaoImpl.class new file mode 100644 index 0000000..29fcd35 Binary files /dev/null and b/Day8/CollectionDemo/bin/com/demo/dao/EmployeeDaoImpl.class differ diff --git a/Day8/CollectionDemo/bin/com/demo/service/EmployeeService.class b/Day8/CollectionDemo/bin/com/demo/service/EmployeeService.class new file mode 100644 index 0000000..60e9c4b Binary files /dev/null and b/Day8/CollectionDemo/bin/com/demo/service/EmployeeService.class differ diff --git a/Day8/CollectionDemo/bin/com/demo/service/EmployeeServiceImpl.class b/Day8/CollectionDemo/bin/com/demo/service/EmployeeServiceImpl.class new file mode 100644 index 0000000..db3116b Binary files /dev/null and b/Day8/CollectionDemo/bin/com/demo/service/EmployeeServiceImpl.class differ diff --git a/Day8/CollectionDemo/bin/com/demo/test/TestArrayList.class b/Day8/CollectionDemo/bin/com/demo/test/TestArrayList.class new file mode 100644 index 0000000..5b9deec Binary files /dev/null and b/Day8/CollectionDemo/bin/com/demo/test/TestArrayList.class differ diff --git a/Day8/CollectionDemo/bin/com/demo/test/TestEmployeeManagementSystem.class b/Day8/CollectionDemo/bin/com/demo/test/TestEmployeeManagementSystem.class new file mode 100644 index 0000000..59d662f Binary files /dev/null and b/Day8/CollectionDemo/bin/com/demo/test/TestEmployeeManagementSystem.class differ diff --git a/Day8/CollectionDemo/bin/com/demo/test/TestVector.class b/Day8/CollectionDemo/bin/com/demo/test/TestVector.class new file mode 100644 index 0000000..0bc2b9e Binary files /dev/null and b/Day8/CollectionDemo/bin/com/demo/test/TestVector.class differ diff --git a/Day8/CollectionDemo/src/com/demo/beans/Employee.java b/Day8/CollectionDemo/src/com/demo/beans/Employee.java new file mode 100644 index 0000000..a8d9e51 --- /dev/null +++ b/Day8/CollectionDemo/src/com/demo/beans/Employee.java @@ -0,0 +1,72 @@ +package com.demo.beans; + +import java.time.LocalDate; + +public class Employee { + private int empid; + private String ename; + private double sal; + private LocalDate jdt; + + public Employee() { + super(); + } + + public Employee(int empid) { + super(); + this.empid = empid; +} + + public Employee(int empid, String ename, double sal, LocalDate jdt) { + super(); + this.empid = empid; + this.ename = ename; + this.sal = sal; + this.jdt = jdt; + } + + + @Override + public boolean equals(Object obj) { + System.out.println("in equals method "+this.empid+"----"+((Employee)obj).empid); + return this.empid==((Employee)obj).empid; + } + + public int getEmpid() { + return empid; + } + + public void setEmpid(int empid) { + this.empid = empid; + } + + public String getEname() { + return ename; + } + + public void setEname(String ename) { + this.ename = ename; + } + + public double getSal() { + return sal; + } + + public void setSal(double sal) { + this.sal = sal; + } + + public LocalDate getJdt() { + return jdt; + } + + public void setJdt(LocalDate jdt) { + this.jdt = jdt; + } + + @Override + public String toString() { + return "Employee [empid=" + empid + ", ename=" + ename + ", sal=" + sal + ", jdt=" + jdt + "]"; + } + +} diff --git a/Day8/CollectionDemo/src/com/demo/dao/EmployeeDao.java b/Day8/CollectionDemo/src/com/demo/dao/EmployeeDao.java new file mode 100644 index 0000000..f56ae55 --- /dev/null +++ b/Day8/CollectionDemo/src/com/demo/dao/EmployeeDao.java @@ -0,0 +1,19 @@ +package com.demo.dao; + +import java.util.List; + +import com.demo.beans.Employee; + +public interface EmployeeDao { + + boolean save(Employee e); + + List findAll(); + + Employee findById(int eid); + + boolean removeById(int eid); + + List findByName(String nm); + +} diff --git a/Day8/CollectionDemo/src/com/demo/dao/EmployeeDaoImpl.java b/Day8/CollectionDemo/src/com/demo/dao/EmployeeDaoImpl.java new file mode 100644 index 0000000..745435a --- /dev/null +++ b/Day8/CollectionDemo/src/com/demo/dao/EmployeeDaoImpl.java @@ -0,0 +1,62 @@ +package com.demo.dao; + +import java.time.LocalDate; +import java.util.ArrayList; +import java.util.List; +import java.util.stream.Collectors; + +import com.demo.beans.Employee; + +public class EmployeeDaoImpl implements EmployeeDao { + static List elist; + static { + elist=new ArrayList<>(); + elist.add(new Employee(100,"Manjiri",45678,LocalDate.of(2024, 11, 12))); + elist.add(new Employee(101,"Gauri",55678,LocalDate.of(2023, 11, 12))); + elist.add(new Employee(103,"Kanchan",35678,LocalDate.of(2020, 11, 12))); + } + @Override + public boolean save(Employee e) { + elist.add(e); + return true; + + } + @Override + public List findAll() { + return elist; + } + @Override + public Employee findById(int eid) { + //indexOf calls equals method internally + //equals method is written in employee class + int pos=elist.indexOf(new Employee(eid)); + if(pos!=-1) { + return elist.get(pos); + } + return null; + } + @Override + public boolean removeById(int eid) { + //remove calls equals method internally + //equals method is written in employee class + return elist.remove(new Employee(eid)); + } + @Override + public List findByName(String nm) { + /*List temp=new ArrayList<>(); + for(Employee e:elist) { + if(e.getEname().equals(nm)) { + temp.add(e); + } + }*/ + List temp= elist.stream() + .filter(emp->emp.getEname().equals(nm)) + .collect(Collectors.toList()); + + if(temp.size()>0) { + return temp; + } + return null; + } + +} diff --git a/Day8/CollectionDemo/src/com/demo/service/EmployeeService.java b/Day8/CollectionDemo/src/com/demo/service/EmployeeService.java new file mode 100644 index 0000000..1090043 --- /dev/null +++ b/Day8/CollectionDemo/src/com/demo/service/EmployeeService.java @@ -0,0 +1,19 @@ +package com.demo.service; + +import java.util.List; + +import com.demo.beans.Employee; + +public interface EmployeeService { + + boolean addNewEmployee(); + + List displayAll(); + + Employee searchById(int eid); + + boolean deleteById(int eid); + + List findByName(String nm); + +} diff --git a/Day8/CollectionDemo/src/com/demo/service/EmployeeServiceImpl.java b/Day8/CollectionDemo/src/com/demo/service/EmployeeServiceImpl.java new file mode 100644 index 0000000..09d2ceb --- /dev/null +++ b/Day8/CollectionDemo/src/com/demo/service/EmployeeServiceImpl.java @@ -0,0 +1,61 @@ +package com.demo.service; + +import java.time.LocalDate; +import java.time.format.DateTimeFormatter; +import java.util.List; +import java.util.Scanner; + +import com.demo.beans.Employee; +import com.demo.dao.EmployeeDao; +import com.demo.dao.EmployeeDaoImpl; + +public class EmployeeServiceImpl implements EmployeeService { + private EmployeeDao edao; + + + public EmployeeServiceImpl() { + edao=new EmployeeDaoImpl(); + } + + + @Override + public boolean addNewEmployee() { + Scanner sc=new Scanner(System.in); + System.out.println("enter id"); + int empid=sc.nextInt(); + System.out.println("Enter name"); + String nm=sc.next(); + System.out.println("enetr salary"); + double sal=sc.nextDouble(); + System.out.println("entr joining date (dd/mm/yyyy)"); + String dt=sc.next(); + LocalDate ldt=LocalDate.parse(dt,DateTimeFormatter.ofPattern("dd/MM/yyyy")); + Employee e=new Employee(empid,nm,sal,ldt); + return edao.save(e); + } + + + @Override + public List displayAll() { + return edao.findAll(); + } + + + @Override + public Employee searchById(int eid) { + return edao.findById(eid); + } + + + @Override + public boolean deleteById(int eid) { + return edao.removeById(eid); + } + + + @Override + public List findByName(String nm) { + return edao.findByName(nm); + } + +} diff --git a/Day8/CollectionDemo/src/com/demo/test/TestArrayList.java b/Day8/CollectionDemo/src/com/demo/test/TestArrayList.java new file mode 100644 index 0000000..1cb2231 --- /dev/null +++ b/Day8/CollectionDemo/src/com/demo/test/TestArrayList.java @@ -0,0 +1,58 @@ +package com.demo.test; + +import java.time.LocalDate; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; +import java.util.ListIterator; +import java.util.Optional; + +import com.demo.beans.Employee; + +public class TestArrayList { + + public static void main(String[] args) { + List elist=new ArrayList<>(); //by default capacity is 10 + elist.add(new Employee(12,"Rajesh",45678,LocalDate.of(2025,02,10))); + elist.add(new Employee(13,"Rashmi",56678,LocalDate.of(2025,07,10))); + elist.add(new Employee(12,"Amit",35678,LocalDate.of(2025,03,10))); + for(int i=0;i it=elist.iterator(); + while(it.hasNext()) { + Employee e=it.next(); + System.out.println(e); + } + + //it is bidirectional iterator + ListIterator it1=elist.listIterator(); + + //1.8 + elist.forEach(System.out::println); + //search by id + int id=13; + Optional op=elist.stream().filter(emp->emp.getEmpid()==id).findFirst(); + if(op.isPresent()) { + System.out.println(op.get()); + }else { + System.out.println("Not found"); + } + + + + + + + + + + + } + +} diff --git a/Day8/CollectionDemo/src/com/demo/test/TestEmployeeManagementSystem.java b/Day8/CollectionDemo/src/com/demo/test/TestEmployeeManagementSystem.java new file mode 100644 index 0000000..84531f7 --- /dev/null +++ b/Day8/CollectionDemo/src/com/demo/test/TestEmployeeManagementSystem.java @@ -0,0 +1,78 @@ +package com.demo.test; + +import java.util.List; +import java.util.Scanner; + +import com.demo.beans.Employee; +import com.demo.service.EmployeeService; +import com.demo.service.EmployeeServiceImpl; + +public class TestEmployeeManagementSystem { + + public static void main(String[] args) { + Scanner sc=new Scanner(System.in); + EmployeeService eservice=new EmployeeServiceImpl(); + int choice=0; + do { + System.out.println("1. add new employee\n 2. display all\n3. search by id"); + System.out.println("4. Search by name\n 5. update sal\n6. delete by id\n7. delete by salary\n"); + System.out.println("8. search by salary \n 9. sort by salary\n10. exit\n choice: "); + choice=sc.nextInt(); + + switch(choice) { + case 1->{ + boolean status=eservice.addNewEmployee(); + if(status) { + System.out.println("added successfully"); + }else { + System.out.println("not found"); + } + } + case 2->{ + List elist=eservice.displayAll(); + //display data + elist.forEach(System.out::println); + } + case 3->{ + System.out.println("enetr id for search"); + int eid=sc.nextInt(); + Employee e=eservice.searchById(eid); + if(e!=null) { + System.out.println(e); + }else { + System.out.println("not found"); + } + } + case 4->{ + System.out.println("enetr name for searching"); + String nm=sc.next(); + List elst=eservice.findByName(nm); + if(elst!=null) { + elst.forEach(System.out::println); + }else{ + System.out.println("not found"); + } + } + case 6->{ + System.out.println("enetr id for delete"); + int eid=sc.nextInt(); + boolean status=eservice.deleteById(eid); + if(status) { + System.out.println("deleted successfully"); + }else { + System.out.println("not found"); + } + } + case 10->{sc.close(); + System.out.println("Thank ypu for visiting...."); + } + default->{ + System.out.println("wrong choice"); + } + } + + }while(choice!=10); + + } + +} diff --git a/Day8/CollectionDemo/src/com/demo/test/TestVector.java b/Day8/CollectionDemo/src/com/demo/test/TestVector.java new file mode 100644 index 0000000..1efd3e4 --- /dev/null +++ b/Day8/CollectionDemo/src/com/demo/test/TestVector.java @@ -0,0 +1,33 @@ +package com.demo.test; + +import java.util.Vector; + +public class TestVector { + + public static void main(String[] args) { + Vector v=new Vector<>(); + v.add(12); + v.add(13); + v.add(13); + System.out.println(v); + System.out.println("Capacity : "+v.capacity()); + System.out.println("Size : "+v.size()); + for(int i=0;i<10;i++) { + v.add(i+20); + } + System.out.println(v); + System.out.println("Capacity : "+v.capacity()); + System.out.println("Size : "+v.size()); + for(int i=0;i<10;i++) { + v.add(i+20); + } + System.out.println(v); + System.out.println("Capacity : "+v.capacity()); + System.out.println("Size : "+v.size()); + v.remove(new Integer(13)); + System.out.println(v); + System.out.println("Capacity : "+v.capacity()); + System.out.println("Size : "+v.size()); + } + +} diff --git a/Day8/StringDemo/bin/com/demo/test/StringFunctionTest.class b/Day8/StringDemo/bin/com/demo/test/StringFunctionTest.class new file mode 100644 index 0000000..99d3207 Binary files /dev/null and b/Day8/StringDemo/bin/com/demo/test/StringFunctionTest.class differ diff --git a/Day8/StringDemo/bin/com/demo/test/TestStringData.class b/Day8/StringDemo/bin/com/demo/test/TestStringData.class new file mode 100644 index 0000000..8f1cb06 Binary files /dev/null and b/Day8/StringDemo/bin/com/demo/test/TestStringData.class differ diff --git a/Day8/StringDemo/src/com/demo/test/StringFunctionTest.java b/Day8/StringDemo/src/com/demo/test/StringFunctionTest.java new file mode 100644 index 0000000..d6992a6 --- /dev/null +++ b/Day8/StringDemo/src/com/demo/test/StringFunctionTest.java @@ -0,0 +1,30 @@ +package com.demo.test; + +import java.util.stream.Stream; + +public class StringFunctionTest { + + public static void main(String[] args) { + String str="rain in SPAIN in plain"; + System.out.println("matches:"+str.matches(".*a.*n.*")); + String s1="Happy Life"; + System.out.println("matches with :"+s1.matches(".*fe$")); + + boolean r = str.isBlank(); + System.out.println(r); + str = ""; + r = str.isBlank(); + System.out.println(r); + str = "testing \n is a \r technical \n portal"; + + Stream lines = str.lines(); + //lines.forEach(ln->System.out.println(ln)); + lines.forEach(System.out::println); + String str1=" hello "; + + System.out.println("using strip "+str1.strip()); + System.out.println("using stripleading "+str1.stripLeading()); + System.out.println("using stripTrailing "+str1.stripTrailing()); + } + +} diff --git a/Day8/StringDemo/src/com/demo/test/TestStringData.java b/Day8/StringDemo/src/com/demo/test/TestStringData.java new file mode 100644 index 0000000..88698ce --- /dev/null +++ b/Day8/StringDemo/src/com/demo/test/TestStringData.java @@ -0,0 +1,32 @@ +package com.demo.test; + +public class TestStringData { + + public static void main(String[] args) { + String s1="Test"; + String s2="Test"; + String s3=s2; + String s4=new String("Test"); + System.out.println(" s2 == s3 "+(s2==s3)); //true + System.out.println(" s2 == s4 "+(s2==s4)); //false + System.out.println(" s2 .equals(s4) "+(s2.equals(s4))); //true + s1="welcome"; + System.out.println(" s2 == s1 "+(s2==s1)); //false + + //all the methods are synchronized, so they are thread safe + //useful in multithreaded program + StringBuffer sbf=new StringBuffer("Hello"); + System.out.println(sbf.append(" Everyone")); //Hello Everyone + + //useful in single threaded program, It is not thread safe + StringBuilder sbd=new StringBuilder("test"); + System.out.println(sbd.append(" data")); //test data + + String s6="xxx,yyy,zzz-rrrr"; + String[] arr=s6.split(","); + String str=String.join(":",arr); + System.out.println(str); + + } + +} diff --git a/Day8/day 8 notes.pdf b/Day8/day 8 notes.pdf new file mode 100644 index 0000000..27492c0 Binary files /dev/null and b/Day8/day 8 notes.pdf differ diff --git a/Day9/CollectionDemo/bin/com/demo/beans/Employee.class b/Day9/CollectionDemo/bin/com/demo/beans/Employee.class new file mode 100644 index 0000000..d78c38b Binary files /dev/null and b/Day9/CollectionDemo/bin/com/demo/beans/Employee.class differ diff --git a/Day9/CollectionDemo/bin/com/demo/comparators/MyIdComparator.class b/Day9/CollectionDemo/bin/com/demo/comparators/MyIdComparator.class new file mode 100644 index 0000000..4da41ec Binary files /dev/null and b/Day9/CollectionDemo/bin/com/demo/comparators/MyIdComparator.class differ diff --git a/Day9/CollectionDemo/bin/com/demo/comparators/MyNameComparator.class b/Day9/CollectionDemo/bin/com/demo/comparators/MyNameComparator.class new file mode 100644 index 0000000..84d476d Binary files /dev/null and b/Day9/CollectionDemo/bin/com/demo/comparators/MyNameComparator.class differ diff --git a/Day9/CollectionDemo/bin/com/demo/dao/EmployeeDao.class b/Day9/CollectionDemo/bin/com/demo/dao/EmployeeDao.class new file mode 100644 index 0000000..de7a000 Binary files /dev/null and b/Day9/CollectionDemo/bin/com/demo/dao/EmployeeDao.class differ diff --git a/Day9/CollectionDemo/bin/com/demo/dao/EmployeeDaoImpl.class b/Day9/CollectionDemo/bin/com/demo/dao/EmployeeDaoImpl.class new file mode 100644 index 0000000..fc18b65 Binary files /dev/null and b/Day9/CollectionDemo/bin/com/demo/dao/EmployeeDaoImpl.class differ diff --git a/Day9/CollectionDemo/bin/com/demo/service/EmployeeService.class b/Day9/CollectionDemo/bin/com/demo/service/EmployeeService.class new file mode 100644 index 0000000..e9baf1d Binary files /dev/null and b/Day9/CollectionDemo/bin/com/demo/service/EmployeeService.class differ diff --git a/Day9/CollectionDemo/bin/com/demo/service/EmployeeServiceImpl.class b/Day9/CollectionDemo/bin/com/demo/service/EmployeeServiceImpl.class new file mode 100644 index 0000000..e067891 Binary files /dev/null and b/Day9/CollectionDemo/bin/com/demo/service/EmployeeServiceImpl.class differ diff --git a/Day9/CollectionDemo/bin/com/demo/test/TestArrayList.class b/Day9/CollectionDemo/bin/com/demo/test/TestArrayList.class new file mode 100644 index 0000000..5b9deec Binary files /dev/null and b/Day9/CollectionDemo/bin/com/demo/test/TestArrayList.class differ diff --git a/Day9/CollectionDemo/bin/com/demo/test/TestEmployeeManagementSystem.class b/Day9/CollectionDemo/bin/com/demo/test/TestEmployeeManagementSystem.class new file mode 100644 index 0000000..2feee88 Binary files /dev/null and b/Day9/CollectionDemo/bin/com/demo/test/TestEmployeeManagementSystem.class differ diff --git a/Day9/CollectionDemo/bin/com/demo/test/TestVector.class b/Day9/CollectionDemo/bin/com/demo/test/TestVector.class new file mode 100644 index 0000000..0bc2b9e Binary files /dev/null and b/Day9/CollectionDemo/bin/com/demo/test/TestVector.class differ diff --git a/Day9/CollectionDemo/src/com/demo/beans/Employee.java b/Day9/CollectionDemo/src/com/demo/beans/Employee.java new file mode 100644 index 0000000..43433ec --- /dev/null +++ b/Day9/CollectionDemo/src/com/demo/beans/Employee.java @@ -0,0 +1,88 @@ +package com.demo.beans; + +import java.time.LocalDate; + +public class Employee implements Comparable { + private int empid; + private String ename; + private double sal; + private LocalDate jdt; + + public Employee() { + super(); + } + + public Employee(int empid) { + super(); + this.empid = empid; +} + + public Employee(int empid, String ename, double sal, LocalDate jdt) { + super(); + this.empid = empid; + this.ename = ename; + this.sal = sal; + this.jdt = jdt; + } + + + @Override + public boolean equals(Object obj) { + System.out.println("in equals method "+this.empid+"----"+((Employee)obj).empid); + return this.empid==((Employee)obj).empid; + } + + + public int getEmpid() { + return empid; + } + + public void setEmpid(int empid) { + this.empid = empid; + } + + public String getEname() { + return ename; + } + + public void setEname(String ename) { + this.ename = ename; + } + + public double getSal() { + return sal; + } + + public void setSal(double sal) { + this.sal = sal; + } + + public LocalDate getJdt() { + return jdt; + } + + public void setJdt(LocalDate jdt) { + this.jdt = jdt; + } + + @Override + public String toString() { + return "Employee [empid=" + empid + ", ename=" + ename + ", sal=" + sal + ", jdt=" + jdt + "]"; + } + + @Override + public int compareTo(Employee ob) { + System.out.println("in compareTo method "+this.empid+"----"+ob.empid); + System.out.println("Salary---> "+this.sal+"----"+ob.sal); + /*if(this.sal { + + @Override + public int compare(Employee o1, Employee o2) { + /*if(o1.getEmpid() { + + @Override + public int compare(Employee o1, Employee o2) { + System.out.println("in nameComparator compare method"); + System.out.println("Names: "+o1.getEname()+"-----"+o2.getEname()); + return o1.getEname().compareTo(o2.getEname()); + } + +} diff --git a/Day9/CollectionDemo/src/com/demo/dao/EmployeeDao.java b/Day9/CollectionDemo/src/com/demo/dao/EmployeeDao.java new file mode 100644 index 0000000..d3e7f0c --- /dev/null +++ b/Day9/CollectionDemo/src/com/demo/dao/EmployeeDao.java @@ -0,0 +1,31 @@ +package com.demo.dao; + +import java.util.List; + +import com.demo.beans.Employee; + +public interface EmployeeDao { + + boolean save(Employee e); + + List findAll(); + + Employee findById(int eid); + + boolean removeById(int eid); + + List findByName(String nm); + + boolean modifyById(int eid, double sal); + + boolean removeBySalary(double sal); + + List findBySal(double sal); + + List sortBySal(); + + List sortByName(); + + List sortById(); + +} diff --git a/Day9/CollectionDemo/src/com/demo/dao/EmployeeDaoImpl.java b/Day9/CollectionDemo/src/com/demo/dao/EmployeeDaoImpl.java new file mode 100644 index 0000000..230b292 --- /dev/null +++ b/Day9/CollectionDemo/src/com/demo/dao/EmployeeDaoImpl.java @@ -0,0 +1,129 @@ +package com.demo.dao; + +import java.time.LocalDate; +import java.util.ArrayList; +import java.util.Comparator; +import java.util.List; +import java.util.stream.Collectors; + +import com.demo.beans.Employee; +import com.demo.comparators.MyNameComparator; + +public class EmployeeDaoImpl implements EmployeeDao { + static List elist; + static { + elist=new ArrayList<>(); + elist.add(new Employee(100,"Manjiri",45678,LocalDate.of(2024, 11, 12))); + elist.add(new Employee(101,"Gauri",55678,LocalDate.of(2023, 11, 12))); + elist.add(new Employee(103,"Kanchan",35678,LocalDate.of(2020, 11, 12))); + } + @Override + public boolean save(Employee e) { + elist.add(e); + return true; + + } + @Override + public List findAll() { + return elist; + } + @Override + public Employee findById(int eid) { + //indexOf calls equals method internally + //equals method is written in employee class + int pos=elist.indexOf(new Employee(eid)); + if(pos!=-1) { + return elist.get(pos); + } + return null; + } + @Override + public boolean removeById(int eid) { + //remove calls equals method internally + //equals method is written in employee class + return elist.remove(new Employee(eid)); + } + @Override + public List findByName(String nm) { + /*List temp=new ArrayList<>(); + for(Employee e:elist) { + if(e.getEname().equals(nm)) { + temp.add(e); + } + }*/ + List temp= elist.stream() + .filter(emp->emp.getEname().equals(nm)) + .collect(Collectors.toList()); + + if(temp.size()>0) { + return temp; + } + return null; + } + @Override + public boolean modifyById(int eid, double sal) { + int pos=elist.indexOf(new Employee(eid)); + if(pos!=-1) { + Employee e= elist.get(pos); + e.setSal(sal); + return true; + } + return false; + } + @Override + public boolean removeBySalary(double sal) { + + return elist.removeIf(emp->emp.getSal()>sal); + + } + @Override + public List findBySal(double sal) { + List lst= elist.stream() + .filter(emp->emp.getSal()==sal) + .collect(Collectors.toList()); + if (lst.size()>0) { + return lst; + } + return null; + } + @Override + public List sortBySal() { + List lst=new ArrayList<>(); + for(Employee e:elist) { + lst.add(e); + } + lst.sort(null); + return lst; + } + @Override + public List sortByName() { + List lst=new ArrayList<>(); + for(Employee e:elist) { + lst.add(e); + } + //lst.sort(new MyNameComparator()); + Comparator c=(o1,o2)->{ + System.out.println("In functional comparator"); + return o1.getEname().compareTo(o2.getEname()); + }; + lst.sort(c); + return lst; + } + + @Override + @Override + public List sortById() { + List lst=new ArrayList<>(); + for(Employee e:elist) { + lst.add(e); + } + //lst.sort(new MyNameComparator()); + Comparator c=(o1,o2)->{ + System.out.println("In functional comparator"); + return o1.getEname().compareTo(o2.getEname()); + }; + lst.sort(c); + return lst; + } + +} diff --git a/Day9/CollectionDemo/src/com/demo/service/EmployeeService.java b/Day9/CollectionDemo/src/com/demo/service/EmployeeService.java new file mode 100644 index 0000000..3ff04d1 --- /dev/null +++ b/Day9/CollectionDemo/src/com/demo/service/EmployeeService.java @@ -0,0 +1,29 @@ +package com.demo.service; + +import java.util.List; + +import com.demo.beans.Employee; + +public interface EmployeeService { + + boolean addNewEmployee(); + + List displayAll(); + + Employee searchById(int eid); + + boolean deleteById(int eid); + + List findByName(String nm); + + boolean updateById(int eid, double sal); + + boolean deleteBySalary(double sal); + + List searchBySal(double sal); + + List sortBySal(); + + List sortByName(); + +} diff --git a/Day9/CollectionDemo/src/com/demo/service/EmployeeServiceImpl.java b/Day9/CollectionDemo/src/com/demo/service/EmployeeServiceImpl.java new file mode 100644 index 0000000..cd4a0cc --- /dev/null +++ b/Day9/CollectionDemo/src/com/demo/service/EmployeeServiceImpl.java @@ -0,0 +1,94 @@ +package com.demo.service; + +import java.time.LocalDate; +import java.time.format.DateTimeFormatter; +import java.util.List; +import java.util.Scanner; + +import com.demo.beans.Employee; +import com.demo.dao.EmployeeDao; +import com.demo.dao.EmployeeDaoImpl; + +public class EmployeeServiceImpl implements EmployeeService { + private EmployeeDao edao; + + + public EmployeeServiceImpl() { + edao=new EmployeeDaoImpl(); + } + + + @Override + public boolean addNewEmployee() { + Scanner sc=new Scanner(System.in); + System.out.println("enter id"); + int empid=sc.nextInt(); + System.out.println("Enter name"); + String nm=sc.next(); + System.out.println("enetr salary"); + double sal=sc.nextDouble(); + System.out.println("entr joining date (dd/mm/yyyy)"); + String dt=sc.next(); + LocalDate ldt=LocalDate.parse(dt,DateTimeFormatter.ofPattern("dd/MM/yyyy")); + Employee e=new Employee(empid,nm,sal,ldt); + return edao.save(e); + } + + + @Override + public List displayAll() { + return edao.findAll(); + } + + + @Override + public Employee searchById(int eid) { + return edao.findById(eid); + } + + + @Override + public boolean deleteById(int eid) { + return edao.removeById(eid); + } + + + @Override + public List findByName(String nm) { + return edao.findByName(nm); + } + + + @Override + public boolean updateById(int eid, double sal) { + return edao.modifyById(eid,sal); + + } + + + @Override + public boolean deleteBySalary(double sal) { + return edao.removeBySalary(sal); + + } + + + @Override + public List searchBySal(double sal) { + + return edao.findBySal(sal); + } + + + @Override + public List sortBySal() { + return edao.sortBySal(); + } + + + @Override + public List sortByName() { + return edao.sortByName(); + } + +} diff --git a/Day9/CollectionDemo/src/com/demo/test/TestArrayList.java b/Day9/CollectionDemo/src/com/demo/test/TestArrayList.java new file mode 100644 index 0000000..1cb2231 --- /dev/null +++ b/Day9/CollectionDemo/src/com/demo/test/TestArrayList.java @@ -0,0 +1,58 @@ +package com.demo.test; + +import java.time.LocalDate; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; +import java.util.ListIterator; +import java.util.Optional; + +import com.demo.beans.Employee; + +public class TestArrayList { + + public static void main(String[] args) { + List elist=new ArrayList<>(); //by default capacity is 10 + elist.add(new Employee(12,"Rajesh",45678,LocalDate.of(2025,02,10))); + elist.add(new Employee(13,"Rashmi",56678,LocalDate.of(2025,07,10))); + elist.add(new Employee(12,"Amit",35678,LocalDate.of(2025,03,10))); + for(int i=0;i it=elist.iterator(); + while(it.hasNext()) { + Employee e=it.next(); + System.out.println(e); + } + + //it is bidirectional iterator + ListIterator it1=elist.listIterator(); + + //1.8 + elist.forEach(System.out::println); + //search by id + int id=13; + Optional op=elist.stream().filter(emp->emp.getEmpid()==id).findFirst(); + if(op.isPresent()) { + System.out.println(op.get()); + }else { + System.out.println("Not found"); + } + + + + + + + + + + + } + +} diff --git a/Day9/CollectionDemo/src/com/demo/test/TestEmployeeManagementSystem.java b/Day9/CollectionDemo/src/com/demo/test/TestEmployeeManagementSystem.java new file mode 100644 index 0000000..246116d --- /dev/null +++ b/Day9/CollectionDemo/src/com/demo/test/TestEmployeeManagementSystem.java @@ -0,0 +1,130 @@ +package com.demo.test; + +import java.util.List; +import java.util.Scanner; + +import com.demo.beans.Employee; +import com.demo.service.EmployeeService; +import com.demo.service.EmployeeServiceImpl; + + + +public class TestEmployeeManagementSystem { + + public static void main(String[] args) { + Scanner sc=new Scanner(System.in); + EmployeeService eservice=new EmployeeServiceImpl(); + int choice=0; + do { + System.out.println("1. add new employee\n 2. display all\n3. search by id"); + System.out.println("4. Search by name\n 5. update sal\n6. delete by id\n7. delete by salary\n"); + System.out.println("8. search by salary \n 9. sort by salary\n10. Sort By name\n11. exit\n choice: "); + choice=sc.nextInt(); + + switch(choice) { + case 1->{ + boolean status=eservice.addNewEmployee(); + if(status) { + System.out.println("added successfully"); + }else { + System.out.println("not found"); + } + } + case 2->{ + List elist=eservice.displayAll(); + //display data + elist.forEach(System.out::println); + } + case 3->{ + System.out.println("enetr id for search"); + int eid=sc.nextInt(); + Employee e=eservice.searchById(eid); + if(e!=null) { + System.out.println(e); + }else { + System.out.println("not found"); + } + } + case 4->{ + System.out.println("enetr name for searching"); + String nm=sc.next(); + List elst=eservice.findByName(nm); + if(elst!=null) { + elst.forEach(System.out::println); + }else{ + System.out.println("not found"); + } + } + case 5->{ + System.out.println("enetr id for search"); + int eid=sc.nextInt(); + System.out.println("enetr sal"); + double sal=sc.nextDouble(); + boolean status=eservice.updateById(eid,sal); + { + if(status) { + System.out.println("updated successfully"); + } + else { + System.out.println("Not found"); + } + + } + + } + + case 6->{ + System.out.println("enetr id for delete"); + int eid=sc.nextInt(); + boolean status=eservice.deleteById(eid); + if(status) { + System.out.println("deleted successfully"); + }else { + System.out.println("not found"); + } + } + case 7->{ + System.out.println("Enter salary"); + double sal=sc.nextDouble(); + + boolean status=eservice.deleteBySalary(sal); + if(status) { + System.out.println("deleted successfully"); + }else { + System.out.println("not found"); + } + + } + case 8->{ + System.out.println("Enter salary"); + double sal=sc.nextDouble(); + List elist= eservice.searchBySal(sal); + if(elist!=null) { + elist.forEach(System.out::println); + + } + else { + System.out.println("Not found"); + } + } + case 9->{ + List lst=eservice.sortBySal(); + lst.forEach(System.out::println); + } + case 10->{ + List lst=eservice.sortByName(); + lst.forEach(System.out::println); + } + case 11->{sc.close(); + System.out.println("Thank ypu for visiting...."); + } + default->{ + System.out.println("wrong choice"); + } + } + + }while(choice!=11); + + } + +} diff --git a/Day9/CollectionDemo/src/com/demo/test/TestVector.java b/Day9/CollectionDemo/src/com/demo/test/TestVector.java new file mode 100644 index 0000000..1efd3e4 --- /dev/null +++ b/Day9/CollectionDemo/src/com/demo/test/TestVector.java @@ -0,0 +1,33 @@ +package com.demo.test; + +import java.util.Vector; + +public class TestVector { + + public static void main(String[] args) { + Vector v=new Vector<>(); + v.add(12); + v.add(13); + v.add(13); + System.out.println(v); + System.out.println("Capacity : "+v.capacity()); + System.out.println("Size : "+v.size()); + for(int i=0;i<10;i++) { + v.add(i+20); + } + System.out.println(v); + System.out.println("Capacity : "+v.capacity()); + System.out.println("Size : "+v.size()); + for(int i=0;i<10;i++) { + v.add(i+20); + } + System.out.println(v); + System.out.println("Capacity : "+v.capacity()); + System.out.println("Size : "+v.size()); + v.remove(new Integer(13)); + System.out.println(v); + System.out.println("Capacity : "+v.capacity()); + System.out.println("Size : "+v.size()); + } + +}