The world’s Largest Sharp Brain Virtual Experts Marketplace Just a click Away
Levels Tought:
Elementary,Middle School,High School,College,University,PHD
| Teaching Since: | May 2017 |
| Last Sign in: | 401 Weeks Ago, 5 Days Ago |
| Questions Answered: | 66690 |
| Tutorials Posted: | 66688 |
MCS,PHD
Argosy University/ Phoniex University/
Nov-2005 - Oct-2011
Professor
Phoniex University
Oct-2001 - Nov-2016
You work at a soft drink distributorship that sells at most 100 different kinds of soft drinks. This program will process weekly transactions and allow for a report to be displayed that includes the soft-drink name, ID number, starting inventory, final inventory, and the number of transactions received.
Â
There are two data files, data7.txt 
and data7trans.txt
, which hold the initial soft drink information and transactions, respectively. The file data7.txt
consists of at most 100 lines where each line contains the soft drink name (string), ID number (string), and the starting inventory of cases (int).
Â
The file data7trans.txt
holds the transactions. Each transaction consists of the ID number followed by the number of cases purchased (positive integer), or the amount sold (negative integer). In the case of an invalid ID number, do not process the data (ignore it, no error message).
Â
Sample data7.txt:
Coke 123 100 Pepsi 345 50 CanadaDry 678 75 DrPepper 444 120
Sample data7trans.txt:
345 10 123 -5 345 10 678 8 444 20 444 -20 444 10 999 5 345 10 123 -25
The displayReport function displays the drink name, ID number, starting inventory, final inventory, and the number of transactions processed.
Â
For the sample data, the output of your program would be as follows:
Soft drink ID number Starting Inventory Final Inventory # transactions Coke 123 100 70 2 Pepsi 345 50 80 3 CanadaDry 678 75 83 1 DrPepper 444 120 130 3
Write a SoftDrinkInventory class with the following functionality:
Â
public SoftDrinkInventory: Is a constructor that initializes arrays holding soft drink name, ID number, and starting inventory from data file. The array holding final inventory is set to the same values as the starting inventory and transaction counts array is initialized to zero (initialize described below is used for this).
Â
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.
Â
public displayReport: Displays a report including soft drink name, ID number, starting inventory, final inventory, and number of transactions processed.
Â
private findID: Takes an ID number parameter and returns the position in the array where the soft drink with that ID is found. A -1 value is returned if the ID is not found.
Â
private initialize: Takes an int array parameter and initializes its array values to zero.
/** * This program tests the functionality of a the SoftDrinkInventory class. * A datafile containing initial data is used to construct a SoftDrink object. * Then transactions are processed where each transaction contains how * cases are bought or sold. A function displays a report of the drink name, * ID number, starting inventory, final inventory, and the number of * transactions processed. The largest and smallest transaction value * is displayed. */ import java.util.Scanner; import java.io.FileInputStream; import java.io.FileNotFoundException; public class SoftDrinkTester { public static void main (String[] args) { Scanner inventoryFile = null; // inventory data file Scanner transFile = null; // transaction data file // open the inventory initialization file try { inventoryFile = new Scanner(new FileInputStream("data7.txt")); } catch (FileNotFoundException e) { System.out.println("File not found or not opened."); System.exit(0); } // open the file containing the buy/sell transactions try { } catch (FileNotFoundException e) { System.out.println("File not found or not opened."); System.exit(0); } // instantiate the soft drink distributorship object // and process the transactions by updating the inventory totals } }
Hel-----------lo -----------Sir-----------/Ma-----------dam-----------Tha-----------nk -----------You----------- fo-----------r u-----------sin-----------g o-----------ur -----------web-----------sit-----------e a-----------nd -----------and----------- ac-----------qui-----------sit-----------ion----------- of----------- my----------- po-----------ste-----------d s-----------olu-----------tio-----------n.P-----------lea-----------se -----------pin-----------g m-----------e o-----------n c-----------hat----------- I -----------am -----------onl-----------ine----------- or----------- in-----------box----------- me----------- a -----------mes-----------sag-----------e I----------- wi-----------ll