Question

In: Computer Science

Class GroceryBag collects instances of class Item in an appropriate data structure.                       Class Item      &n

Class GroceryBag
collects instances of class Item in an appropriate data structure.

                      Class Item
                ---------------------------
               -String description
               -int cost   //price in cents
               ----------------------------
               + [constructor, getters, and a toString() method]
•         (Assume class Item has already been coded)

                      Class GroceryBag (Highlights)
               ----------------------------------
                 -bag   // an ArrayList of <Item>
               ----------------------------------
                  assume public methods: constructor, totalBag(), findItem(String it), listAll(), etc.

•         The ONLY thing you need to do in the space below is to write java code for the complete method specified:
•         In the space below, write code for a complete method
                                  void showCheapItems()
that will use the ArrayList bag and which will display all Items in the bag whose price is below the overall average of
all the prices of all the items in the bag.
[Hint: average will be the sum divided by the number of items].
Required: use at least one for-each loop as part of your method.

please help quickly!!!!!

Solutions

Expert Solution

Below is the snapshot of the program, the user needs to write the program on the java compiler, then he can exutre the program:

Output snapshot of the program:


Related Solutions

1- Given following data structure of Single linked list :           class ListNode                     &n
1- Given following data structure of Single linked list :           class ListNode                                    { int item ;                                           ListNode next ;                                      ….            } Choose the correct answer :                                                            Suppose reference refers to a node in a List (using the ListNode ) . What statement changes reference so that it refers to the next node?                        1-      reference++ ; 2-    reference = next ; 3-    reference+= next ; reference = reference.next ; Suppose p refers to...
In java what is the best algorithm and data structure choice to search for all instances...
In java what is the best algorithm and data structure choice to search for all instances where a pattern is found some larger texts. Also please provide the worst-case complexity big o notation of this and why it is best. Assuming the texts are all stored in a class instance that has a field contents. Which is then stored as a array list value in a linked hash map with the key being the username of the poster.
A class collects data on eye color and gender and organizes it into the table shown....
A class collects data on eye color and gender and organizes it into the table shown. Brown Blue Green Male 24 14 10 Female 20 20 12 Use the data to find the probability that a person randomly selected from this group: (a) does not have brown eyes. (b) has brown eyes or blue eyes. (c) is male or has green eyes. (d) is female, given that the person has blue eyes. (e) Find the probability that two people selected...
Learning Objectives: To be able to code a class structure with appropriate attributes and methods. To...
Learning Objectives: To be able to code a class structure with appropriate attributes and methods. To demonstrate the concept of inheritance. To be able to create different objects and use both default and overloaded constructors. Practice using encapsulation (setters and getters) and the toString method. Create a set of classes for various types of video content (TvShows, Movies, MiniSeries). Write a super or parent class that contains common attributes and subclasses with unique attributes for each class. Make sure to...
Language: Java To be able to code a class structure with appropriate attributes and methods. To...
Language: Java To be able to code a class structure with appropriate attributes and methods. To demonstrate the concept of inheritance. To be able to create different objects and use both default and overloaded constructors. Practice using encapsulation (setters and getters) and the toString method. Create a set of classes for various types of video content (TvShows, Movies, MiniSeries). Write a super or parent class that contains common attributes and subclasses with unique attributes for each class. Make sure to...
A class variable is visible to and shared by all instances of a class. How would...
A class variable is visible to and shared by all instances of a class. How would such a variable be used in an application? Describe the difference between abstract classes and concrete classes, giving an example of each. Explain how data are encapsulated and information is hidden in Java? Explain the difference between a class and an interface in Java, using at least one example.
CS 209 Data Structure 5. Consider the Pair class covered in class: class Pair {    ...
CS 209 Data Structure 5. Consider the Pair class covered in class: class Pair {     public A first;     public B second;     public Pair(A a, B b)     {         first = a;         second = b;     }     public void setFirst(A a)     {         first = a;     }     public A getFirst()     {         return first;     }     public void setSecond(B b)     {         second = b;     }     public...
class nodeType                    // class used to implement a node { public:         int data;   &n
class nodeType                    // class used to implement a node { public:         int data;                        // data member of node         nodeType * next;        // pointer member of node }; int main() {         int x;         nodeType * head =________ ;                     // initialize head pointer         nodeType * tail = _______ ;                        // initialize tail pointer _______ * p;                                                 // create an auxiliary pointer to a node         for (x = 0; x < 10; ++x)         {                 p =   _________ nodeType; // create a node ___________ = x + 10;                                // store...
Write a class named RetailItem that holds data about an item in retail store.
Python 3Your program will have 2 classes:A) RetailItem ClassWrite a class named RetailItem that holds data about an item in retail store.Attributes: The class should store following data in attributes:>item_Name> PriceMethods:> RetailItem class’s __init__ method should accept an argument for each attribute.> RetailItem class should also have accessor and mutator methods for each attributeB) MainMenu ClassAttributes: The class should store following data in attributes:> List of RetailItem Objects: InventoryMethods:> createInventory(): method to create three RetailItem Objects store in list Inventory...
QUESTION 24 A physician query may not be appropriate in which of the following instances? A....
QUESTION 24 A physician query may not be appropriate in which of the following instances? A. Diagnosis of viral pneumonia noted in a progress note and sputum cultures growing bacterial pathogens B. An operative report stating "lung cancer" when the pathology report states non-small cell carcinoma C. A final diagnosis of chest pain and abnormal cardiac enzymes indicative of an AMI D. Discharge summary indicating chronic renal failure when the progress notes document acute renal failure throughout the stay 10...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT