A list, like a top-ten list, is a collection of items in a defined order, such...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
A "list", like a top-ten list, is a collection of items in a defined order, such that each item has an assigned position from one to the length of the list. For example, in the list: [Fred, 46. "Wie gehts?", 3+5i. X9+, Barney, 46 ]. the item 'Fred' is at position one, and the item 'Bamey is at position six. Notice that the items do not have to be sorted in any way. Note also that lists implicitly do not contain 'holes': the next item after the third is always the fourth. Deleting an item does not leave a "hole': for example, after deleting the third item. the item that used to be fourth is now third, the fifth is now fourth, and so on. On the other hand, inserting an item 'pushes all the items after it: after inserting an item at position three, the item that used to be third is now fourth, the fourth is now fifth, and so on. There are many operations that could be supported by a list, but for this exercise provide the following: (1) initialize: create an empty list (no items). (2) insert: insert a given item at a given position in the list. (3) insertAtFront: insert a given item at the front of the list. (4) deleteRange: delete all the items from a given start position to a given end position. [Optional] (5) deleteltem: delete all the occurrences of a given item from the list. (6) retrieve: return the item at a given position in the list. (7) find: return a list of the positions where a given item is found in the list. (8) getSize: return the number of items in the list. (9) show: return a string summarizing the contents of the list. The first operation is a constructor, and the "show" operation must be named "toString." The first item is at position one. Valid positions extend from one (not zero) to the number of items in the list. (The only exception is for 'insert: the maximum position is the size of the list plus one, so that an item can be inserted on the end.) If an operation is attempted with an invalid position, ignore the requested operation, and, if required, return "null". The insertion and deletion operations do not have to return anything. Application: Write a simple test program to exercise all the operations of a list by maintaining three lists: one with Strings and two with 'inventory items. An inventory item contains the following information: the inventory item name (a String), the quantity, and the cost per item (dollars). Construct three empty lists, then allow the user to repeatedly perform selected operations. Include one option for each of the operations listed above, and one more to compute the total value of all items in the lists of inventory (compute the sum of the quantity times the cost for each item). For each operation, let the user select which list to manipulate, then allow them to choose from a menu of the available operations. For each option, prompt for any necessary input, and display the results of each operation (or a simple message acknowledging completion if there is no result). For the deleteltem and find operations, prompt for the name of the inventory item only (not the other fields). With the find operation, display the entire list of results. Always give the user some feedback to indicate that the program has responded to the request (but don't display the contents of the list unless requested). Make your program easy to use. Start with a brief message identifying what the program does. Afterwards, include enough information in each input prompt so that the user will know what to enter without reading your code. Label the results thoroughly as well. To make your messages easier to read and understand, print occasional blank lines, especially between the input prompts and the results. Implementation: Define at least four classes: one for the main program, one for the data entries in the application's lists (the inventory item), one for a list, and one for a link. Implement the List as a singly-linked list with the empty list represented as null. Allocate the Links dynamically as required by the operations. Use only private data members in the List class, and no public methods except ones corresponding to the operations described for the data structure above. For data members, include the head of the linked list and, for efficiency of the 'getSize' method and to check the validity of the position given to some operations, a counter for the number of elements in the linked list. Inside the List class, make no reference to any of the other classes besides the Link class. The find method must generate a new List of integers to refer to all the positions where the given item was found. Inside the toString method, use the toString methods of the data entries (implicitly) to display the properties of each entry. The appropriate toString method for the actual object will be determined dynamically (at run time). Inside the find and deleteItem methods, use the 'equals' method of the data entries to compare values. The List is a general-purpose tool; it will do no input or output with the user. Declare the Link class externally, just the same as in the examples in class, with public data members, but do not refer to the Link class in the signature of any public member functions of the List class, and do not refer to the Link class anywhere except in the List class. To make it a general-purpose data structure, have each Link include a reference to an Object as the data entry. The only methods of the internal data Objects that will be used are the toString and equals methods. Define the InventoryItem class with private data members and the following methods: a constructor, accessor methods for each data member, a toString method that returns a String summarizing the contents of the object, and an equals method that compares the instance with a given instance. Notice that there are no mutator methods. For the equals method, use the same signature as that used by the Object class: public boolean equals( Object other) It will be necessary to convert the 'other' Object to an InventoryItem instance for the comparison. Then two inventory item instances are considered 'equal' if they have the same names (the Strings). Before converting to an InventoryItem, check that the Object is really an InventoryItem (with 'instanceof), and return 'false' if it is not. (If it's not an InventoryItem, it can't be equal.) Declare no data members in the main program class (except for a Scanner). Any number of methods may be defined, but information must be communicated through the parameter list. All the methods of this class must be static. The main program class is permitted to refer to InventoryItem instances but the List and Link classes are not. Create these objects as required for insertion in the appropriate lists. For the deleteItem and find operations, create an InventoryItem instance with quantity and cost equal to zero. (There is a better way to do this, but this simplifies the assignment.) All input and output will be confined to the main program class (but data validation is optional). Remember to follow the guidelines listed in your handout on software engineering standards. Start early and get the program working one piece at a time. Instead of writing all the code and then attempting to compile and test it all at once, write just a few methods and compile and test these before moving on to the rest of the operations. Turn in: Submit the file "program6.java" to "simms@mesacc.edu" Page < 2 of 2 с ZOOM + A "list", like a top-ten list, is a collection of items in a defined order, such that each item has an assigned position from one to the length of the list. For example, in the list: [Fred, 46. "Wie gehts?", 3+5i. X9+, Barney, 46 ]. the item 'Fred' is at position one, and the item 'Bamey is at position six. Notice that the items do not have to be sorted in any way. Note also that lists implicitly do not contain 'holes': the next item after the third is always the fourth. Deleting an item does not leave a "hole': for example, after deleting the third item. the item that used to be fourth is now third, the fifth is now fourth, and so on. On the other hand, inserting an item 'pushes all the items after it: after inserting an item at position three, the item that used to be third is now fourth, the fourth is now fifth, and so on. There are many operations that could be supported by a list, but for this exercise provide the following: (1) initialize: create an empty list (no items). (2) insert: insert a given item at a given position in the list. (3) insertAtFront: insert a given item at the front of the list. (4) deleteRange: delete all the items from a given start position to a given end position. [Optional] (5) deleteltem: delete all the occurrences of a given item from the list. (6) retrieve: return the item at a given position in the list. (7) find: return a list of the positions where a given item is found in the list. (8) getSize: return the number of items in the list. (9) show: return a string summarizing the contents of the list. The first operation is a constructor, and the "show" operation must be named "toString." The first item is at position one. Valid positions extend from one (not zero) to the number of items in the list. (The only exception is for 'insert: the maximum position is the size of the list plus one, so that an item can be inserted on the end.) If an operation is attempted with an invalid position, ignore the requested operation, and, if required, return "null". The insertion and deletion operations do not have to return anything. Application: Write a simple test program to exercise all the operations of a list by maintaining three lists: one with Strings and two with 'inventory items. An inventory item contains the following information: the inventory item name (a String), the quantity, and the cost per item (dollars). Construct three empty lists, then allow the user to repeatedly perform selected operations. Include one option for each of the operations listed above, and one more to compute the total value of all items in the lists of inventory (compute the sum of the quantity times the cost for each item). For each operation, let the user select which list to manipulate, then allow them to choose from a menu of the available operations. For each option, prompt for any necessary input, and display the results of each operation (or a simple message acknowledging completion if there is no result). For the deleteltem and find operations, prompt for the name of the inventory item only (not the other fields). With the find operation, display the entire list of results. Always give the user some feedback to indicate that the program has responded to the request (but don't display the contents of the list unless requested). Make your program easy to use. Start with a brief message identifying what the program does. Afterwards, include enough information in each input prompt so that the user will know what to enter without reading your code. Label the results thoroughly as well. To make your messages easier to read and understand, print occasional blank lines, especially between the input prompts and the results. Implementation: Define at least four classes: one for the main program, one for the data entries in the application's lists (the inventory item), one for a list, and one for a link. Implement the List as a singly-linked list with the empty list represented as null. Allocate the Links dynamically as required by the operations. Use only private data members in the List class, and no public methods except ones corresponding to the operations described for the data structure above. For data members, include the head of the linked list and, for efficiency of the 'getSize' method and to check the validity of the position given to some operations, a counter for the number of elements in the linked list. Inside the List class, make no reference to any of the other classes besides the Link class. The find method must generate a new List of integers to refer to all the positions where the given item was found. Inside the toString method, use the toString methods of the data entries (implicitly) to display the properties of each entry. The appropriate toString method for the actual object will be determined dynamically (at run time). Inside the find and deleteItem methods, use the 'equals' method of the data entries to compare values. The List is a general-purpose tool; it will do no input or output with the user. Declare the Link class externally, just the same as in the examples in class, with public data members, but do not refer to the Link class in the signature of any public member functions of the List class, and do not refer to the Link class anywhere except in the List class. To make it a general-purpose data structure, have each Link include a reference to an Object as the data entry. The only methods of the internal data Objects that will be used are the toString and equals methods. Define the InventoryItem class with private data members and the following methods: a constructor, accessor methods for each data member, a toString method that returns a String summarizing the contents of the object, and an equals method that compares the instance with a given instance. Notice that there are no mutator methods. For the equals method, use the same signature as that used by the Object class: public boolean equals( Object other) It will be necessary to convert the 'other' Object to an InventoryItem instance for the comparison. Then two inventory item instances are considered 'equal' if they have the same names (the Strings). Before converting to an InventoryItem, check that the Object is really an InventoryItem (with 'instanceof), and return 'false' if it is not. (If it's not an InventoryItem, it can't be equal.) Declare no data members in the main program class (except for a Scanner). Any number of methods may be defined, but information must be communicated through the parameter list. All the methods of this class must be static. The main program class is permitted to refer to InventoryItem instances but the List and Link classes are not. Create these objects as required for insertion in the appropriate lists. For the deleteItem and find operations, create an InventoryItem instance with quantity and cost equal to zero. (There is a better way to do this, but this simplifies the assignment.) All input and output will be confined to the main program class (but data validation is optional). Remember to follow the guidelines listed in your handout on software engineering standards. Start early and get the program working one piece at a time. Instead of writing all the code and then attempting to compile and test it all at once, write just a few methods and compile and test these before moving on to the rest of the operations. Turn in: Submit the file "program6.java" to "simms@mesacc.edu" Page < 2 of 2 с ZOOM +
Expert Answer:
Answer rating: 100% (QA)
Now Here it shows a simple linked list with three nodes The head of the linked list is the node at the top of the image and the tail of the linked lis... View the full answer
Related Book For
Smith and Roberson Business Law
ISBN: 978-0538473637
15th Edition
Authors: Richard A. Mann, Barry S. Roberts
Posted Date:
Students also viewed these programming questions
-
4. Consider the table of values (below - left) for two functions. Complete the table of values (below - right) for the composite function y = g(f(x)). X y = f(x) -2 2 y= g(x) 0 X y = g(f(x)) -2 -1 0...
-
List three specific parts of the Case Guide, Objectives and Strategy Section (See below) that you had the most difficulty understanding. Describe your current understanding of these parts. Provide...
-
Read the case study "Southwest Airlines," found in Part 2 of your textbook. Review the "Guide to Case Analysis" found on pp. CA1 - CA11 of your textbook. (This guide follows the last case in the...
-
Write a program that displays the color study shown at right, which gives Albers squares corresponding to each of the 256 levels of blue (blue-to-white in row major order) and gray (black-to-white in...
-
The clamp shown is used to hold the rough work piece C Knowing that the maximum allowable compressive force on the work piece is 200 N and neglecting the effect of friction at A, determine the...
-
84. Which is incorrect order of -I (1) F>Cl> Br>I (2) NR,>-NH3>-NO (3) OCH3>-OH>NH, > -C = CH>H (4) 85. Which of the following compounds is most basic? (1) CH3NH2 (3) CH,-N-CH3 CH (2) CH3-NH-CH3 (4)...
-
What are the main objectives of an international compensation plan? Would an integrated solution or a best-of-breed solution make more sense for a large manufacturing corporation? Do you believe that...
-
In fig. 20-45, charged particles move in the vicinity of a current-carrying wire. For each charged particles, the arrow indicates the direction of motion of the particle, and the + or indicates the...
-
Benchmark has an optimal target capital structure consisting of a debt-to-assets ratio of 60 percent. Benchmark can raise up to $5 million in new debt at a before-tax cost of 8 percent. If more debt...
-
What four environmental conditions that increase user demand for relevant and reliable information?
-
Explain why, in a simple model, a bivalent material could be considered to be an insulator. Also explain why this simple argument is not true.
-
A firms debt to equity ratio is 1.0. The before tax cost of debt=7%, RF=3%, beta=1.1, the market return =8% and the tax rate =32%. The firm's WACC (weighted average cost of capital)=?% Use 4 decimals...
-
The spot price of oil is $60.80 per barrel and the cost of storing a barrel of oil for one year is $4.50, payable at the end of the year. The risk-free interest rate is 1.2% per annum, continuously...
-
A monopolist has determined that marginal revenue is $2.00 and the average cost is $1.75. It has also determined that the lowest sustainable average cost is $1.75. To maximize profit, should the firm...
-
How does the neuroendocrine axis regulate the stress response, encompassing the hypothalamic-pituitary-adrenal (HPA) axis and the sympathetic-adrenal-medullary (SAM) system, and what are the...
-
How is methylation of DNA connected to the acetylation of histones and gene expression? Explain
-
5) If labor becomes more productive, the production possibilities frontier will A) remain constant, but output will increase as unemployment falls. B) shift to outward away from the origin. C) shift...
-
U.S. households have become smaller over the years. The following table from the 2010 GSS contains information on the number of people currently aged 18 years or older living in a respondent's...
-
Civil Code 1719, subdivision (a) provides in part that any person who draws a check that is dishonored due to insufficient funds shall be liable to the payee for the amount owing upon the check and...
-
Raymond Zukaitis was a physician practicing medicine in Douglas County, Nebraska. Aetna issued a policy of professional liability insurance to Zukaitis through its agent, the Ed Larsen Insurance...
-
Consolidated Business Forms leased a Phillips business computer from Benchmark. Benchmark subsequently transferred the lease and promissory note to Exchange International Leasing Corporation....
-
When a honeybee flies through the air, it develops a charge of +17 pC. How many electrons did it lose in the process of acquiring this charge?
-
Falling raindrops frequently develop electric charges. Does this create noticeable forces between the droplets? Suppose two 1.8 mg drops each have a charge of +25 pC; these are typical values. The...
-
A housefly walking across a surface may develop a significant electric charge through a process similar to frictional charging. Suppose a fly picks up a charge of +52 pC. How many electrons does it...
Study smarter with the SolutionInn App