Question
Assignment 6: ShoppingCart In this programming assignment, the goal is to create a smart shopping cart . Think of the self-checkout option in many stores
Assignment 6: ShoppingCart
In this programming assignment, the goal is to create a smart shopping cart. Think of the self-checkout option in many stores these days.
Design a ShoppingCart class that contains Items. (Use the item class that you already designed!) This uses composition since there is an array of Item objects inside a ShoppingCart. Several interesting methods are
addItem to insert an item to the cart. This is a void method since it modifies the state of the array in the ShoppingCartobject. There are different ways to implement this method. One was is to have a single parameter that is an already constructedItem. Another way is to have a set of parameters that are the parameters to the constructor of the Item class.
cartTotal computes the total price of the cart. This method returns a double but does not need any parameters since it works with data members of the ShoppingCart object.
cartTaxAmount receives the tax rate and computes the total tax to charge for the items currently in the cart. Only Taxable items should be considered for this calculation. This method also returns a double but does not need any parameters since it works with data members of the ShoppingCart object.
the capacity of a ShoppingCart is fixed at 10 item
Each class should have at least one constructor that receives arguments.
Make data members private and create accessor and mutator methods whenever necessary.
Each class should have a toString method that you use to display the contents of the class.
HERE my ITEM class:
1 public class Item 2 { 3 private String name; 4 private String vendor; 5 private double salePrice; 6 private double costPrice; 7 private double weight; 8 private boolean taxable; 9 10 public Item(String name, double sPrice, double cPrice) //constructor 3 parameters 11 { 12 this.name=name; 13 salePrice=sPrice; 14 costPrice=cPrice; 15 taxable=true; 16 weight=1; 17 } 18 public String getName() //accessors 19 { 20 return name; 21 } 22 public String getVendor() 23 { 24 return vendor; 25 } 26 public double getSalePrice() 27 { 28 return salePrice; 29 } 30 public double getWeight() 31 { 32 return weight; 33 } 34 public boolean isTaxable() 35 { 36 return taxable; 37 } 38 public void setWeight(double weight) //mutator 39 { 40 this.weight=weight; 41 } 42 public void setTaxable(boolean t) 43 { 44 taxable=t; 45 } 46 public void increaseCost() 47 { 48 costPrice++; 49 } 50 public double profit() 51 { 52 return salePrice-costPrice; 53 } 54 public String toString() 55 { 56 return "Item name: "+name+", weight is: "+weight+", sale price: "+salePrice+", cost price is: "+costPrice+", taxable: "+taxable+", vendor is: "+vendor; 57 }}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started