diff --git a/Practical_exam_Akanksha_Shrivastava_WFS4/src/com/exam/bean/Apparel.java b/Practical_exam_Akanksha_Shrivastava_WFS4/src/com/exam/bean/Apparel.java new file mode 100644 index 00000000..b399993d --- /dev/null +++ b/Practical_exam_Akanksha_Shrivastava_WFS4/src/com/exam/bean/Apparel.java @@ -0,0 +1,48 @@ +// Author : Akanksha Shrivastava +// Purpose : Apparel entity class that is a child of product and lists details of apparel items. + +package com.exam.bean; + +public class Apparel extends Product { + + //data members + private String size; + private String material; + + //default constructor + public Apparel() { + super(); + size = null; + material = null; + } + + //parameterized constructor + public Apparel(String size, String material) { + super(); + this.size = size; + this.material = material; + } + + //setter and getter methods + public String getSize() { + return size; + } + + public void setSize(String size) { + this.size = size; + } + + public String getMaterial() { + return material; + } + + public void setMaterial(String material) { + this.material = material; + } + + // Overriding toString method + @Override + public String toString() { + return super.toString() +"Apparel [size=" + size + ", material=" + material + ", toString()=" + "]"; + } +} diff --git a/Practical_exam_Akanksha_Shrivastava_WFS4/src/com/exam/bean/Electronics.java b/Practical_exam_Akanksha_Shrivastava_WFS4/src/com/exam/bean/Electronics.java new file mode 100644 index 00000000..6a59f2cc --- /dev/null +++ b/Practical_exam_Akanksha_Shrivastava_WFS4/src/com/exam/bean/Electronics.java @@ -0,0 +1,36 @@ +// Author : Akanksha Shrivastava +// Purpose : Electronics entity class that inherits Product class and contains details about electronic items. + +package com.exam.bean; + +public class Electronics extends Product { + + //data memebers + private int warranty; + + //default constructor + public Electronics() { + warranty = 0; + } + + //parameterized constructor + public Electronics(int warranty) { + super(); + this.warranty = warranty; + } + + //setter and getter methods + public int getWarranty() { + return warranty; + } + + public void setWarranty(int warranty) { + this.warranty = warranty; + } + + //Overriding toString method + @Override + public String toString() { + return super.toString()+"Electronics [warranty=" + warranty + "]"; + } +} diff --git a/Practical_exam_Akanksha_Shrivastava_WFS4/src/com/exam/bean/FoodItem.java b/Practical_exam_Akanksha_Shrivastava_WFS4/src/com/exam/bean/FoodItem.java new file mode 100644 index 00000000..dc5ea25c --- /dev/null +++ b/Practical_exam_Akanksha_Shrivastava_WFS4/src/com/exam/bean/FoodItem.java @@ -0,0 +1,56 @@ +// Author : Akanksha Shrivastava +// Purpose : FoodItem entity class which is a child of Product class and stores details of food items. + +package com.exam.bean; + +import java.util.Date; + +public class FoodItem extends Product { + + //data members + private Date dateOfManufacture; + private Date dateOfExpiry; + private String vegetarian; + + //default constructor + public FoodItem() { + super(); + dateOfManufacture = null; + dateOfExpiry = null; + vegetarian = null; + } + //parameterized constructor + public FoodItem(Date dateOfManufacture, Date dateOfExpiry, String vegetarian) { + super(); + this.dateOfManufacture = dateOfManufacture; + this.dateOfExpiry = dateOfExpiry; + this.vegetarian = vegetarian; + } + + //setter and getter methods + public Date getDateOfManufacture() { + return dateOfManufacture; + } + public void setDateOfManufacture(Date dateOfManufacture) { + this.dateOfManufacture = dateOfManufacture; + } + public Date getDateOfExpiry() { + return dateOfExpiry; + } + public void setDateOfExpiry(Date dateOfExpiry) { + this.dateOfExpiry = dateOfExpiry; + } + public String getVegetarian() { + return vegetarian; + } + public void setVegetarian(String vegetarian) { + this.vegetarian = vegetarian; + } + + //Overriding toString method + @Override + public String toString() { + return super.toString()+"FoodItem [dateOfManufacture=" + dateOfManufacture + ", dateOfExpiry=" + dateOfExpiry + ", vegetarian=" + + vegetarian + "]"; + } +} diff --git a/Practical_exam_Akanksha_Shrivastava_WFS4/src/com/exam/bean/Product.java b/Practical_exam_Akanksha_Shrivastava_WFS4/src/com/exam/bean/Product.java new file mode 100644 index 00000000..f7bfbe96 --- /dev/null +++ b/Practical_exam_Akanksha_Shrivastava_WFS4/src/com/exam/bean/Product.java @@ -0,0 +1,71 @@ +// Author : Akanksha Shrivastava +// Purpose : abstract Product entity class acting as base class to all kinds of products. + +package com.exam.bean; + +abstract public class Product { + + //data members + private int itemCode; + private String itemName; + private double unitPrice; + private int quantity; + + //default constructor + public Product() { + + itemCode = 0; + itemName = null; + unitPrice = 0.0; + quantity = 0; + } + + //parameterized constructor + public Product(int itemCode, String itemName, double unitPrice, int quantity) { + + this.itemCode = itemCode; + this.itemName = itemName; + this.unitPrice = unitPrice; + this.quantity = quantity; + } + + //setter and getter methods + public int getItemCode() { + return itemCode; + } + + public void setItemCode(int itemCode) { + this.itemCode = itemCode; + } + + public String getItemName() { + return itemName; + } + + public void setItemName(String itemName) { + this.itemName = itemName; + } + + public double getUnitPrice() { + return unitPrice; + } + + public void setUnitPrice(double unitPrice) { + this.unitPrice = unitPrice; + } + + public int getQuantity() { + return quantity; + } + + public void setQuantity(int quantity) { + this.quantity = quantity; + } + + //Overriding toString method from Object class + @Override + public String toString() { + return "Product [itemCode=" + itemCode + ", itemName=" + itemName + ", unitPrice=" + unitPrice + ", quantity=" + + quantity + "]"; + } +} diff --git a/Practical_exam_Akanksha_Shrivastava_WFS4/src/com/exam/dao/ProductDao.java b/Practical_exam_Akanksha_Shrivastava_WFS4/src/com/exam/dao/ProductDao.java new file mode 100644 index 00000000..e3874327 --- /dev/null +++ b/Practical_exam_Akanksha_Shrivastava_WFS4/src/com/exam/dao/ProductDao.java @@ -0,0 +1,17 @@ +//Author : Akanksha Shrivastava +//Purpose : Data Access Interface which lists the methods for addition and retrieval of product data. + +package com.exam.dao; + +import com.exam.bean.Product; +import com.exam.exception.DuplicateIdException; +import com.exam.exception.ItemNotFoundException; + +public interface ProductDao { + + boolean addNewProduct(Product ob);//throws DuplicateIdException; + + void retrieve(Product ob); //throws ItemNotFoundException; + + void report(Product ob); +} diff --git a/Practical_exam_Akanksha_Shrivastava_WFS4/src/com/exam/dao/ProductDaoImpl.java b/Practical_exam_Akanksha_Shrivastava_WFS4/src/com/exam/dao/ProductDaoImpl.java new file mode 100644 index 00000000..4bc0c61b --- /dev/null +++ b/Practical_exam_Akanksha_Shrivastava_WFS4/src/com/exam/dao/ProductDaoImpl.java @@ -0,0 +1,80 @@ +//Author : Akanksha Shrivastava +//Purpose : Implementation of ProductDao interface. + +package com.exam.dao; + +import java.util.ArrayList; +import java.util.List; +import java.util.Set; +import java.util.TreeSet; + +import com.exam.bean.Apparel; +import com.exam.bean.Electronics; +import com.exam.bean.FoodItem; +import com.exam.bean.Product; +import com.exam.exception.DuplicateIdException; +import com.exam.exception.ItemNotFoundException; + +public class ProductDaoImpl implements ProductDao { + + + //creating sets + static Set foodItems; + static Set apparelList; + static Set electronicItems; + + static { + + foodItems = new TreeSet<>(); + apparelList = new TreeSet<>(); + electronicItems = new TreeSet<>(); + } + + @Override + public boolean addNewProduct(Product ob) {//throws DuplicateIdException { + + if(ob instanceof FoodItem) { + foodItems.add((FoodItem)ob); + return true; + } + else if(ob instanceof Apparel) { + apparelList.add((Apparel)ob); + return true; + } + else if(ob instanceof Electronics) { + electronicItems.add((Electronics)ob); + return true; + } + else + return false; + } + + @Override + public void retrieve(Product ob) {//throws ItemNotFoundException { + + if(ob instanceof FoodItem) { + for(FoodItem f:foodItems) { + if(ob.equals(f)) { + ((FoodItem)ob).toString(); + } + } + } + else if(ob instanceof Apparel) { + for(Apparel a:apparelList) { + if(ob.equals(a)) { + ((Apparel)ob).toString(); + } + } + } + else if(ob instanceof Electronics) { + electronicItems.add((Electronics)ob); + } + } + + @Override + public void report(Product ob) { + // TODO Auto-generated method stub + + } + +} diff --git a/Practical_exam_Akanksha_Shrivastava_WFS4/src/com/exam/exception/DuplicateIdException.java b/Practical_exam_Akanksha_Shrivastava_WFS4/src/com/exam/exception/DuplicateIdException.java new file mode 100644 index 00000000..59c41247 --- /dev/null +++ b/Practical_exam_Akanksha_Shrivastava_WFS4/src/com/exam/exception/DuplicateIdException.java @@ -0,0 +1,11 @@ +//Author : Akanksha Shrivastava +//Purpose : A class extending Exception class to handle the case of duplicate ID entered by user. + +package com.exam.exception; + +public class DuplicateIdException extends Exception { + + public DuplicateIdException(String message) { + super(message); + } +} diff --git a/Practical_exam_Akanksha_Shrivastava_WFS4/src/com/exam/exception/ItemNotFoundException.java b/Practical_exam_Akanksha_Shrivastava_WFS4/src/com/exam/exception/ItemNotFoundException.java new file mode 100644 index 00000000..4c18972d --- /dev/null +++ b/Practical_exam_Akanksha_Shrivastava_WFS4/src/com/exam/exception/ItemNotFoundException.java @@ -0,0 +1,12 @@ +//Author : Akanksha Shrivastava +//Purpose : a class extending Exception class to handle the case when requested item is not present. + +package com.exam.exception; + +public class ItemNotFoundException extends Exception { + + public ItemNotFoundException(String message) { + super(message); + } + +} diff --git a/ReadMe.docx b/ReadMe.docx new file mode 100644 index 00000000..a279896d Binary files /dev/null and b/ReadMe.docx differ