Methods 2: Inventory control with files: Spring 2024
Learning Objective(s)
- Improving methods skill
- Work with files
- Use constants
Overview of the Program
Create a program to inform the user if a certain item needs to be reordered because of low levels
Specifics
- The program should be called Reorder
- There should be three constants for the file names: names.txt, onhand.txt, minamount.txt
- The program should continue to read in items (as strings) from the user until the word "quit" is entered
- for each item, it should tell the user if more should be re-ordered and if so, how many.
- The only I/O allowed in the main method should be to get the name of each item (along with the associated prompt)
- You should have one method that will process a single item. It should not directly read from any file but call other methods that read from a file
- You should have a method that is sent an item and a file name. It should return the line number that item is on. If that item is not in the file, or it is a bad file, it should return -1
- You should have another method that is sent a line number and a file name and it should return that number at that line in the file. If there is a problem with the file, it should either return -1 or exit the entire program.
- If a method opens a file, it should close it before it returns
Sample dialogue
Below is a sample dialogue. Your output can vary somewhat as long as the required data is nicely displayed
What item do you want to check on (quit to exit)?
apple
Please order at least 4 of apple.
What item do you want to check on (quit to exit)?
basket
There is no need to reorder basket.
What item do you want to check on (quit to exit)?
banana
There is no need to reorder banana.
What item do you want to check on (quit to exit)?
quit
You can also run a solution for this program if you want. See classroom instructions for more details.
Submission
- Create your SDR.
- In Lessons Learned, include a discussion on how many things could go wrong. You only need to test for two
- Your testing should include at least 2 different types of errors and ensure that every line of code is executed at least once. Add copies of your files that you used (with appropriate links back to the test cases) at the end of the report. Try to put them in columns to save space. You might want to have different sets of files for some of the different tests.
- If you used any hints, be sure to indicate that in the Outside Resources Used section
- Convert your SDR into a pdf document
- Create an empty zip folder
- Place your java file and pdf document in it.
- Submit the zip folder on canvas
Hints
- Steps to develop
- Algorithm hint
- Finding the item
- Finding a number in a file
- Constants
Optional improvements
Optional improvements should ONLY be worked on once the program is completing working. In addition, the work is to be done on your own with little if any help for lab assistants or the instructor.
- Don't throw the IOExceptions but catch them instead