Question: Please Write the following code in Java 2. Define a Groceryltem class that represents a request to purchase a particular item at the grocery store

Please Write the following code in JavaPlease Write the following code in Java 2. Define a Groceryltem classthat represents a request to purchase a particular item at the grocery

2. Define a Groceryltem class that represents a request to purchase a particular item at the grocery store in a given quantity (for example, two boxes of cereal). A Groceryltem object should store an item name (a String), an item quantity (an int), and a unit price (a double Your Groceryltem class should contain the following methods: *A public constructor that takes an item name, quantity, and unit price, and assigns them to the appropriate instance variables. *A getCost() method that returns the total cost of this item (its unit price times its quantity). For example, three cans of soup that cost 1.50 each would have a total cost of 4.50 A setQuantity() method that sets the Groceryltem's quantity to the supplied value. You Stony Brook University CSE 114: Computer Science I Fall 2017 may assume that the argument is always greater than 0. Next, define a GroceryList class that represents a list of items to buy from the grocery store Your GroceryList should contain an array that holds Groceryltem objects, along with a variable that tracks the current number of items in the list. You may assume that the

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!