Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Practical Exam Actual #32

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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()=" + "]";
}
}
Original file line number Diff line number Diff line change
@@ -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 + "]";
}
}
Original file line number Diff line number Diff line change
@@ -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 + "]";
}
}
Original file line number Diff line number Diff line change
@@ -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 + "]";
}
}
Original file line number Diff line number Diff line change
@@ -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);
}
Original file line number Diff line number Diff line change
@@ -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<FoodItem> foodItems;
static Set<Apparel> apparelList;
static Set<Electronics> 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

}

}
Original file line number Diff line number Diff line change
@@ -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);
}
}
Original file line number Diff line number Diff line change
@@ -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);
}

}
Binary file added ReadMe.docx
Binary file not shown.