Please help me with this HW

Overview

For our assignment this week, you will be creating a UML class diagram to model a simulated online shopping system.

The skills you will practice in this assignment include:

  • defining class members using a UML class diagram
  • defining relationships between classes using a UML class diagram
  • practicing correct UML class diagram syntax

Instructions

Create a UML class diagram that includes all of the classes, attributes, and relationships specified below.

Not all details included below are relevant to the UML diagram, and not all required details are provided. If a detail is not provided in the outline below, then you must decide what it should be based on good object-oriented principles. Some details are only provided to give you a better idea of how the whole project fits together.

Your diagram must show the following:

  • All classes listed below
  • All members of each class with their types, return values, and visibility modifiers
  • All relationships (using the correct lines) with multiplicity values and role descriptions

The small details are important! You may lose points if you use the wrong type of arrow for a relationship, point an arrow in the wrong direction, or leave off the access modifier symbol for a variable or method.

You may draw your diagram by hand and submit a picture of it, or you may use any digital drawing software of your choice.

Classes

Product

A class that models the products that are sold in this system.

  • Variables
    • String name – the name of the product.
    • String productID – a numeric identifier for the product. For this simulation you can make up numbers as long as each product has a unique ID.
    • double price – the price of the product.
    • int inStock – how many of this product are in stock.
  • Methods
    • Product(String name, String productID, double price, Supplier supplier, int inStock) – a constructor
    • Product(String name, String productID, double price, Supplier supplier) – a constructor that defaults the amount in stock to 0.
    • String getName() – an accessor for the name attribute
    • String getID() – an accessor for the ID attribute
    • double getPrice() – an accessor for the price attribute
    • int getStock() – an accessor for the stock attribute
    • void setPrice(double newPrice) – sets the new price of the product (minimum of 0)
    • void setStock(int newStock) – sets the new amount of stock of this product (minimum of 0)
    • boolean addStock(int amount) – adds an amount to the existing stock. The parameter can be negative to remove stock instead (minimum of 0). Returns true if the requested change was successful and false if not.
  • Relationships
    • ShoppingCarts can contain up to 100 products. Likewise, products can be placed in any number of shopping carts at any given time. Deleting the shopping cart does not remove the products it contained from the store shelves.
    • Customers purchase any number of products, and products are purchased by any number of customers. Customers don’t directly contain products, so this relationship is one of association.
    • Suppliers contain any number of products in their list of supplied products. In contrast, products must be provided by exactly one supplier, no more and no less. Even if the supplier disappears, any existing products they had on the market remain available.

ShoppingCart

A class that models a virtual shopping cart. Products are added to the shopping cart before purchase.

  • Variables
    • Product[] contents – an array of product objects that have been placed in the cart. A single cart can hold up to 100 products at once.
    • int[] amount – an array that holds the amount of each product that is in the cart. The values in this array are used in parallel with the contents array (i.e. if amount[0] == 4, then this customer is buying 4 of the product at contents[0]).
  • Methods
    • ShoppingCart() – a constructor that makes an empty ShoppingCart.
    • boolean addItem(Product item, int amount) – adds the specified amount of the specified item into the shopping cart. The amount of the product added can’t be higher than what is currently in stock. Returns true if successful and false if there’s not enough stock.
    • boolean removeItem(Product item) – searches through the contents array and removes the specified item. Returns false if it was not found. (You can compare objects in the cart using == since you are comparing their references.)
    • double getTotalPrice() – returns the total price of all items in the cart
    • void clear() – removes all products from the shopping cart.
    • String toString() – returns a String representation of the shopping cart. For each product in the cart, its name and the amount in the cart should be written on one line separated by a comma. Each product appears on a separate line. Any null products are not printed (do not print an empty line or the word null). An empty cart should return an empty String.
  • Relationships
    • ShoppingCarts contain up to 100 products. Products can be placed in any number of shopping carts at any given time.
    • Each customer has exactly one shopping cart. Similarly, each shopping cart belongs to exactly one customer. If the customer’s profile is deleted, their shopping cart is deleted as well.

PaymentInfo

