Question
JAVA Object Classes: designing Shopping Cart Shopping Cart , build a checkout system for a shop which sells items (i.e., products say Bread, Milk, and
JAVA
Object Classes: designing Shopping Cart
Shopping Cart , build a checkout system for a shop which sells items (i.e., products say Bread, Milk, and Bananas). A shopping cart that can have multiples. Costs of the products are : Bread - $1, Milk - $0.60 and Banana - $0.40. A system should displays the order total.
The heart of a shopping cart can be represented in three classes: a cart class an order class, and an item class. Item objects are added to an array stored within the cart object.
Object Classes: designing Shopping Cart
Object Classes: designing Shopping Cart
Think first what are the nouns in the specification? (ex: Item) These are likely your Objects or possibly key data in an object
Which responsibilities belong to which nouns? These are likely to become their methods.
What are the relationships between nouns (Objects)? Draw it out that will help you visualize how they are interconnected
Object Classes: designing Shopping Cart
You will find that several Objects have a Has-a relationship An ItemOrder has an Item (one to one relationship) A ShoppingCart has many ItemOrders (one to many relationship)
Object Classes: designing Shopping Cart
Summary Methods with same name, different signatures are overloaded methods An enumeration is a class can have instance variables, constructors, methods A package of class definitions grouped together in same folder, contain a package statement at beginning of each class
Item i double price ItemOrder io 2 int quantity String name 42 "String cheese
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