Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

here is the question: Specifications : Overview : You will write two classes thi

ID: 3841569 • Letter: H

Question

here is the question:

Specifications:

Overview: You will write two classes this week. One will represent information for a product in a store (such as milk, apples, candy, or…bread). The other invoke the Product class by having an array of Products representing the store inventory.

Product

Requirements: Write a class that has the following data fields and methods:

Data Fields:

productID: integer

name: String

price: double

quantity: double

isPartitial: boolean

Constructor that takes 5 parameters:

Integer for the product ID

String for the product name

Double for the product price

Double for the product quantity

Boolean to indicate if whole numbers are required for this product (i.e. apples can be bought in partial kilograms, but milk can only be bought by whole containers)

Note: if Boolean parameter is true, quantity should be set to a whole number by rounding down the value passed for quantity

getID

Takes no parameters

Returns the product ID

getName

Takes no parameters

Returns the Product name

setName

Takes a String parameter

Changes the product name

Returns nothing

getPrice

Takes no parameters

Returns the product price

setPrice

Takes a double parameter

Checks for price to be non-negative

Changes the product price if non-negative

Displays an error message if price is negative

Returns nothing

getQuantity

Takes a double parameter

Returns the quantity

reduceQuantity

Takes a double parameter

Checks for amount requested to be non-negative

Displays an error message if negative

Checks for amount requested to be less than or equal to remaining quantity

Displays an error message if greater than amount remaining

Checks if whole numbers are required and if the amount requested is a whole number

Displays an error message if a whole number is not given but they are required

If no errors are encountered, reduces quantity by amount requested

Returns true (Boolean) if no errors are encountered, false otherwise

increaseQuantity

Takes a double parameter

Checks for amount to be added to be non-negative

Displays an error message if negative

Checks if whole numbers are required and if the amount to be added is a whole number

Displays an error message if a whole number is not given but they are required

If no errors are encountered, increases quantity by amount to be added

Returns true (Boolean) if no errors are encountered, false otherwise

Include any class variables you need to implement these methods. We will not check for these variables, so they can be named anything you choose and can be public or private.

You may also implement any other methods you think necessary, but the methods given above will be the ones that will be tested.

Store

Requirements: Write a class that has the following data fields and methods:

Data Fields:

name: String

products: array of products

Constructor that takes 2 parameters:

String for the store name

Product array for the inventory

getName

Takes no parameters

Returns the Store name

productList

Takes no parameters

Displays a heading for ID, Name, Quantity, and Price followed by the list of products

An example is shown

Returns nothing

sellProduct

Takes 2 parameters (Product ID and amount requested)

If the product is not found, displays an error message

Reduces the inventory for the product by the amount requested and displays the following (Hint: call the Product method)

Returns the cost for this product (price * quantity)

If the sale was not able to happen (Product not found, quantity has a value not allowed), returns -1

addQuantity

Takes 2 parameters (Product ID and amount to be added)

If the product is not found, displays an error message

Adds to the inventory for the product by the amount given and displays the following (Hint: call the Product method)

If the addition was not able to happen (Product not found, amount to be added has a value not allowed), returns false

Returns true otherwise

discount

Takes 2 parameters (Product ID and percentage to be discounted)

If the product is not found, displays an error message

Changes the price of product to the old price * (1 – discount percentage) and displays the following

(25% discount, 0.25 was entered)

Returns nothing

Include any class variables you need to implement these methods. We will not check for these variables, so they can be named anything you choose and can be public or private.

You may also implement any other methods you think necessary, but the methods given above will be the ones that will be tested.

words Qx English (United States) Specifications: overview: You will write two classes this week. One will represent information for a product in a store (such as milk, apples, candy, or...bread). The other invoke the Product class by having an array of Products representing the store inventory. Product Requirements: Write a class that has the following data fields and methods: Data Fields o productID: integer o name: String o price: double o quantity: double o is Partitial: boolean Constructor that takes 5 parameters: o Integer for the product ID o String for the product name o Double for the product price o Double for the product quantity o Boolean to indicate if whole numbers are required for this product (i.e. apples can be bought in partial kilograms, but milk can only be bought by whole containers) o Note: if Boolean parameter is true, quantity should be set to a whole number by rounding down the value passed for quantity etID o T no parameters akes

