In our software we never want to have sections of code that are duplicated. We also...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
In our software we never want to have sections of code that are duplicated. We also want to avoid sections of code that are nearly duplicated - the same with slight variations. This is one of the primary rules in programming: no duplicate code. You may have noticed that in the Library assignment we break this rule, even though we have used inheritance. In this assignment, we remove duplicate code that we have added to the project by using the principles of polymorphism. We are going to remove nearly duplicate code involving books and videos. Requirements Here are the requirements for the project. • In Class Library, we have two separate arrays for books and videos. Change these two arrays to be a single array of Loanable[]. Make the size of the array be 10. • . Create a new method addToLibrary(Loanable loanable) to add a new Loanable to Loanable[]. Update addBookToLibrary() to create a new book and then call addToLibrary(). Make a similar change for video. • Create a new method called find Loanable() that finds a Loanable by title and returns it. Delete findBook(), findVideo(). • Create a new method checkout(String title) that finds a Loanable and checks it out. Delete checkoutBook(), checkoutVideo(). • Create toString() in Class Book and Video. • Change printinventory() to use loanables[] and the toString() methods. Remove the code that totals pages and minutes. • When I made these changes, it reduced the size of Library by about 40 lines, making it 33% smaller than it was. Testing Here is a test program: public static void main (String arg[]) { Library library = new Library(); library.addBookToLibrary ("Moby Dick", 540); library.addBookToLibrary ("The Crow", 112) ; library.addBookToLibrary ("Coding", 412); } library.addBookToLibrary library.addBookToLibrary library.addBookToLibrary library.addVideoToLibrary library.addVideoToLibrary library.addVideoToLibrary ("Metaverse", 200); ("Purple", 180); ("Summer", 301); ("Blade Runner", 190); ("Inception", 230); ("The Tiger and Me", 200); library.print Inventory (); library.checkout ("Orange"); library.checkout ("Purple"); library.checkout ("Coding"); library.checkout ("Purple"); library.checkout ("Inception"); library.printItemsOnLoan (); Output Inventory: Book 'Moby Dick' Number of pages: 540 Book 'The Crow' Number of pages: 112 Book 'Coding' Number of pages: 412 Book 'Metaverse' Number of pages: 200 Book 'Purple' Number of pages: 180 Book 'Summer' Number of pages: 301 Video 'Blade Runner' Number of minutes: 190 Video 'Inception' Number of minutes: 230 Video 'The Tiger and Me' Number of minutes: 200 Couldn't find book Orange You can check out Purple You can check out Coding Purple is already checked out. You can check out Inception Loaned: Book 'Moby Dick' Number of pages: 540 Book 'The Crow' Number of pages: 112 Book 'Metaverse' Number of pages: 200 Book 'Purple' Number of pages: 180 Book 'Summer' Number of pages: 301 Video 'Blade Runner' Number of minutes: 190 Video 'Inception' Number of minutes: 230 Video 'The Tiger and Me' Number of minutes: 200 Number of items on loan: 9 In our software we never want to have sections of code that are duplicated. We also want to avoid sections of code that are nearly duplicated - the same with slight variations. This is one of the primary rules in programming: no duplicate code. You may have noticed that in the Library assignment we break this rule, even though we have used inheritance. In this assignment, we remove duplicate code that we have added to the project by using the principles of polymorphism. We are going to remove nearly duplicate code involving books and videos. Requirements Here are the requirements for the project. • In Class Library, we have two separate arrays for books and videos. Change these two arrays to be a single array of Loanable[]. Make the size of the array be 10. • . Create a new method addToLibrary(Loanable loanable) to add a new Loanable to Loanable[]. Update addBookToLibrary() to create a new book and then call addToLibrary(). Make a similar change for video. • Create a new method called find Loanable() that finds a Loanable by title and returns it. Delete findBook(), findVideo(). • Create a new method checkout(String title) that finds a Loanable and checks it out. Delete checkoutBook(), checkoutVideo(). • Create toString() in Class Book and Video. • Change printinventory() to use loanables[] and the toString() methods. Remove the code that totals pages and minutes. • When I made these changes, it reduced the size of Library by about 40 lines, making it 33% smaller than it was. Testing Here is a test program: public static void main (String arg[]) { Library library = new Library(); library.addBookToLibrary ("Moby Dick", 540); library.addBookToLibrary ("The Crow", 112) ; library.addBookToLibrary ("Coding", 412); In our software we never want to have sections of code that are duplicated. We also want to avoid sections of code that are nearly duplicated - the same with slight variations. This is one of the primary rules in programming: no duplicate code. You may have noticed that in the Library assignment we break this rule, even though we have used inheritance. In this assignment, we remove duplicate code that we have added to the project by using the principles of polymorphism. We are going to remove nearly duplicate code involving books and videos. Requirements Here are the requirements for the project. • In Class Library, we have two separate arrays for books and videos. Change these two arrays to be a single array of Loanable[]. Make the size of the array be 10. • . Create a new method addToLibrary(Loanable loanable) to add a new Loanable to Loanable[]. Update addBookToLibrary() to create a new book and then call addToLibrary(). Make a similar change for video. • Create a new method called find Loanable() that finds a Loanable by title and returns it. Delete findBook(), findVideo(). • Create a new method checkout(String title) that finds a Loanable and checks it out. Delete checkoutBook(), checkoutVideo(). • Create toString() in Class Book and Video. • Change printinventory() to use loanables[] and the toString() methods. Remove the code that totals pages and minutes. • When I made these changes, it reduced the size of Library by about 40 lines, making it 33% smaller than it was. Testing Here is a test program: public static void main (String arg[]) { Library library = new Library(); library.addBookToLibrary ("Moby Dick", 540); library.addBookToLibrary ("The Crow", 112) ; library.addBookToLibrary ("Coding", 412); } library.addBookToLibrary library.addBookToLibrary library.addBookToLibrary library.addVideoToLibrary library.addVideoToLibrary library.addVideoToLibrary ("Metaverse", 200); ("Purple", 180); ("Summer", 301); ("Blade Runner", 190); ("Inception", 230); ("The Tiger and Me", 200); library.print Inventory (); library.checkout ("Orange"); library.checkout ("Purple"); library.checkout ("Coding"); library.checkout ("Purple"); library.checkout ("Inception"); library.printItemsOnLoan (); Output Inventory: Book 'Moby Dick' Number of pages: 540 Book 'The Crow' Number of pages: 112 Book 'Coding' Number of pages: 412 Book 'Metaverse' Number of pages: 200 Book 'Purple' Number of pages: 180 Book 'Summer' Number of pages: 301 Video 'Blade Runner' Number of minutes: 190 Video 'Inception' Number of minutes: 230 Video 'The Tiger and Me' Number of minutes: 200 Couldn't find book Orange You can check out Purple You can check out Coding Purple is already checked out. You can check out Inception Loaned: Book 'Moby Dick' Number of pages: 540 Book 'The Crow' Number of pages: 112 } library.addBookToLibrary library.addBookToLibrary library.addBookToLibrary library.addVideoToLibrary library.addVideoToLibrary library.addVideoToLibrary ("Metaverse", 200); ("Purple", 180); ("Summer", 301); ("Blade Runner", 190); ("Inception", 230); ("The Tiger and Me", 200); library.print Inventory (); library.checkout ("Orange"); library.checkout ("Purple"); library.checkout ("Coding"); library.checkout ("Purple"); library.checkout ("Inception"); library.printItemsOnLoan (); Output Inventory: Book 'Moby Dick' Number of pages: 540 Book 'The Crow' Number of pages: 112 Book 'Coding' Number of pages: 412 Book 'Metaverse' Number of pages: 200 Book 'Purple' Number of pages: 180 Book 'Summer' Number of pages: 301 Video 'Blade Runner' Number of minutes: 190 Video 'Inception' Number of minutes: 230 Video 'The Tiger and Me' Number of minutes: 200 Couldn't find book Orange You can check out Purple You can check out Coding Purple is already checked out. You can check out Inception Loaned: Book 'Moby Dick' Number of pages: 540 Book 'The Crow' Number of pages: 112 Book 'Metaverse' Number of pages: 200 Book 'Purple' Number of pages: 180 Book 'Summer' Number of pages: 301 Video 'Blade Runner' Number of minutes: 190 Video 'Inception' Number of minutes: 230 Video 'The Tiger and Me' Number of minutes: 200 Number of items on loan: 9 Book 'Metaverse' Number of pages: 200 Book 'Purple' Number of pages: 180 Book 'Summer' Number of pages: 301 Video 'Blade Runner' Number of minutes: 190 Video 'Inception' Number of minutes: 230 Video 'The Tiger and Me' Number of minutes: 200 Number of items on loan: 9
Expert Answer:
Answer rating: 100% (QA)
Here is a basic outline of the changes you need to make to the existing code 1 Change arrays to a si... View the full answer
Related Book For
Managerial Accounting Decision Making and Performance Management
ISBN: 978-0273764489
4th edition
Authors: Ray Proctor
Posted Date:
Students also viewed these programming questions
-
Planning is one of the most important management functions in any business. A front office managers first step in planning should involve determine the departments goals. Planning also includes...
-
Googles ease of use and superior search results have propelled the search engine to its num- ber one status, ousting the early dominance of competitors such as WebCrawler and Infos- eek. Even later...
-
There are major responsibilities of system administrator as listed below: o Start-up and shut down the system o Performance tuning o Managing user accounts o System security o Backup and recovery o...
-
Profit maximization implies that firms will make input choices in a marginal way. Explain why the following marginal rules found in this chapter are specific applications of this general idea: a. MRL...
-
Chris is the the principal Licensee at City Real Estate. He has built the agency over the last six years and he has established a strong client base and reputation within the local region. He has...
-
Using information from the preceding question, suppose Copies R Us sold the machine for $5,000. What is the result of this disposal transaction? a. Gain of $2,000 b. Loss of $2,000 C. Gain of $3,000...
-
Assume the following data for Lusk Inc. before its year-end adjustments: Journalize the adjusting entries for the following: a. Estimated customer allowances b. Estimated customer returns? Unadjusted...
-
1. How has the study of media effects evolved over the past 100 years? 2. How do we determine when material is obscene or not? 3.How have newer media changed the way we study media effects? 4.What...
-
The Country Store is a retail outlet for a variety of hardware and housewares. The owner is eager to prepare a budget and is especially concerned with her cash position. The company will have to...
-
Kaumajet Factory produces two products: table lamps and desk lamps. It has two separate departments: Fabrication and Assembly. The factory overhead budget for the Fabrication Department is $738,010,...
-
Transverse waves with a speed of 59.5 m/s are to be produced on a stretched string. A 5.85 m length of string with a total mass of 0.0600 kg is used. (a) What is the required tension in the string? N...
-
An isolated conductor of arbitrary shape has a net charge of +9.00x106 C. Inside the conductor is a cavity within which is a point charge q +3.15x106 C. = What is the charge on the cavity wall?...
-
An investor web page claims thatearnings per share is the bestmeasure of a share's true price because it shows you how much of a company's profit after tax that each shareholder owns. Look up the...
-
Who are the stakeholders? What does each stakeholder want? What resources do they contribute to the organization? What claims are they likely to make on the organization?
-
A 2 0 kg object is pulled to the right with a force of 3 8 0 N at an angle of 4 5 degree above the horizontal. It is also being pulled to the left wiht a force of 3 4 0 N at an angle of 2 5 degree...
-
A light rod of length = 1.00 m rotates about an axis perpendicular to its length and passing through its center as in the figure below. Two particles of masses m = 4.30 kg and m = 3.00 kg are...
-
Define the essential properties of the following types of operating systems: a. Batch b. Interactive c. Time sharing d. Real time e. Network f. Parallel g. Distributed h. Clustered i. Handheld
-
The current annual budget for King & Co., makers of baseball caps, is summarized as follows: ...............................................................................................000 Sales...
-
SACCUS is a local charity which decides to hold an outdoors fund-raising event in mid-summer. The secretary has a connection with an entertainments company which puts on musical laser light shows for...
-
P Ltd manufactures a specialist photocopier. Increased competition from a new manufacturer has meant that P Ltd has been operating below full capacity for the last two years. The budgeted information...
-
A company is scheduling temporary differences for the purpose of computing deferred taxes. The company compared tax basis assets and liabilities with book basis assets and liabilities and accumulated...
-
A company is scheduling its temporary differences for the purpose of computing deferred taxes. The company compared tax basis assets and liabilities with book basis assets and liabilities and...
-
Derive the look-up table for the tangent function in increments of 1 degree. Be sure to take advantage of symmetry.
Study smarter with the SolutionInn App