Question

Create a main method inside the ShoppingCart - create a vegetable object - call the addprice...

Create a main method inside the ShoppingCart 

   - create a vegetable object
       - call the addprice method polymorphically
       - call the display method polymorphically

   - create a meat object
      - call the addprice method polymorphically
      - call the display method polymorphically

Homework Answers

Answer #1

I am solving the question in Java as the question has not specified the language to solve the problem.I am assuming the Shopping cart is a class and vegetable and meat are child classes of shopping cart. Please find the attached COMMENTS in the answer for better understanding. THANK YOU.

public static void main(String args[] ) {

/* FOR THE VEGETABLE SECTION */

ShoppingCart veg_obj= new Vegetable();   //creating the vegtable object 

veg_obj.addprice();     //calling addprice() method  polymorphically 
veg_obj.display();     // callind the display method polymorphically 

/*FOR MEAT SECTION */

ShoppingCart meat_obj= new meat();            //creating the meat object 

meat_obj.addprice();      //calling the addprice method polymorphically 

meat_obj.display();     // calling the display method polymorphically 

}
 
Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
java coding Create two objects S1 and S2 that uses the default constructor · Call the...
java coding Create two objects S1 and S2 that uses the default constructor · Call the ‘display’ method for objects S1 and S2. · Call the ‘setGrade’method that increments the grade by 1 for object S2 · Call the ‘getGrade’ method that will display the value variable grade for objects S1 and S2
write some lines of Java code that create a Screen object. Then call its clear method...
write some lines of Java code that create a Screen object. Then call its clear method if (and only if) its number of pixels is greater than two million. (Don’t worry about things being logical here; the goal is only to write something that is syntactically correct—i.e., that would compile if we typed it in.)
Create a C# program named PaintingEstimate whose Main() method prompts a user for length and width...
Create a C# program named PaintingEstimate whose Main() method prompts a user for length and width of a room in feet. Create a method that accepts the values and then computes the cost of painting the room, assuming the room is rectangular and has four full walls and 9-foot ceilings. The price of the job is $6 per square foot. Return the price to the Main() method, and display it.
main The main method instantiates an ArrayList object, using the Car class. So, the ArrayList will...
main The main method instantiates an ArrayList object, using the Car class. So, the ArrayList will be filled with Car objects. It will call the displayMenu method to display the menu. Use a sentinel-controlled loop to read the user’s choice from stdin, call the appropriate method based on their choice, and redisplay the menu by calling displayMenu. Be sure to use the most appropriate statement for this type of repetition. displayMenu Parameters:             none Return value:          none Be sure to use...
Create a Shape (Object) Class Create a class (Shapes) that prompts the user to select a...
Create a Shape (Object) Class Create a class (Shapes) that prompts the user to select a shape to be drawn on the screen. Objects: Circle, X, box, box with an x inside, or any other object of your choice. Depending on the user’s choice, you will then ask for the number of rows, columns or any requirements needed to draw the shape. Finally, you will display the shape selected by the user to the screen. Your class should have at...
In C++ Create a method that populates an array: pArray(), be sure to have the appropriate...
In C++ Create a method that populates an array: pArray(), be sure to have the appropriate return type, and parameters. Call pArray() in your main() method.
Create a ShoppingCart class in java that simulates the operation of a shopping cart. The ShoppingCart...
Create a ShoppingCart class in java that simulates the operation of a shopping cart. The ShoppingCart instance should contain a BagInterface implementation that will serve to hold the Items that will be added to the cart. Use the implementation of the Item object provided in Item.java. Note that the price is stored as the number of cents so it can be represented as an int (e.g., an Item worth $19.99 would have price = 1999). Your shopping cart should support...
Write the following problem in Java Create a class Dog, add name, breed, age, color as...
Write the following problem in Java Create a class Dog, add name, breed, age, color as the attributes. You need to choose the right types for those attributes. Create a constructor that requires no arguments. In this constructor, initialize name, breed, age, and color as you wish. Define a getter and a setter for each attribute. Define a method toString to return a String type, the returned string should have this information: “Hi, my name is Lucky. I am a...
Find the error in the following pseudocode. Module main()     Declare Real mileage     Call getMileage()...
Find the error in the following pseudocode. Module main()     Declare Real mileage     Call getMileage()     Display "You've driven a total of ", mileage, " miles." End Module Module getMileage()     Display "Enter your vehicle’s mileage."     Input mileage End Module
Create and use an enumeration create an enumeration and use it in a test application. 1....
Create and use an enumeration create an enumeration and use it in a test application. 1. Import the project named ch13 ex 2 Enumeration that's in the ex starts folder, 2. Create an enumeration named CustomerType. This enumeration should contain constants that represent three types of customers: retail. trade, and college. Use an enumeration 3. open the Customer Type App class. Then, add a method to this class that returns a discount percent C10 for retail. 30 for trade. and.20...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT