Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
Binary file added Day 12/EnumDemo/bin/com/demo/beans/Person.class
Binary file not shown.
Binary file added Day 12/EnumDemo/bin/com/demo/enums/Coffee.class
Binary file not shown.
Binary file added Day 12/EnumDemo/bin/com/demo/enums/Gender.class
Binary file not shown.
Binary file not shown.
Binary file not shown.
44 changes: 44 additions & 0 deletions Day 12/EnumDemo/src/com/demo/beans/Person.java
Original file line number Diff line number Diff line change
@@ -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 + "]";
}


}
21 changes: 21 additions & 0 deletions Day 12/EnumDemo/src/com/demo/enums/Coffee.java
Original file line number Diff line number Diff line change
@@ -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;
}


}
6 changes: 6 additions & 0 deletions Day 12/EnumDemo/src/com/demo/enums/Gender.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.demo.enums;

public enum Gender {
male,female;

}
25 changes: 25 additions & 0 deletions Day 12/EnumDemo/src/com/demo/test/TestCoffee.java
Original file line number Diff line number Diff line change
@@ -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());
}
}

}



}
28 changes: 28 additions & 0 deletions Day 12/EnumDemo/src/com/demo/test/TestPerson.java
Original file line number Diff line number Diff line change
@@ -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));

}
}
Binary file added Day 12/Java 8 Features.pdf
Binary file not shown.
Binary file not shown.
13 changes: 13 additions & 0 deletions Day 12/Java8Features/src/com/demo/test/TestClass.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.demo.test;

import java.util.List;

public class TestClass {

public static void main(String[] args) {
List<Integer> lst=List.of(3,2,4,15,26,33,7,4,5);
lst.stream().filter(e->e>10).forEach(System.out::println);

}

}
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
57 changes: 57 additions & 0 deletions Day 12/OrderManagementSystem/src/com/demo/beans/Customer.java
Original file line number Diff line number Diff line change
@@ -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 + "]";
}


}
61 changes: 61 additions & 0 deletions Day 12/OrderManagementSystem/src/com/demo/beans/Item.java
Original file line number Diff line number Diff line change
@@ -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 + "]";
}

}
24 changes: 24 additions & 0 deletions Day 12/OrderManagementSystem/src/com/demo/dao/OrderDao.java
Original file line number Diff line number Diff line change
@@ -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<Item> lst);

Map<Customer, List<Item>> findAll();

Entry<Customer, List<Item>> findById(int cid);

boolean removeById(int cid);

boolean addNewItem(int cid, Item item);

boolean deleteById(int cid, int iid);

}
75 changes: 75 additions & 0 deletions Day 12/OrderManagementSystem/src/com/demo/dao/OrderDaoImpl.java
Original file line number Diff line number Diff line change
@@ -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<Customer,List<Item>> hm;
static {
hm=new HashMap<>();
Customer c1=new Customer(10,"Sushrut","33333");
List<Item> 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<Item> 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<Item> lst) {
if(!hm.containsKey(c)) {
hm.put(c,lst);
return true;
}
return false;
}
@Override
public Map<Customer, List<Item>> findAll() {
return hm;
}
@Override
public Entry<Customer, List<Item>> findById(int cid) {
Set<Map.Entry<Customer,List<Item>>> cset=hm.entrySet();
for(Map.Entry<Customer,List<Item>> e:cset) {
if(e.getKey().getCid()==cid)
return e;
}
return null;

}
@Override
public boolean removeById(int cid) {
List<Item> lst= hm.remove(new Customer(cid));
return lst!=null;
}
@Override
public boolean addNewItem(int cid, Item item) {
List<Item> 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<Item> 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;
}
}
Original file line number Diff line number Diff line change
@@ -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<Customer, List<Item>> displayAll();

Entry<Customer, List<Item>> findByCustomer(int cid);

boolean deleteById(int cid);

boolean addNewItem(int cid, Item item);

boolean removeItemById(int cid, int iid);

}
Loading