Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Tasks: Part 1: You own a store and people can buy products that are then shipped to their place. You already have some code

image text in transcribedimage text in transcribed

Tasks: Part 1: You own a store and people can buy products that are then shipped to their place. You already have some code for handling the shopping cart of products bought (see Product.java and Store.java). Now you decide to offer other things that people could buy, that is very different than the products you have been selling up to now: they can also buy an online book (actually a subscription, with a monthly payment and a duration) or a song in a sound file. The classes for these are provided to you (Online Book.java and SongFile.java). You now want to be able to add those to the shopping cart as well. Modify the classes provided (Product, Online Book, and SongFile) so that they can be put into the same ArrayList. Note: the only thing they should share is the possibility of buying them (i.e., do not use inheritance here...not even the Object class). OnlineBook and SongFile cannot do this for now, so you should add that too. Note that there is one major difference between how OnlineBook and SongFile would be bought vs. how Products are currently bought: there would not be any shipment involved. The only thing that needs to be done in the related method is to get the total price for buying those, and return such amount. Next, in the main method, create one book and one song, and add both to shopping cart. Modify the "for" loop provided, so that the "read" method is called when you get a book, and the "listen" method is called when you get a song. Part 2: Using the following array of integers: 80 40 25 65 90 77 52 29 70 For tasks a) and b) above, please show your work like in the Slides #3 and #9 in "SortingSearching.pdf" 60 a) Show (step by step) how this array would be sorted using the Selection sort algorithm. b) Show (step by step) how this array would be sorted using the Insertion sort algorithm. c) Using the sorted array, show which cells would be accessed (sequence) when searching each of the following values, using the Linear Search algorithm: 60, 25, 90, and 68. d) Using the sorted array, show which cells would be accessed (sequence) when searching each of the following values, using the Binary Search algorithm: 60, 25, 90, 68, 29, and 65. For tasks c) and d) above, just give the list of values you check in the array as you perform the algorithm. For example, if I started with the non-sorted array above and searching the value 25, using the kind of algorithm used in the "search" method in the "FlexibleCourse2.java" example, here is what I would expect as answer: search 25: 80, 40, 25 Note: tasks c) and d) above ask you to do the work on the sorted array, not the unsorted one...

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Marketing

Authors: Roger Kerin, Steven Hartley, William Rudelius

16th Edition

1264218753, 978-1264218752

More Books

Students also viewed these Programming questions

Question

network design and plan

Answered: 1 week ago