Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Question 1 : Building an Online Shopping Cart System Step 1 : Product and Cart Classes 1 . Product Class Design: Create a class called

Question 1: Building an Online Shopping Cart System
Step 1: Product and Cart Classes
1. Product Class Design: Create a class called Product with attributes like name, price, and
quantity. Include a method within the class to calculate the total cost of a specific quantity of
the product, (ex: price*quantity).
2. Cart Class Construction: Develop a class named Cart that initializes an empty list to store
products. Implement methods to add products to the cart, remove products, and compute the
total cost of all items in the cart.
Step 2: Specialized Products and Enhanced Cart Functionality
1. Specialized Product Types:
Use inheritance to inherit Product class (Parent Class) to define specific product types
(child classes) like Books, Clothing, and Electronics.
Each subclass should have its unique attributes/methods relevant to its category.
2. Cart Functionality Expansion:
Enhance the Cart class to manage different product types efficiently.
Implement methods to:
Display cart contents for each product category.
Calculate total costs per category.
Step 3: Payment Handling using Polymorphism and Abstract Class
1. Abstract Payment Class Creation: Establish an abstract class named Payment with an abstract
method process_payment(). Develop subclasses like CreditCardPayment and PayPalPayment,
each featuring its payment processing method.
Note: The Payment class will act as a base for different payment methods (e.g., credit card,
PayPal), ensuring that every payment method class that derives from it must implement the
process_payment() method, ensuring consistency across all payment types.
2. Modifying the Cart Class for Payment Handling:
Supporting Various Payment Methods: Modify the Cart class to incorporate multiple payment
methods by utilizing polymorphism. Polymorphism allows different classes (in this case,
payment methods) to be treated as instances of the same base class (Payment).
Implementing process_payment(payment_method): Within the Cart class, create a method
named process_payment(payment_method). This method will handle payments based on the
chosen payment method passed as an argument.
Polymorphic Behavior: The process_payment() method in the Cart class will use polymorphism
to interact with different payment methods. It will accept a payment_method parameter, which
could be an instance of any class that extends the Payment abstract class (e.g.,
CreditCardPayment, PayPalPayment).
Step 4: Advanced Features, Security Measures, and Control
1. Secure Data Access: Implement getter-setter methods within classes to regulate access to
sensitive product or payment information. Enforce security measures within the system to
prevent unauthorized access to specific functionalities.
After implement the above classes, please solve the below questions:
Assignment Questions:
1. Describe the inheritance hierarchy within the shopping cart system. Please provide an
example of a specialized product class derived from the base Product class and elucidate how
it extends the functionality of the base class.
2. Explain the role of polymorphism in handling payments within the shopping cart system.
Illustrate how different payment methods are accommodated within the Cart class using
polymorphic behavior.
3. Demonstrate the usage of getter-setter methods for controlling access to sensitive
information in the implemented system. Provide examples showcasing how these methods
contribute to data security within the shopping cart context.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Professional Android 4 Application Development

Authors: Reto Meier

3rd Edition

1118223853, 9781118223857

More Books

Students also viewed these Programming questions

Question

1.what is rule of law? 2.The administrative body of government?

Answered: 1 week ago

Question

Write a short note on - JUDICIARY

Answered: 1 week ago