You are on page 1of 3

Shopping Cart

Project Objective:
Create a console-based Java application that would allow users to generate Shopping bill based
on the items and quantity of items in the cart for a Start-up company E-Zone

Project Design:
A. System Design: Name of the package Usage
com.wipro.shopbill.entity This package will contain the Shopping bill and
Item classes
com.wipro.shopbill.exception This package will contain the user defined
exception classes
com.wipro.shopbill.service This package will have service class to validate
the data.
com.wipro.shopbill.main This package will contain the MainClass that is
used to test the application

Package: com.wipro.shopbill.exception

Class Method and Variables Description


InvalidItemException An Exception Class
public String toString() Override toString() method
such that it Returns the
message “Invalid Item Data”
InvalidInvalidQuantityExc public String toString() Override toString() method
eption such that it Returns the
message “Invalid Quantity”

Package: com.wipro.shopbill.entity

Class Method and Variables Description


Item
private String itemName itemName must be atleast 5
characters
private double price Must be within the range Rs 5000
to 5,00,000.
private itemType Must be either
Laptop/Mobile/Accessories
private String company
private String placeOfManufacture Must be either India/USA/China
public Item (String itemName,
double price, String itemType, String
company, String
placeOfManufacture)
Getter and setter methods
Package: com.wipro.shopbill.entity

Class Method and Variables Description


Cart
private Item items[]
private int quantity[] Stores the quantity of each item in
the cart. Must ensure that each
item must have a non-zero
quantity and quantity must be
positive value. So, the size of
quantity array and items array
must be same always.
private int cartCapacity No. of items cart can hold
private int itemCount No. of items in cart currently.
private double totalFare
public Cart() Initialize cartCapacity=2.
Instantiates items and quantity
with a size of cartCapacity and
totalFare to 0.0.
private increaseCartCapacity() If the items[] and quantity[] are
full, then double the size of these
arrays.
public addToCart(Item item, int Adds the item to Items[] and
quantity) quantity to quantity[]. Each time an
item is added, the itemCount
increments by one. If the
itemCount is equal to cartCapacity
then call the increaseCartCapacity()
and add the item.
public int computeTotal() Returns the totalFare after
computation. For each item
multiply with its price and quantity.
public void PrintDetails() Must print in the following format:
S.NO ItemName Price Qty
1. Lenovo16 8500 1
2. XXXX 9000 2

Total: Rs 26500
Package : com.wipro.shopbill.service

Class Method and Description


Variables
BillService Class
public boolean validate Validate the Item as per the description
(Item item,int quantity) mentioned above. If invalid data found throw
throws the InvalidItemException
InvalidItemException,
InvalidQuantityExceptio Quantity must be between 1 to 5. In case a
n wrong quantity is given then throw
InvalidQuantityException.

If all inputs are valid then return true.


public double This method calls the validate method to
shop(Item items[], int validate each item and quantity and handles
quantity[]) the exception thrown. In case
InvalidItemException occurs then return
-1.

In case InvalidQuantityException occurs


then return -2.

If no exceptions then call the computeTotal()


method and printDetails. Return the total.

You might also like