An organization feels like 47 lawnmowers for 47 lawns is a bit over-consumeristic. They have formed...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
An organization feels like 47 lawnmowers for 47 lawns is a bit over-consumeristic. They have formed a group that is willing to share tools with each other. This group has a file that has three values: the tool name, the owner's name, and availability. The first two values are strings. Availability is a boolean (true or false) value that indicates whether the tool is available. This organization finds it tedious to keep looking at the file. They want a way to search for a tool and find out whether it exists, who owns it and whether it is available. The search must be case-insensitive. They also want to be able to enter add a new tool by entering the name of the tool and an owner's name; the available field will default to true. They would like for the new tool to be added to the list of tools in memory as well as appended to the tools in the file. They also want mark a tool as borrowed (that is, unavailable) or returned (i.e. mark as available). Tools in the file are sorted by the name of the tool. The program must have a menu that allows the following actions: Locate - find a tool. If the user selects this option, they will be prompted for a tool name. If successful, that is, it is found, then the tool name, owner and availability must be displayed. After this, there will be a submenu Borrow, Return, Remove or Cancel. Selecting 'cancel' has no effect. Selecting Borrow or Return will modify the available field as appropriate. Selecting Remove will remove the tool from the Toolkeeper. If the tool isn't found, the user will simply be notified with a 'not found' type message. Add - (followed by prompts for tool name and owner). This tool will be added to the list with the available flag set to true. List All Tools - prints the entire array list of tools, one tool per line. The list should be well-formatted in columnar style. [This is mainly to be used in testing. I suggest you complete this one first.] Quit - exits the while-loop, displays a farewell message and quits the program. Restrictions and file format There may be any number of tools in the file. A typical line would look like: Dremel false Franklin This line would indicate that there is a Dremel owned by Franklin but it is not available. Input guarantees As before, this file will have no formatting problems. Here are the guarantees for the file: The tools in the file are sorted by the name of the tool. Tool names will not have spaces. (If spaces are required, the name will be hyphenated, e.g. hand-mixer.) Owner names will not have spaces. The format given (string Boolean string) will be followed for each line. No line will have too many or two few fields. Implementation notes You are required to have two classes in addition to the main class. The Tool class is fairly simple. The Toolkeeper will contain much of the work. REMEMBER INTERACTION WITH THE USER (INPUT AND OUTPUT FROM THE CONSOLE) SHOULD ONLY BE DONE FROM THE MAIN CLASS. THE TOOL AND TOOLKEEPER SHOULD KNOW NOTHING ABOUT SYSTEM.IN OR SYSTEM.OUT. Required Classes The Tool class This class will consist of three fields, toolName, owner, and available. The first two of these fields are Strings. They will have only getters. The available field is a boolean. It will have a getter named isAvailable. It will also have a setter that accepts a boolean value. The Tool class must have overloaded constructors. One that accepts two Strings; one that accepts two Strings and a boolean. In the first constructor, the available field should be set to true. The constructor with three parameters must be used when reading information from the file; the constructor with two parameters must be used when creating a Tool from user input. The Toolkeeper class This class will hold the array and associated methods. It needs only on field, an array list of Tool objects. At a minimum, you must provide these methods. load ToolList - this method accepts a filepath. In the loop that loads in the information from the file, each line (record) should be used to create an instance of your Tool class. This instance must be added to an ArrayList of tools (i.e. ArrayList ). You should use this ArrayList when you search for the tools or when you add a new tool to the list. getNumTools - returns the number of tools in the ArrayList. Do not keep an instance variable for this value; that could lead to stale data. findToolByName-returns a Tool matching the parameter passed to the method if that Tool if it exists. Otherwise it should return null. Remember to check whether the return value is null before using it. This method should exist in the main class or the ToolChest mentioned below. This method should use the binary-search to find the tool since the tools are sorted by name. You will lose points if you use the sequential search. [Note: once you have added new names, this method may no longer work properly. That is to be expected since the order may no longer be alphabetical. You do not need to fix it (unless you are working for an 'A'.]/ addTool - accepts a Tool object and adds it to the array list. removeTool - accepts a Tool object and deletes that object from the array list of Tool objects. (Hint: look at the remove method in the ArrayList class. getToolList - returns a copy of the tool list. The above methods are required and should be public. You may find that other private methods will make your work easier or less cluttered, but these are entirely up to you. Main class The main program will run in a loop until the user decides to quit. This class will need methods to display a menu to the user and get a validate response. In addition, it will need a method to create a tool based on the user's input. (See below.) It would be wise to have a method for locating a tool and displaying the list of tools. Doing so will keep your main method more manageable. create Tool - returns a Tool based on input from the user. The main class must have a method that accepts a Scanner object as its only argument. It must return a Tool object. The code of the method must prompt the user for the name of the tool and the name of the owner. It must instantiate the Tool object and return that object. The main method will add the returned Tool to the array of tools. For a grade of 'C': Implement the program described above. For a starting grade of 'B': Complete the requirements for a grade of 'C'. In addition: Rewrite the file (overwrite) to reflect new borrowed/return state as well as any new tools that have been added. Do this only after the user decides to quit the program. You do not want to update the file every time a change is made. If we had a database, that would be a different story. Your program should work if started with the overwritten file. This means that the original format [toolname availability owner] must be followed. Each tool should be on its own line, each field will be separated by a space. As with the 'C' work, if a tool has been created, the ability to find that tool may not work if the program is started with the new file. [Be careful. Make certain you keep a copy of the original file somewhere so that you can continue to test your code. Once you cause the file to be unsorted, binary search will no longer work.] For a starting grade of 'A': When adding a new tool, insert it at the correct place to keep the array of tools in alphabetical order. There are better ways, but simplest is to walk the array until the correct location (think what that means) is found and using the overloaded add method in the array list to insert the tool at this location. This means that the list will always be in alphabetical order based on the names of the tools, which also means that the findToolByName method will succeed even after new tools are added. Multiple entries of tools with the same name should be allowed. Development hints 1. Hard code a list of five or six Tools and put them in the array. It is easier to see if things are working if the list is small. Don't forget to make sure the tools are in alphabetical order. 2. Get the menu option to list all the tools working. 3. Implement the loading of the array from the file. Get it working properly before you move on. Use the 'list all tools' option to see if things are working correctly. Start with a small list. (Just delete all but the first ten tools or so in the file.) 4. Implement the Locate menu option. Test it well. Check that it finds something in the middle, the last tool, the first tool. Check that it fails to find a non-existing tool in the middle, before the first tool, after the last tool. 5. Implement the add tool option. Make certain you can find that tool and that it shows up in the list. 6. Replace your small file with the complete one. Check that everything still works. Things to keep in mind for program five. Additional requirements for a grade of 'B' are in green; additional requirements for a grade of 'A' are in blue. Done Task Tool class has overloaded constructors has all getters has setter for availability Toolkeeper class the class contains an ArrayList of Tool objects class works properly with any number of tools load ToolList accepts a path to the file as a String load ToolList correctly adds new Tool for each record getNum Tools returns the correct count class does NOT contain an instance variable for number of tools findToolByName uses the binary search algorithm to find the tool addTool accepts a Tool object addTool adds the tool to the list add Tool adds the tool in the correct location in the ArrayList remove Tool accepts a Tool object remove Tool removes the tool from the list getToolList does not return the actual list; it returns a copy Main class menu is well formatted tools marked available/unavailable show up correctly Locate reports tools that are not found when a tool is found using Locate; a sub-menu is displayed with four choices when a tool is removed, it is no longer displayed in the list when the availability of a tool is changed, it shows up correctly in the list the list of tools is well-formatted newly added tools can be found using Locate the method to store the file overwrites the existing file listing all tools shows any newly added tools when the program is run again when a tool is removed, it is no longer when the program is run again when a tool is added and the program is rerun, Locate works properly An organization feels like 47 lawnmowers for 47 lawns is a bit over-consumeristic. They have formed a group that is willing to share tools with each other. This group has a file that has three values: the tool name, the owner's name, and availability. The first two values are strings. Availability is a boolean (true or false) value that indicates whether the tool is available. This organization finds it tedious to keep looking at the file. They want a way to search for a tool and find out whether it exists, who owns it and whether it is available. The search must be case-insensitive. They also want to be able to enter add a new tool by entering the name of the tool and an owner's name; the available field will default to true. They would like for the new tool to be added to the list of tools in memory as well as appended to the tools in the file. They also want mark a tool as borrowed (that is, unavailable) or returned (i.e. mark as available). Tools in the file are sorted by the name of the tool. The program must have a menu that allows the following actions: Locate - find a tool. If the user selects this option, they will be prompted for a tool name. If successful, that is, it is found, then the tool name, owner and availability must be displayed. After this, there will be a submenu Borrow, Return, Remove or Cancel. Selecting 'cancel' has no effect. Selecting Borrow or Return will modify the available field as appropriate. Selecting Remove will remove the tool from the Toolkeeper. If the tool isn't found, the user will simply be notified with a 'not found' type message. Add - (followed by prompts for tool name and owner). This tool will be added to the list with the available flag set to true. List All Tools - prints the entire array list of tools, one tool per line. The list should be well-formatted in columnar style. [This is mainly to be used in testing. I suggest you complete this one first.] Quit - exits the while-loop, displays a farewell message and quits the program. Restrictions and file format There may be any number of tools in the file. A typical line would look like: Dremel false Franklin This line would indicate that there is a Dremel owned by Franklin but it is not available. Input guarantees As before, this file will have no formatting problems. Here are the guarantees for the file: The tools in the file are sorted by the name of the tool. Tool names will not have spaces. (If spaces are required, the name will be hyphenated, e.g. hand-mixer.) Owner names will not have spaces. The format given (string Boolean string) will be followed for each line. No line will have too many or two few fields. Implementation notes You are required to have two classes in addition to the main class. The Tool class is fairly simple. The Toolkeeper will contain much of the work. REMEMBER INTERACTION WITH THE USER (INPUT AND OUTPUT FROM THE CONSOLE) SHOULD ONLY BE DONE FROM THE MAIN CLASS. THE TOOL AND TOOLKEEPER SHOULD KNOW NOTHING ABOUT SYSTEM.IN OR SYSTEM.OUT. Required Classes The Tool class This class will consist of three fields, toolName, owner, and available. The first two of these fields are Strings. They will have only getters. The available field is a boolean. It will have a getter named isAvailable. It will also have a setter that accepts a boolean value. The Tool class must have overloaded constructors. One that accepts two Strings; one that accepts two Strings and a boolean. In the first constructor, the available field should be set to true. The constructor with three parameters must be used when reading information from the file; the constructor with two parameters must be used when creating a Tool from user input. The Toolkeeper class This class will hold the array and associated methods. It needs only on field, an array list of Tool objects. At a minimum, you must provide these methods. load ToolList - this method accepts a filepath. In the loop that loads in the information from the file, each line (record) should be used to create an instance of your Tool class. This instance must be added to an ArrayList of tools (i.e. ArrayList ). You should use this ArrayList when you search for the tools or when you add a new tool to the list. getNumTools - returns the number of tools in the ArrayList. Do not keep an instance variable for this value; that could lead to stale data. findToolByName-returns a Tool matching the parameter passed to the method if that Tool if it exists. Otherwise it should return null. Remember to check whether the return value is null before using it. This method should exist in the main class or the ToolChest mentioned below. This method should use the binary-search to find the tool since the tools are sorted by name. You will lose points if you use the sequential search. [Note: once you have added new names, this method may no longer work properly. That is to be expected since the order may no longer be alphabetical. You do not need to fix it (unless you are working for an 'A'.]/ addTool - accepts a Tool object and adds it to the array list. removeTool - accepts a Tool object and deletes that object from the array list of Tool objects. (Hint: look at the remove method in the ArrayList class. getToolList - returns a copy of the tool list. The above methods are required and should be public. You may find that other private methods will make your work easier or less cluttered, but these are entirely up to you. Main class The main program will run in a loop until the user decides to quit. This class will need methods to display a menu to the user and get a validate response. In addition, it will need a method to create a tool based on the user's input. (See below.) It would be wise to have a method for locating a tool and displaying the list of tools. Doing so will keep your main method more manageable. create Tool - returns a Tool based on input from the user. The main class must have a method that accepts a Scanner object as its only argument. It must return a Tool object. The code of the method must prompt the user for the name of the tool and the name of the owner. It must instantiate the Tool object and return that object. The main method will add the returned Tool to the array of tools. For a grade of 'C': Implement the program described above. For a starting grade of 'B': Complete the requirements for a grade of 'C'. In addition: Rewrite the file (overwrite) to reflect new borrowed/return state as well as any new tools that have been added. Do this only after the user decides to quit the program. You do not want to update the file every time a change is made. If we had a database, that would be a different story. Your program should work if started with the overwritten file. This means that the original format [toolname availability owner] must be followed. Each tool should be on its own line, each field will be separated by a space. As with the 'C' work, if a tool has been created, the ability to find that tool may not work if the program is started with the new file. [Be careful. Make certain you keep a copy of the original file somewhere so that you can continue to test your code. Once you cause the file to be unsorted, binary search will no longer work.] For a starting grade of 'A': When adding a new tool, insert it at the correct place to keep the array of tools in alphabetical order. There are better ways, but simplest is to walk the array until the correct location (think what that means) is found and using the overloaded add method in the array list to insert the tool at this location. This means that the list will always be in alphabetical order based on the names of the tools, which also means that the findToolByName method will succeed even after new tools are added. Multiple entries of tools with the same name should be allowed. Development hints 1. Hard code a list of five or six Tools and put them in the array. It is easier to see if things are working if the list is small. Don't forget to make sure the tools are in alphabetical order. 2. Get the menu option to list all the tools working. 3. Implement the loading of the array from the file. Get it working properly before you move on. Use the 'list all tools' option to see if things are working correctly. Start with a small list. (Just delete all but the first ten tools or so in the file.) 4. Implement the Locate menu option. Test it well. Check that it finds something in the middle, the last tool, the first tool. Check that it fails to find a non-existing tool in the middle, before the first tool, after the last tool. 5. Implement the add tool option. Make certain you can find that tool and that it shows up in the list. 6. Replace your small file with the complete one. Check that everything still works. Things to keep in mind for program five. Additional requirements for a grade of 'B' are in green; additional requirements for a grade of 'A' are in blue. Done Task Tool class has overloaded constructors has all getters has setter for availability Toolkeeper class the class contains an ArrayList of Tool objects class works properly with any number of tools load ToolList accepts a path to the file as a String load ToolList correctly adds new Tool for each record getNum Tools returns the correct count class does NOT contain an instance variable for number of tools findToolByName uses the binary search algorithm to find the tool addTool accepts a Tool object addTool adds the tool to the list add Tool adds the tool in the correct location in the ArrayList remove Tool accepts a Tool object remove Tool removes the tool from the list getToolList does not return the actual list; it returns a copy Main class menu is well formatted tools marked available/unavailable show up correctly Locate reports tools that are not found when a tool is found using Locate; a sub-menu is displayed with four choices when a tool is removed, it is no longer displayed in the list when the availability of a tool is changed, it shows up correctly in the list the list of tools is well-formatted newly added tools can be found using Locate the method to store the file overwrites the existing file listing all tools shows any newly added tools when the program is run again when a tool is removed, it is no longer when the program is run again when a tool is added and the program is rerun, Locate works properly
Expert Answer:
Related Book For
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...
-
Design a Java class that represents a cache with a fixed size. It should support operations like add, retrieve, and remove, and it should evict the least recently used item when it reaches capacity.
-
Assume that a company is going to invest 900,000 USD in a new project. We expect that the invested capital in the fixed assets will be fully depreciated within 3 years as follows: 500,000 USD,...
-
Ocean Research of San Diego, California, just received a check in the amount of $800,000 from a customer in Bangor, Maine. If the firm processes the check in the normal manner, the funds will become...
-
An engineering firm is hired to determine if certain waterways in Virginia are safe for fishing. Samples are taken from three rivers. (a) List the elements of a sample space S, using the letters F...
-
The isotopes magnesium-24 (mass \(3.983 \times 10^{-26} \mathrm{~kg}\) ) and magnesium-26 (mass \(4.315 \times 10^{-26} \mathrm{~kg}\) ) are to be separated using a mass spectrometer in which the...
-
I was sure that when our battery hit the market it would be an instant success, said Roger Strong, founder and president of Solar Technology, Inc., but just look at the gusher of red ink for the...
-
How will the Information Assurance program benefit you in the future?
-
Ellipses Corp is a small business that operates in Herndon, VA. The company is located at10 Period Lane, Herndon, VA 20170. Its federal Employer Identification Number is 77-7777777, and its...
-
Suppose you are working as a designer for a university that offers a program in computer science. One of the tracts is computer security. One of your colleagues has recommended adding a course...
-
What are comprehensive community-based delinquency prevention programs?
-
Prevention and control are the two broad-based approaches that can be used to reduce delinquency. How do these approaches differ?
-
Are you familiar with any instances of retrospective reading in your home town? Have you ever engaged in it yourself, saying, I always knew he had problems?
-
Is widening the net a real danger, or are treatmentoriented programs simply a method of helping troubled youths?
-
What factors precipitated the development of the Illinois Juvenile Court Act of 1899?
-
Kathy and Bill were married on 12-2-88. Bill was 50 and Kathy is 51 as of 1-1-20. They have two children living with them, Karla and Billy, fraternal twins, age 22, no longer in school and single as...
-
Players A, B, and C toss a fair coin in order. The first to throw a head wins. What are their respective chances of winning?
-
On October 2, 2013, a Canadian company contracts with a U.S. winery for delivery from the winery of 1,000 cases of wine at a price of U.S. $100,000. The wine is to be delivered February 1, 2014, and...
-
On December 31, 2009, Jupiter Inc. purchased all of the shares of Europa Ltd. for $4,760,000. On that date, the carrying amount of Europas identifiable net assets was $4,080,000. The carrying amount...
-
XYZ, a Canadian company, has a subsidiary located in Europe that owns land. The land was purchased on January 1 for 1 million when the euro to Canadian dollar direct rate was $1. On December 31, it...
-
What is a key function of credit-rating agencies? Do credit-rating agencies always provide reliable information? What was the role of credit-rating agencies in the sub-prime crisis of 2008?
-
Assuming the expectations theory is the correct theory of the term structure, calculate the interest rates in the term structure for maturities of one to four years, and plot the resulting yield...
-
Magee Corporation provided the following summary balance sheet information: Compute net income for the year ending December 31, 20X2, under each of the following independent scenarios: (a) Magee paid...
Study smarter with the SolutionInn App