Explanation / Answer

Below is the required code with two classes , please rate if satisfied else comment , i ll clarify your query:

Product.java

package Chegg;

public class Product {

   private int productID;
   private String name;
   private double price;
   private double quantity;
   private boolean isPartial;

   public Product(int productID, String name, double price, double quantity, boolean isPartial) {
       this.productID = productID;
       this.name = name;
       this.price = price;
       if (isPartial) {
           this.quantity = Math.floor(quantity);
       } else {
           this.quantity = quantity;
       }
       this.isPartial = isPartial;
   }

   public String getName() {
       return name;
   }

   public void setName(String name) {
       this.name = name;
   }

   public double getPrice() {
       return price;
   }

   public void setPrice(double price) {
       if (price <= 0) {
           System.out.println("Price cannot be negative");
       }
       {
           this.price = price;
       }
   }

   public int getID() {
       return productID;
   }

   public double getQuantity() {
       return quantity;
   }

   /**
   * Reduces quantity of product
   *
   * @param amount
   * @return
   */
   public boolean reduceQuantity(double amount) {
       if (amount <= 0) {
           System.out.println("Price cannot be negative");
           return false;
       } else if (amount <= quantity) {
           System.out.println("Greater than amount remaining");
           return false;
       } else if (isPartial) {
           if (!(amount % 1 == 0)) {
               System.out.println("Whole number is required");
               return false;
           }
       }
       quantity = quantity - amount;
       return true;

   }

   /**
   * Adds quantity of product
   *
   * @param amount
   * @return
   */
   public boolean increaseQuantity(double amount) {
       if (amount <= 0) {
           System.out.println("Price cannot be negative");
           return false;
       } else if (isPartial) {
           if (!(amount % 1 == 0)) {
               System.out.println("Whole number is required");
               return false;
           }
       }
       quantity = quantity + amount;
       return true;
   }

}

Store.java

package Chegg;

public class Store {
   private String name;
   private Product[] products;

   /**
   * @param name
   * @param products
   */
   public Store(String name, Product[] products) {
       this.name = name;
       this.products = products;
   }

   public String getName() {
       return name;
   }

   public Product[] productList() {
       return products;
   }

   /**
   * Reduces quantity of product
   *
   * @param productID
   * @param amount
   * @return
   */
   public double sellProduct(int productID, double amount) {
       // Checks if product is present in array
       boolean temp = false;
       for (int i = 0; i < products.length; i++) {
           if (productID == products[i].getID()) {
               temp = true;
           }
       }

       if (temp == false) {
           System.out.println("Product not found");
           return 0;
       }
       // End product check
       for (int i = 0; i < products.length; i++) {
           if (productID == products[i].getID()) {
               products[i].reduceQuantity(amount);
               return products[i].getPrice() * products[i].getQuantity();
           }
       }
       return 0;

   }

   /**
   * Adds quantity of product
   *
   * @param productID
   * @param amount
   * @return
   */
   public boolean addQuantity(int productID, double amount) {
       // Checks if product is present in array
       boolean temp = false;
       for (int i = 0; i < products.length; i++) {
           if (productID == products[i].getID()) {
               temp = true;
           }
       }

       if (temp == false) {
           System.out.println("Product not found");
           return false;
       }
       // End product check

       for (int i = 0; i < products.length; i++) {
           if (productID == products[i].getID()) {
               products[i].increaseQuantity(amount);
               return true;
           }
       }
       return false;
   }

   /**
   * Updates price of product after applying discount
   *
   * @param productID
   * @param percentage
   */
   public void discount(int productID, int percentage) {
       // Checks if product is present in array
       boolean temp = false;
       for (int i = 0; i < products.length; i++) {
           if (productID == products[i].getID()) {
               temp = true;
           }
       }

       if (temp == false) {
           System.out.println("Product not found");
       }
       // End product check
       for (int i = 0; i < products.length; i++) {
           if (productID == products[i].getID()) {
               double oldPrice = products[i].getPrice();
               products[i].setPrice(oldPrice * (1 - (percentage / 100)));
           }
       }
   }

}