Programming Assignment 2 Solution

$35.00 $29.00

Deliverables: The following Java file should be submitted to Google Classroom by the due date and time specified above. Submissions received after the deadline will be subject to the late policy described in the syllabus. Assignment02_{StudentNumber}.java Specifications: Overview: You will continue the program this semester to maintain the inventory for a store. Do not forget…

5/5 – (2 votes)

You’ll get a: zip file solution

 

Description

5/5 – (2 votes)

Deliverables:

The following Java file should be submitted to Google Classroom by the due date and time specified above. Submissions received after the deadline will be subject to the late policy described in the syllabus.

  1. Assignment02_{StudentNumber}.java

Specifications:

Overview: You will continue the program this semester to maintain the inventory for a store.

Do not forget your headers with @author and @since information.

Requirements: Write and modify the following set of classes (All constructors should take parameters in the order given and initialize empty sets)::

  1. Product

    1. Attributes – no change

    1. Methods – all methods from Project 01 with following modifications

      1. setPrice(price: double): None

        1. raises InvalidPriceException if amount is negative

      1. addToInventory(amount: int): None

        1. raises InvalidAmountException if amount is negative

      1. purchase(amount: int): double

        1. if amount is negative or greater than count, do not change count and raise InvalidPurchaseException

  1. FoodProduct – a child of Product

    1. Attributes – no change

    1. Methods

      1. setCalories(calories: int): None

        1. raises InvalidAmountException if calories is negative

  1. ClothingProduct – no change

  1. Customer

    1. Attributes – no change (hint: additional attributes will make this class easier to implement)

    1. Methods

      1. addToCart(product: Product, count: int): None

        1. Adds the passed product and number to the customer cart

        1. For this assignment, it will mean calling the purchase() method of the Product passed and adding to the receipt String and totalDue if the purchase is successful

        1. If the purchase() method raises an InvalidPurchaseException, this method catches it and displays a message to the screen beginning with “ERROR: ”

Page 2 of 5

      1. receipt(): String

        1. returns each Product in the cart on a separate line in the format below

{Product Name} – {Product Price} X {count} … {total for

Product}

Total Due – {Total amount}

      1. getTotalDue(): double – returns the total amount due

      1. pay(amount: double): double

        1. If amount is greater than or equal to total due, displays a

Thank you” message to the screen and returns the amount that should be given as change

        1. If amount is less than total due, raises a NotEnoughPaymentException

  1. ClubCustomer – no change

  1. Store

    1. Attributes

      1. An array or Arraylist of ClubCustomer objects

      1. An array or Arraylist of Product objects

    1. Methods

      1. Constructor no longer takes number for the array. The size set of Products and ClubCustomers will now be dynamic

      1. getCount(): int – returns the number of Products saved

      1. addProduct(product: Product): None

        1. Adds the passed Product to the set

      1. addCustomer(customer: ClubCustomer): None

        1. Adds the passed Customer to the set

      1. getProduct(name: String): Product

        1. returns the Product with the name passed

        1. if the name is not found in the set, raises an ProductNotFoundException

      1. getCustomer(phone: String): ClubCustomer

        1. returns the ClubCustomer with the phone number passed

        1. if the phone number is not found in the set, raises an CustomerNotFoundException

      1. removeProduct(name: String): None

        1. removes the Product with the name passed from the set

        1. if the name is not found in the set, raises an ProductNotFoundException

      1. removeCustomer(phone: String): None

        1. removes the ClubCustomer with the phone number passed from the set

        1. if the phone number is not found in the set, raises an CustomerNotFoundException

Page 3 of 5

  1. Custom Exceptions (All must be instances of RunTimeException)

    1. InvalidPriceException

      1. Additional Attribute – price: double

      1. toString() “InvalidPriceException: “ + price

    1. InvalidAmountException

      1. Additional Attribute – amount: int

      1. toString() “InvalidAmountException: “ + amount

    1. InvalidPurchaseException

      1. Additional Attributes – amount: int, remaining: int

      1. toString() “InvalidPurchaseException: “ + amount + “ requested, “ + remaining + “ remaining”

    1. NotEnoughPaymentException

      1. Additional Attributes – amount: double, due: double

      1. toString() “NonEnoughPaymentException: “ + due + “ due, but only “ + amount + “ given”

    1. ProductNotFoundException

      1. Additional Attribute – name: String

      1. toString() “ProductNotFoundException: “ + name

    1. CustomerNotFoundException

      1. Additional Attribute – phone: String

      1. toString() “CustomerNotFoundException: “ + phone

Design: Your program does not require a main method. You are only responsible for creating the six (6) classes and six (6) Exceptions described above.

Code: The file you submit will be named Assignment02_{StudentNumber}. You should put all java classes for this assignment inside of this file as discussed in class.

Test: You are responsible for testing your program. It is important to not rely solely on the examples presented in this Assignment description. It would be a very good idea to write your own test cases for this assignment.

Grading:

Google Classroom Submission: If anything is ambiguous, it is your responsibility to ask questions. It is also your responsibility to complete this assignment in a timely manner. Questions regarding this assignment will likely not be answered if received after 17:00 on the due date of the assignment.

An example main() method.

Compiler error

Commenting out compiler error gets first Runtime error (“fp.purchase(200)”)

Page 5 of 5

Commenting out first Exception line gets second Exception (“c.pay(2000)”)

CSE 102|Spring 2020

5

Programming Assignment 2 Solution
$35.00 $29.00