A class that stores information about a customer’s payment information. Only credit and debit cards are accepted in this simulated system. (Please do not enter any real information into this simulation program.)

  • Variables
    • String cardNumber – a credit/debit card number.
    • String name – the name on the credit/debit card.
    • int cvv – the security code on the back of the credit/debit card.
    • String address – the billing address for this payment information.
  • Methods
    • PaymentInfo(String cardNumber, String name, int cvv, String address) – a constructor
    • String getNumber() – an accessor for the cardNumber attribute
    • String getName() – an accessor for the name attribute
    • int getCVV() – an accessor for the cvv attribute
    • String getAddress() – an accessor for the address attribute
    • void setNumber(String newNumber) – a mutator for the cardNumber attribute
    • void setName(String newName) – a mutator for the name attribute
    • void setCVV(int newCVV) – a mutator for the cvv attribute
    • void setAddress(String newAddress) – a mutator for the address attribute
    • static PaymentInfo promptForInfo() – a static method that displays prompts to the console asking the user to enter each part of their payment information. This information is used to construct a new PaymentInfo object, which is returned by the method.
  • Relationships
    • Each set of payment information belongs to exactly one customer. A customer can have at most 1 set of payment information at a time, but they can also have no payment information in the system. If a customer’s profile is deleted, their payment information is deleted as well.

Customer

A class that models a single customer’s account in this shopping system.

  • Variables
    • String email – the customer’s email address
    • String password – the customer’s account password
    • ShoppingCart cart – the customer’s shopping cart
    • PaymentInfo payment – the customer’s payment information
  • Methods
    • Customer(String email, String password) – a constructor. A new empty shopping cart is created for the customer, but the payment variable is left as null.
    • String getEmail() – an accessor for the email attribute
    • void setEmail(String newEmail) – a mutator for the email attribute
    • ShoppingCart getCart() – an accessor for the cart attribute
    • PaymentInfo getPaymentInfo() – an accessor for the payment attribute
    • boolean addItemToCart(Product item, int amount) – adds the specified amount of the item parameter to this customer’s cart.
    • boolean removeItemFromCart(Product item) – removes the specified item from this customer’s cart.
    • void viewCart() – prints all items in this customer’s cart followed by the total price of all items in the cart. If the cart is empty, print a message stating that it is empty instead.
    • void checkout() – purchases all of the items in this customer’s cart. This method must follow these steps in order:
      1. If the customer’s payment information is null, prompt them to enter new information using PaymentInfo.promptForInfo(). If the user already has payment information, skip this step.
      2. For each product in the customer’s shopping cart, remove the amount that they purchased from the stock of each product.
      3. Empty this customer’s shopping cart.
  • Relationships
    • Customers can purchase any number of products, and products can be purchased by any number of customers. Customer objects don’t directly contain Product objects or vice versa.
    • Each customer has exactly one shopping cart. Each shopping cart is unique to each customer’s profile. If the customer’s profile is deleted, their shopping cart is deleted as well.
    • Each set of payment information belongs to exactly one customer. A customer can have at most 1 set of payment information at a time, but they can also have no payment information in the system. If a customer’s profile is deleted, their payment information is deleted as well.

Supplier

A class representing a company that supplies products to this shopping system.

  • Variables
    • String name – the name of this company
    • Product[] products – a list of the products provided by this company
  • Methods
    • Supplier(String name, Product[] products) – a constructor
    • Supplier(String name) – a constructor that defaults the products array to null.
    • public String getName() – an accessor for the name attribute
    • public void setName(String newName) – a mutator for the name attribute
    • public Product[] getProductList() – an accessor for the products attribute
    • public void setProductList() – a mutator for the products attribute
  • Relationships
    • Suppliers contain any number of products in their list of supplied products. In contrast, products must be provided by exactly one supplier, no more and no less. Even if the supplier disappears, any existing products they had on the market remain available.

Implementation


Once you have completed the UML class diagram for this project, try using your diagram to implement this project in Java. If you need any details that were not specified in the outline above, you must choose how to implement them by following good object-oriented design. Above all else, your program must adhere to the design you specified in your class diagram!

Please include any code you wrote to test your program. This project is a good opportunity to try unit testing.

If you are able to correctly implement this whole project without deviating from the original design and without any major errors, No partial credit will be given for incomplete/buggy code.

Submission

Once you have completed your diagram, submit this assignment by clicking “Start Assignment” at the top of the page and then selecting your class diagram picture for submission. Make sure all parts of your diagram are clear and legible or you may lose points!

If you chose to complete the optional implementation code, please submit your program files alongside your diagram.

Rubric

Criteria Ratings Pts

This criterion is linked to a Learning OutcomeCompletenessFor full points, the diagram must show all classes listed in the instructions with all variables and methods that each class

× How can I help you?