Product Browsing : After logging into the site, the customer can see a list of p
ID: 3829425 • Letter: P
Question
Product Browsing: After logging into the site, the customer can see a list of products. Each product listing includes the name of the product, an image, and the price of the object. A user can set a quantity for a product and select to purchase it. If there are enough items in inventory, the entire order will be added to the shopping cart. If not enough to fill the order, the user will be notified to change their order. As items are added to a shopping cart, they should be removed from the inventory in the database. Products can be anything.
Shopping Cart Review: At any time, the customer can click a link to view their shopping cart. The shopping cart view will display a list of products in the cart, the quantity to be purchased, the cost of each to be purchased product, and the total cost. The customer should be able to delete an item from their cart. If an item is deleted from the shopping cart, it should be added back to the product inventory. A customer should be able to resume shopping from the shopping cart view. Additional Use Cases are optional.
Required Features: Your project must include the following components: • Database: You will need to design and create a database to store relevant data. Make sure that your database is robust and follows the database design lessons you have learned during your MIST courses. • Complete set of MVC components for all requests/responses use cases. Validate data on both the client and server side. Make sure that your application “degrades gracefully.” • Use relevant state management objects. General Requirements: Your application should also conform to the following general requirements: • Use standard Java conventions. • Use Java classes in the model as much as possible. • Use JSTL in JSPs when possible.
Explanation / Answer
Answer:
1. Entity class Product for table Product: Product.java
-------------------------------------------
import java.io.Serializable;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
/**
*
* Entity class Product
*/
@Entity (name="Product")
public class Product implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
@Column (name="ProductName")
private String productName;
@Column (name="ProductPrice")
private double productPrice;
public String getProductName() {
return productName;
}
public void setProductName(String productName) {
this.productName = productName;
}
public double getProductPrice() {
return productPrice;
}
public void setProductPrice(double productPrice) {
this.productPrice = productPrice;
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
@Override
public int hashCode() {
int hash = 0;
hash += (id != null ? id.hashCode() : 0);
return hash;
}
@Override
public boolean equals(Object object) {
// TODO: Warning - this method won't work in the case the id fields are not set
if (!(object instanceof Product)) {
return false;
}
Product other = (Product) object;
if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
return false;
}
return true;
}
@Override
public String toString() {
return "productbrowsing.Product[ id=" + id + " ]";
}
}
----------------------------------------------
2. Entiry class Inventory for Inventory table: Inventory.java
------------------------------------------
import java.io.Serializable;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
/**
*
* Entity class Inventory
*/
@Entity (name = "Inventory")
public class Inventory implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
@Column (name = "ProductId")
private Long productId;
@Column (name = "ItemsInStock")
private int itemsInStock;
public int getItemsInStock() {
return itemsInStock;
}
public void setItemsInStock(int itemsInStock) {
this.itemsInStock = itemsInStock;
}
public Long getProductId() {
return productId;
}
public void setProductId(Long productId) {
this.productId = productId;
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
@Override
public int hashCode() {
int hash = 0;
hash += (id != null ? id.hashCode() : 0);
return hash;
}
@Override
public boolean equals(Object object) {
// TODO: Warning - this method won't work in the case the id fields are not set
if (!(object instanceof Inventory)) {
return false;
}
Inventory other = (Inventory) object;
if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
return false;
}
return true;
}
@Override
public String toString() {
return "productbrowsing.Inventory[ id=" + id + " ]";
}
}
--------------------------------------------------
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.