subject

Write a java program to record the list of items to buy in a grocery store and compute the total price based on the quantity and unit price of each of the items. For this program, you are asked to write three classes: GroceryList Class: this class represents a list of items to buy in a grocery store. You should use an array field to store the grocery items and to keep track of the number of items as you add it to the list. Since you are lining up in the Express Checkout line, the maximum number of items is 10. This class should have a constructor that initializes the array of Grocery Item (next Class) based on the maximum number and setting the number of item count to zero. This class should also have methods to add (GroceryItems item), getTotalCost( ), and display( ) the entire grocery list items. NOTE, no getter( ) or setter( ) methods.
(8 points) GroceryItem Class: this class represents each of the item for the grocery list array (GroceryList [ ] ). This class should have a item name, quantity, and a pricePerUnit fields plus a getCost( ) method to compute the cost of each item ( quantity * pricePerUnit ). You should use the constructor (argument…) to build each of the item for the GroceryList. Note. No getter( ) or setter( ) .
TestGroceryList Class: this is the class with the main (Strings [ ] args) method that uses the above two classes to build the grocery list based on each of the grocery items.
(should use the toString ( ) method to display class attributes. We will discuss the toString( ) method this week in class)
Your program should display the following:
Grocery list items =
3 of apple 0.5 each
5 of pear 0.35 each
6 of peach 0.25 each
total cost = 4.75

ansver
Answers: 1

Another question on Computers and Technology

question
Computers and Technology, 21.06.2019 13:10
Java g array testgrades contains num_vals test scores. write a for loop that sets sumextra to the total extra credit received. full credit is 100, so anything over 100 is extra credit. ex: if testgrades = {101, 83, 107, 90}, then sumextra = 8, because 1 + 0 + 7 + 0 is 8.
Answers: 1
question
Computers and Technology, 22.06.2019 11:20
The kurt vonnegut commencement speech, the neiman-marcus chocolate chip cookie recipe, and the get-well emails to the dying boy are examples of select one: a. social engineering b. hoax emails c. email viruses d. worms
Answers: 1
question
Computers and Technology, 22.06.2019 18:30
All of the following are characteristics that must be contained in any knowledge representation scheme except
Answers: 3
question
Computers and Technology, 23.06.2019 02:00
In the context of an internet connection, llc stands for leased line connection liability limited company local loop complex local loop carrier
Answers: 1
You know the right answer?
Write a java program to record the list of items to buy in a grocery store and compute the total pri...
Questions
question
Mathematics, 16.10.2020 19:01
question
Mathematics, 16.10.2020 19:01
question
History, 16.10.2020 19:01