Advertisement
akosiraff

SoftDrinkInventory JAVA

Nov 18th, 2013
224
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.17 KB | None | 0 0
  1.  
  2. Download: http://solutionzip.com/downloads/softdrinkinventory-java/
  3. You work at a soft drink distributorship that sells at most 100 different kinds of soft drinks. The program you write for this assignment will process weekly transactions and allow for a report to be displayed that includes the soft- drink name, ID, starting inventory, final inventory, and the number of transactions received.
  4. There are two data files, data6.txt and data6trans.txt, which hold the initial soft drink information and transactions, respectively. The file data6.txt consists of at most 100 lines where each line contains the soft drink name (one string), ID (string), and the starting inventory of cases (int).
  5. The file data6trans.txt holds the transactions. Each transaction consists of the ID followed by the number of cases purchased (positive integer), or the amount sold (negative integer). You can assume the format of the data is correct, but not all IDs are valid. In the case of an invalid ID, do not process the data (ignore it, no error message).
  6. Sample data6.txt: Sample data6trans.txt:
  7. Coke 123 100 345 10
  8. Pepsi 345 50 123 -5
  9. CanadaDry 678 75 345 10
  10. DrPepper 444 120 678 8
  11. 444 20
  12. 444 -20
  13. 444 10
  14. 999 5
  15. 345 10
  16. 123 -25
  17. The displayReport function displays the drink name, ID, starting inventory, final inventory, and the number of transactions processed. Display this exact format (number of blanks separating items does not have to be identical).
  18. For the sample data, the output of your program would be as follows:
  19. Soft Drink ID Starting Inventory Final Inventory # transaction
  20. Coke 123 100 70 2
  21. Pepsi 345 50 80 3
  22. CanadaDry 678 75 83 1
  23. DrPepper 444 120 130 3
  24. Write a SoftDrinkInventory class with the following functionality:
  25. public constructor: Initializes arrays holding soft drink name and ID to hold all empty strings (calls intitializeString twice to perform the tasks). Initializes arrays holding starting inventory, final inventory, and the counts of the number of transaction to zero (calls initializeInt three times to perform the tasks).
  26. public buildInventory: Sets the arrays for soft drink name, ID, and starting inventory from information in the data file. The array holding final inventory is set to the same values as the starting inventory.
  27. public processTransactions: Processes the transactions by correctly adjusting the final inventory and transaction counts arrays. Data for IDs which don’t exist are not processed.
  28. public displayReport: Displays a report including soft drink name, ID, starting inventory, final inventory, and number of transactions processed.
  29. private findID: Takes an ID parameter and returns the position in the array (the subscript) where the soft drink with that id is found. Return -1 if the ID is not found. Remember the id is a String (so use equals to compare).
  30. private initializeInt: Takes an int array parameter and initializes all array values to zero.
  31. private initializeString: Takes a String array parameter and initializes all values to the empty String (“”).
  32. So that you are not overwhelmed with assignment 6, I have put together a skeleton SoftDrinkInventory class. This can be found in the dropbox for the assignment. All the places with “…” need you to write code.
  33. Notice all the good comments that tell you exactly what each method does. This should both help you to write the code and teach you what a good comment looks like. Good comments let you know what the code is doing without you having to read code.
  34. I have also provided a completed SoftDrinkTester class to be used in testing the program. This class, SoftDrinkTester, should not be modified. Be sure to read and understand this class before writing any code for the SoftDrinkInventory class.
  35. Now here is an outline of how to attack the problem. Once you think of a large problem as a bunch of smaller ones, it becomes a much less intimidating task. Divide and conquer!
  36. Comment out from main anything that you are not testing.
  37. STEP 1
  38. When developing this code, first write the constructor that initializes all your class variables. Hopefully you wrote most
  39. of this in lab. You will need to write initializeInt and initializeString to be used in the constructor.
  40. Don’t write more code until this compiles!
  41. STEP 2
  42. Next write displayReport(). You’ll need to review using printf to make nice columns. Compile and run. It should display a report with empty strings and zeros.
  43. Having displayReport() written is handy for debugging purposes. If something goes wrong later on, you can always call it inside a loop and watch how your numbers change.
  44. STEP 3
  45. Now write buildInventory. Compile and run along with displayReport(). Now the display should have the softdrink names, ids, and starting inventory. The final inventory should be the same as the starting inventory and # transactions will be zero.
  46. STEP 4
  47. Now all that is left is processTransactions. Read one transaction at a time and handle it. You will need to write findID to handle one transaction. Finding something in an array (officially called linear search) is a common task. The sample code , FindInArray.java, including as an attachment to the assignment demonstrates how to do this.
  48.  
  49. Download: http://solutionzip.com/downloads/softdrinkinventory-java/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement