CS506 Assignment No 02 Fall 2020 Solution / Discussion
Please read the following instructions carefully before solving & submitting assignment:
Uploading Instructions:
Rules for Marking:
It should be clear that your assignment will not get any credit if:
Note: Do not put any query on MDB regarding this assignment, If you face any type of issue while uploading assignment on LMS, then you should mail your assignment along with screen shot of error within due date to cs506@vu.edu.pk.
Lectures Covered: This assignment covers Lecture # 10-17
GOOD LUCK
Problem Statement:
You are required to write a Java program, named BookShop, to purchase online CS506 course’s helping material. In this program a user can add and remove items to the BookShop Cart. The program will calculate the total bill as the items are added or removed from shopping cart and will display the amount via user friendly interface on real time basis. All orders will be saved in MS Access database so that the administrator could process the orders properly.
Detailed Description:
At start, your program will display a GUI (i.e. Graphical User Interface) which should contain options for selecting quantity of products, sample is given in Figure 1.
Fig. 1: BookShop Cart GUI
Here, the customer can select the quantity (i.e. 0 to 10) for available products by clicking on add (+) or remove (–) buttons. Sample is given in Figure 2.
Fig. 2: BookShop Cart GUI
The cart should be updated on each action and correct amount after calculating the number of items, subtotal, shipping charges (shipping charges are given below) and grand total should be displayed. Sample is given in Figure 3.
Fig. 3: BookShop Cart GUI
When user clicks on "Place Order" then the program should check whether the cart contains any item or not. If cart is empty, then a message "Cart is empty!" should be displayed. Sample is given in Figure 4.
Fig. 4: Cart is Empty
Otherwise, order details will be saved to MS Access database file and interface will be updated with initial values (i.e. zero quantity for each item and zero in amount fields etc.) as well. Sample is given in Figure 5.
Fig. 5: Order placed successfully & values got reset
Further, cross icon at top right corner of the interface should terminate the program and show the developer information (i.e. Student Id and name) via message dialog.
Fig. 6: Developer Info
Required Stuff:
Java Classes:
Product.java:
Cart.java
DatabaseHelper.java (should contain all database related code)
fetchProductsData(…)
BSCartGUI.java (Contains GUI Code)
BookShop.java (should contain Main method)
Database file:
BSxxxxxxxx.accdb (must be same as your own VU student id)
Note: Need to put database file in assets folder in NetBeans project directory as shown below.
Fig. 3: Folder "assets" in NetBeans project directory
Sample Data:
# |
Item |
Price (Rs) |
1 |
Handouts |
500.0 |
2 |
Reference Book |
500.0 |
3 |
DVD |
500.0 |
4 |
USB |
2500.0 |
Tab. 1: Sample Products Data
# |
No of Items |
Shipping Charges (Rs) |
1 |
0 |
0 |
2 |
1 to 5 |
50.0 |
3 |
6 to 10 |
100.0 |
4 |
11 to 15 |
150.0 |
5 |
16 to 20 |
200.0 |
6 |
21 to 25 |
250.0 |
7 |
26 to 30 |
300.0 |
8 |
31 to 35 |
350.0 |
9 |
More than 35 |
400.0 |
Tab. 2: Sample Shipping Charges
Tab. 3: Products Table in MS Access Database file
Tab. 4: Orders Table in MS Access Database file
Important Things to Implement:
Tags:
can someone plzzz share the microsoft Access application or download link
the assignent is complete but the asset is not created
#cs506 #2CS506
CS506 Assignment #2 Solution part 1
cs506 assignment no 02 solution fall 2020
Click on the below link to download the file
CS506 Assignment 2 Fall 2020 Solution:
Code:
class Product{
private int id , quantity;
private String name;
private float price;
public Product(){
id = 0;
quantity = 0;
name = "";
price = 0;
}
public Product(String name, int quantity, float price)
{
this.name = name;
this.quantity= quantity;
this.price = price;
}
public Product(Product p)
{
p.id= id;
p.quantity = quantity;
p.name = name;
p.price = price;
}
public int getId()
{
return id;
}
public void setId(int id){
this.id= id;
}
public int getQuantity()
{
return quantity;
}
public void setQuantity(int quantity){
this.quantity = quantity;
}
public String getName(){
return name;
}
public void setName(String name){
this.name = name;
}
public float getPrice(){
return price;
}
public void setPrice(float price){
this.price = price;
}
}
2. Cart.Jav:
import java.util.ArrayList;
import javax.swing.JOptionPane;
//import a class same
class Cart extends Product{
ArrayList<Product> cartItems;
public Cart(){
cartItems = new ArrayList<>();
}
public Cart(String name , int quantity , float price){
super(name, quantity , price);
}
public Cart(Product p){
super(p);
}
public void addItem(){
int op = 0;
String option = JOptionPane.showInputDialog(null, "Please Enter \n \n "
+ "1 to Add 'Handout(Rs 500.0)'\n "
+ "2 to Add 'Reference Book(Rs 500.0)'\n "
+ "3 to Add 'DVD(Rs 500.0)'\n "
+ "4 to Add 'USB(Rs 2500.0)'\n "
+ "5 to Add 'Done'\n "
, "Add Item(s) in Cart"
, JOptionPane.INFORMATION_MESSAGE);
if (option.equals("")){
JOptionPane.showMessageDialog(null, "Please Select an Item" , "Error" , JOptionPane.ERROR_MESSAGE);
addItem();
}
else
{
op = Integer.parseInt(option);
}
int qty = Integer.parseInt(JOptionPane.showInputDialog(null, "Please Enter \n\n "
+ "Please specify the quantity (1- 10) "
, "Quantity"
, JOptionPane.INFORMATION_MESSAGE));
if (op == 1) {
setPrice(500.0f);
setName("Handout");
}
if (op == 2) {
setPrice(500.0f);
setName("Reference Book");
}
if (op == 3) {
setPrice(500.0f);
setName("DVD");
}
if (op == 4) {
setPrice(2500.0f);
setName("USB");
}
setQuantity(qty);
if (getQuantity() > 10 || getQuantity() < 1) {
JOptionPane.showMessageDialog(null, "Quantity must be between 1- 10 ", "Error", JOptionPane.ERROR_MESSAGE);
}
else
{
Product p = new Product(getName(), getQuantity(), getPrice());
cartItems.add(p);
JOptionPane.showMessageDialog(null, "Item Added to Cart");
}
}
public void removeItem(String n){
if (cartItems.isEmpty())
{
JOptionPane.showMessageDialog(null, "Cart is empty");
}
else
{
for (int i=0; i<cartItems.size(); i++ ) {
Product p = (Product)cartItems.get(i);
if (n.equals(p.getName())) {
cartItems.remove(i);
JOptionPane.showMessageDialog(null, "Item Removed");
}
}
}
}
public void emptyCart(){
if (cartItems.isEmpty())
{JOptionPane.showMessageDialog(null , "Cart is empty");}
else
{
cartItems.clear();
JOptionPane.showMessageDialog(null, "All items removed successfuly!");
}
}
public void Checkout(){
String str = "";
int items = 0 ;
int iterator = 1;
float itemPrice, total = 0.0f;
int size = cartItems.size();
if (size < 1) {
JOptionPane.showMessageDialog(null, "Add item(s) first ", "Cart is empty", JOptionPane.ERROR_MESSAGE);
}
else
{
for (Product cartItems : cartItems ) {
Product p = (Product) cartItems;
itemPrice = p.getPrice() * p.getQuantity();
str += iterator + " . "+ p.getName() + ": Rs"+ p.getPrice() + "x" + p.getQuantity()+
"= Rs"+ itemPrice + " \n";
items += p.getQuantity();
total += p.getPrice() * p.getQuantity();
iterator ++;
}
str += " \n \n No. of items : "+ items + "- Totla Bill: Rs "+ total;
JOptionPane.showMessageDialog(null, str, "Go To Checkout", JOptionPane.INFORMATION_MESSAGE);
//please subscribe my channel
}
}
}
3. BookShop. Java:
import javax.swing.JOptionPane;
public class BookShop{
static int ch = 0;
public static void main(String Args[]) {
String s= "";
Cart myCart = new Cart();
while(true){
switch(showGUI())
{
case 1:
myCart.addItem();
break;
case 2:
String op= JOptionPane.showInputDialog(null, "Please Enter \n \n "
+ "1 to Remove 'Handout'\n "
+ "2 to Remove 'Reference Book'\n "
+ "3 to Remove 'DVD'\n "
+ "4 to Remove 'USB'\n "
, "Remove an Item"
, JOptionPane.INFORMATION_MESSAGE);
if (op.equals("1")) {s = "Handout"; }
if (op.equals("2")) {s = "Reference Book"; }
if (op.equals("3")) {s = "DVD"; }
if (op.equals("4")) {s = "USB"; }
myCart.removeItem(s);
break;
case 3:
myCart.Checkout();
break;
case 4:
myCart.emptyCart();
break;
case 5:
developerInfo();
System.exit(0);
}
}
}
//add your id
public static void developerInfo(){
//Enter Student ID
JOptionPane.showMessageDialog(null, "Develper By: Student Name(BCxxxxxx)", "Develper Info",
JOptionPane.INFORMATION_MESSAGE);
};
public static int showGUI(){
String option = JOptionPane.showInputDialog(null, "Please Enter \n \n "
+ "1 For 'Add Item to Cart'\n "
+ "2 For 'Remove an item from cart '\n "
+ "3 For 'Go To Checkout'\n "
+ "4 For 'Empty Cart'\n "
+ "5 For 'Exit Program'\n "
, "BookShop Cart"
, JOptionPane.INFORMATION_MESSAGE);
ch= Integer.parseInt(option);
return ch;
}
}
//so run the program
//So run the program Best of luck
Download attachment for CS506 Assignment 2 solution files.
codes in DOCx format:
CS506-Assignment-02-Solution-File.doc
Zip Files:
everytime i try to upload the assignment it says
Your uploading file extension is not valid!
Your uploading file extension is not valid!
Your uploading file extension is not valid!
madi ali kon si file upload kar rahay ....
zip file extension
........
there are other complains also on MDB
See those screenshots
problem is solved when today i submit it ....
none of the error occur
finally submitted successfully
© 2021 Created by + M.Tariq Malik.
Powered by
Promote Us | Report an Issue | Privacy Policy | Terms of Service
We are user-generated contents site. All product, videos, pictures & others contents on site don't seem to be beneath our Copyrights & belong to their respected owners & freely available on public domains. We believe in Our Policy & do according to them. If Any content is offensive in your Copyrights then please email at m.tariqmalik@gmail.com with copyright detail & We will happy to remove it immediately.
Management: Admins ::: Moderators
Awards Badges List | Moderators Group
All Members | Featured Members | Top Reputation Members | Angels Members | Intellectual Members | Criteria for Selection
Become a Team Member | Safety Guidelines for New | Site FAQ & Rules | Safety Matters | Online Safety | Rules For Blog Post