Question: Write a class Basket which has the following private field: . An array of MarketProducts. The class must also have the following public methods .
Write a class Basket which has the following private field:
. An array of MarketProducts. The class must also have the following public methods . A constructor that takes no inputs and initialize the field with an empty array. . A getProducts) method which takes no inputs and returns a shallow copy of the array (NOT a copy of the reference!) of MarketProducts of this Basket (with the elements in the same order) An add() method which takes as input a MarketProduct and does not return any value. The method adds the MarketProduct at the end of the list of products of this Basket . A remove ) method which takes as input a MarketProduct and returns a boolean. The method removes the first occurrence of the specified element from the array of products of this Basket. If no such product exists, then the method returns false, otherwise, after removing it, the method returns true. Note that this method removes a product from the list if and only if such product is equal to the input received. For example, it is not possible to remove 0.25 Kg of McIntosh apples for a 0.5 Kg McIntosh apples MarketProduct. After the product has been remove from the array, the subsequent elements should be shifted down by one position, leaving no empty slot in the array. . A clear) method which takes no inputs, returns no values, and empties the array of products of this Basket. A getNumOfProducts) method that takes no inputs and returns the number of products present in this Basket. . A getSubTotal) method that takes no inputs and returns the cost (in cents) of all the products in this Basket . A getTotalTax) method that takes no inputs and returns the tax amount (in cents) to be paid based on the product in this Basket. Since we are in Quebec, you can use a tax rate of 15%. The tax amount should be rounded down to the nearest cent. Note that Egg and Fruit are tax free, so taxes should be paid only for Jam. . A getTotalCost) method that takes no inputs and returns the total cost (in cents and after tax) of the products in this Basket. . A toString) method that returns a String representing a receipt for this Basket. The receipt should contain a product per line. On each line the name of the product should appear, followed by its price separated by a tab character. After all the products have been listed, the following information should appear on each line: An empty line - The subtotal cost - The total tax An empty line - The total cost . An array of MarketProducts. The class must also have the following public methods . A constructor that takes no inputs and initialize the field with an empty array. . A getProducts) method which takes no inputs and returns a shallow copy of the array (NOT a copy of the reference!) of MarketProducts of this Basket (with the elements in the same order) An add() method which takes as input a MarketProduct and does not return any value. The method adds the MarketProduct at the end of the list of products of this Basket . A remove ) method which takes as input a MarketProduct and returns a boolean. The method removes the first occurrence of the specified element from the array of products of this Basket. If no such product exists, then the method returns false, otherwise, after removing it, the method returns true. Note that this method removes a product from the list if and only if such product is equal to the input received. For example, it is not possible to remove 0.25 Kg of McIntosh apples for a 0.5 Kg McIntosh apples MarketProduct. After the product has been remove from the array, the subsequent elements should be shifted down by one position, leaving no empty slot in the array. . A clear) method which takes no inputs, returns no values, and empties the array of products of this Basket. A getNumOfProducts) method that takes no inputs and returns the number of products present in this Basket. . A getSubTotal) method that takes no inputs and returns the cost (in cents) of all the products in this Basket . A getTotalTax) method that takes no inputs and returns the tax amount (in cents) to be paid based on the product in this Basket. Since we are in Quebec, you can use a tax rate of 15%. The tax amount should be rounded down to the nearest cent. Note that Egg and Fruit are tax free, so taxes should be paid only for Jam. . A getTotalCost) method that takes no inputs and returns the total cost (in cents and after tax) of the products in this Basket. . A toString) method that returns a String representing a receipt for this Basket. The receipt should contain a product per line. On each line the name of the product should appear, followed by its price separated by a tab character. After all the products have been listed, the following information should appear on each line: An empty line - The subtotal cost - The total tax An empty line - The total cost
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
