CS506 Assignment 1 Solution and Discussion


  • Cyberian's Gold

    Please read the following instructions carefully before solving & submitting assignment:

    Uploading Instructions:
    • You are not allowed to use any IDE tool like NetBeans for this assignment.
    • Use Notepad or Notepad++ for coding and JDK package for Java source code compilation and running.
    • Place all the source code (.java & .class files) in a Zip/RAR file, save with your own Student ID (e.g. bc000000000.zip) and Upload it on VULMS within due date.
    • Your assignment should be in .zip /.rar format. Other file formats will not be accepted.
    • No assignment will be accepted through email.

    Rules for Marking:
    It should be clear that your assignment will not get any credit if:

    o The assignment is submitted after due date.
    o The submitted assignment does not open or file is corrupted.
    o The assignment is fully or partially copied from other student or ditto copy from handouts or Internet; strict disciplinary action will be taken in this case.
    o The assignment is not submitted in .zip /.rar format.

    Note: Do not put any query on MDB regarding this assignment, if you have any query then email at
    Lectures Covered: This assignment covers Lecture # 1-9

    GOOD LUCK

    Problem Statement:
    You are required to write a Java program, named ShoppingCart, for a typical online shopping system. In which a user can add and remove items to the shopping cart. The program will allow the user to proceed with checkout by displaying all items of the shopping cart along with total bill. Further, user will also be fascinated by giving the option of emptying the shopping cart without buying anything. All will be done by using Java basic GUI component i.e. JOptionPane.

    Detailed Description:
    At start, your program should display an Input Dialog (i.e. JOptionPane.showInputDialog) and ask for following options;

    1. Add Item(s) to Cart

    2. Remove an Item from Cart

    3. Go to Checkout

    4. Empty the Cart

    5. Exit the Program
      325a7ed0-6918-478f-b72d-4089fb2951bc-image.png
      Fig. 1: Shopping Cart GUI

    6. Add Item(s) to Cart:

    Each time, user selects this option, s/he will be prompted via two Input Dialogs (i.e. JOptionPane.showInputDialog) for selecting an item from available items list (sample data is given below) and its quantity respectively. If inputs are correct (i.e. found no empty/null value and quantity is between 1 and 10) then selected item and its quantity will be added in the shopping cart by using ArrayList from java.util.* package.

    6d82a223-7546-4d70-8410-4ef52f73bbdb-image.png
    Fig. 2: Adding items in Shopping Cart

    1. Remove an Item from Cart:

    User can remove any item from the shopping cart by using this option; JOptionPane.showInputDialog should be used here. However, if shopping cart is already empty then message “Cart is empty” via JOptionPane.showMessageDialog should be displayed.

    3525bf78-d6b1-410d-b28e-cb85311d5b33-image.png
    Fig. 3: Remove an Item

    1. Go to Checkout:

    The program should first check if shopping cart contains any item; if not, it means no item is added yet so ask user to add a new item first. Otherwise, a Message Dialog (i.e. JOptionPane.showMessageDialog) will be opened, displaying all added items along with their quantity and prices. Furthermore, total number of items and grand total should be provided at bottom as well.
    b50126f2-d0fe-4194-a223-e9868bfc9bad-image.png
    Fig. 4: Go to Checkout
    4. Empty the Cart:

    User can remove all items from the shopping cart at once by using this option; successful deletion message should be displayed by using JOptionPane.showMessageDialog. However, if shopping cart is already empty then appropriate message like "Cart is empty" should be displayed.
    

    5e025e0e-385a-4bc6-88f1-257a4ea8f686-image.png
    Fig. 5: Empty the Cart
    5. Exit the Program:

    Exit option will terminate the program and show the developer information (i.e. Student Id and name) via JOptionPane.showMessageDialog.
    e3379e0d-f3fc-4e50-a9e5-b17939f45ccd-image.png
    Fig. 6: Developer Info
    Required Java Classes:
    For this purpose, you have to create three java classes (i.e. Product, Cart and MainClass). Data members, member functions and other details of these classes are given below;

    Product Class:

    •	id: int
    •	name: String
    •	price: float
    •	quantity: int
    •	Constructors: default, parameterized and copy constructor
    •	Standard Setters: setId(…), setName(…), setPrice(…), setQuantity(…)
    •	Standard Getters getId(), getName(), getPrice(), getQuantity()
    

    Cart Class:

    Cart Class:
    •	cartItems: ArrayList 
    •	Constructors: default, parameterized and copy constructor
    •	Member Functions: addItem(…), removeItem(…), emptyCart(), getItemsList(), getProductIndex(…)
    
    

    Main Class:

    •	myCart: Cart
    •	Constructors: default, parameterized and copy constructor
    •	Member Functions: main(), showGUI(), addItem(), removeItem(), checkOutCart(), removeAll(), developerInfo()
    

    Sample Data:
    d7ec6a16-87e3-4031-a64f-7ca48f75d253-image.png

    Important Things to Implement:

    • For GUI, you have to use JOptionPane.showInputDialog and JOptionPane.showMessageDialog for taking input from user and showing output to user respectively.
    • Use single ArrayList for adding/removing items to/from shopping cart.
    • Need to make sure that exceptions are managed properly throughout the program; especially NullPointerException and NumberFormatException while taking input from user.
    • All images and sample data, given in this document, are just for reference purpose only; you have to provide your own implementations. It is not required to be exactly the same.

    Good Luck


  • Cyberian's Gold


  • Cyberian's Gold



    Recent Topics


  • 1
  • 20
  • 3
  • 5
  • 14
  • 12
  • 1
  • 3
|